Extract platform selection code from ClientView
This commit is contained in:
parent
94f0883fec
commit
820a090a71
2 changed files with 24 additions and 12 deletions
|
@ -17,14 +17,7 @@ limitations under the License.
|
|||
import {isWebPlatform, isDesktopPlatform, Platform} from "../Platform.js";
|
||||
import {ViewModel} from "../utils/ViewModel.js";
|
||||
import {IdentifierKind} from "../Link.js";
|
||||
|
||||
function getMatchingPlatforms(client, supportedPlatforms) {
|
||||
const clientPlatforms = client.platforms;
|
||||
const matchingPlatforms = supportedPlatforms.filter(p => {
|
||||
return clientPlatforms.includes(p);
|
||||
});
|
||||
return matchingPlatforms;
|
||||
}
|
||||
import {getMatchingPlatforms, selectPlatforms} from "./clients/index.js";
|
||||
|
||||
export class ClientViewModel extends ViewModel {
|
||||
constructor(options) {
|
||||
|
@ -40,10 +33,10 @@ export class ClientViewModel extends ViewModel {
|
|||
|
||||
_update() {
|
||||
const matchingPlatforms = getMatchingPlatforms(this._client, this.platforms);
|
||||
this._webPlatform = matchingPlatforms.find(p => isWebPlatform(p));
|
||||
this._nativePlatform = matchingPlatforms.find(p => !isWebPlatform(p));
|
||||
const preferredPlatform = matchingPlatforms.find(p => p === this.preferences.platform);
|
||||
this._proposedPlatform = preferredPlatform || this._nativePlatform || this._webPlatform;
|
||||
const {proposedPlatform, nativePlatform, webPlatform} = selectPlatforms(matchingPlatforms, this.preferences.platform);
|
||||
this._nativePlatform = nativePlatform;
|
||||
this._webPlatform = webPlatform;
|
||||
this._proposedPlatform = proposedPlatform;
|
||||
|
||||
this.openActions = this._createOpenActions();
|
||||
this.installActions = this._createInstallActions();
|
||||
|
|
|
@ -21,6 +21,25 @@ import {Fractal} from "./Fractal.js";
|
|||
import {Quaternion} from "./Quaternion.js";
|
||||
import {Tensor} from "./Tensor.js";
|
||||
import {Fluffychat} from "./Fluffychat.js";
|
||||
import {isWebPlatform} from "../../Platform.js"
|
||||
|
||||
export function getMatchingPlatforms(client, supportedPlatforms) {
|
||||
const clientPlatforms = client.platforms;
|
||||
const matchingPlatforms = supportedPlatforms.filter(p => {
|
||||
return clientPlatforms.includes(p);
|
||||
});
|
||||
return matchingPlatforms;
|
||||
}
|
||||
|
||||
export function selectPlatforms(matchingPlatforms, userPreferredPlatform) {
|
||||
const webPlatform = matchingPlatforms.find(p => isWebPlatform(p));
|
||||
const nativePlatform = matchingPlatforms.find(p => !isWebPlatform(p));
|
||||
const preferredPlatform = matchingPlatforms.find(p => p === userPreferredPlatform);
|
||||
return {
|
||||
proposedPlatform: preferredPlatform || nativePlatform || webPlatform,
|
||||
nativePlatform, webPlatform
|
||||
};
|
||||
}
|
||||
|
||||
export function createClients() {
|
||||
return [
|
||||
|
|
Loading…
Reference in a new issue