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 {isWebPlatform, isDesktopPlatform, Platform} from "../Platform.js";
|
||||||
import {ViewModel} from "../utils/ViewModel.js";
|
import {ViewModel} from "../utils/ViewModel.js";
|
||||||
import {IdentifierKind} from "../Link.js";
|
import {IdentifierKind} from "../Link.js";
|
||||||
|
import {getMatchingPlatforms, selectPlatforms} from "./clients/index.js";
|
||||||
function getMatchingPlatforms(client, supportedPlatforms) {
|
|
||||||
const clientPlatforms = client.platforms;
|
|
||||||
const matchingPlatforms = supportedPlatforms.filter(p => {
|
|
||||||
return clientPlatforms.includes(p);
|
|
||||||
});
|
|
||||||
return matchingPlatforms;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class ClientViewModel extends ViewModel {
|
export class ClientViewModel extends ViewModel {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
|
@ -40,10 +33,10 @@ export class ClientViewModel extends ViewModel {
|
||||||
|
|
||||||
_update() {
|
_update() {
|
||||||
const matchingPlatforms = getMatchingPlatforms(this._client, this.platforms);
|
const matchingPlatforms = getMatchingPlatforms(this._client, this.platforms);
|
||||||
this._webPlatform = matchingPlatforms.find(p => isWebPlatform(p));
|
const {proposedPlatform, nativePlatform, webPlatform} = selectPlatforms(matchingPlatforms, this.preferences.platform);
|
||||||
this._nativePlatform = matchingPlatforms.find(p => !isWebPlatform(p));
|
this._nativePlatform = nativePlatform;
|
||||||
const preferredPlatform = matchingPlatforms.find(p => p === this.preferences.platform);
|
this._webPlatform = webPlatform;
|
||||||
this._proposedPlatform = preferredPlatform || this._nativePlatform || this._webPlatform;
|
this._proposedPlatform = proposedPlatform;
|
||||||
|
|
||||||
this.openActions = this._createOpenActions();
|
this.openActions = this._createOpenActions();
|
||||||
this.installActions = this._createInstallActions();
|
this.installActions = this._createInstallActions();
|
||||||
|
|
|
@ -21,6 +21,25 @@ import {Fractal} from "./Fractal.js";
|
||||||
import {Quaternion} from "./Quaternion.js";
|
import {Quaternion} from "./Quaternion.js";
|
||||||
import {Tensor} from "./Tensor.js";
|
import {Tensor} from "./Tensor.js";
|
||||||
import {Fluffychat} from "./Fluffychat.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() {
|
export function createClients() {
|
||||||
return [
|
return [
|
||||||
|
|
Loading…
Reference in a new issue