Merge pull request #10181 from vector-im/t3chguy/electron_config_via_plaf
Move config-getting to VectorBasePlatform
This commit is contained in:
commit
2111db73a7
|
@ -1,8 +1,8 @@
|
||||||
/*
|
/*
|
||||||
Copyright 2016 Aviral Dasgupta
|
Copyright 2016 Aviral Dasgupta
|
||||||
Copyright 2016 OpenMarket Ltd
|
Copyright 2016 OpenMarket Ltd
|
||||||
Copyright 2017 Michael Telatynski <7t3chguy@gmail.com>
|
|
||||||
Copyright 2018 New Vector Ltd
|
Copyright 2018 New Vector Ltd
|
||||||
|
Copyright 2017, 2019 Michael Telatynski <7t3chguy@gmail.com>
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
@ -173,6 +173,9 @@ ipcMain.on('ipcCall', async function(ev, payload) {
|
||||||
await migrateFromOldOrigin();
|
await migrateFromOldOrigin();
|
||||||
migratingOrigin = false;
|
migratingOrigin = false;
|
||||||
break;
|
break;
|
||||||
|
case 'getConfig':
|
||||||
|
ret = vectorConfig;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
mainWindow.webContents.send('ipcReply', {
|
mainWindow.webContents.send('ipcReply', {
|
||||||
id: payload.id,
|
id: payload.id,
|
||||||
|
|
|
@ -17,6 +17,8 @@ limitations under the License.
|
||||||
import Promise from 'bluebird';
|
import Promise from 'bluebird';
|
||||||
import request from 'browser-request';
|
import request from 'browser-request';
|
||||||
|
|
||||||
|
// Load the config file. First try to load up a domain-specific config of the
|
||||||
|
// form "config.$domain.json" and if that fails, fall back to config.json.
|
||||||
export async function getVectorConfig(relativeLocation) {
|
export async function getVectorConfig(relativeLocation) {
|
||||||
if (relativeLocation === undefined) relativeLocation = '';
|
if (relativeLocation === undefined) relativeLocation = '';
|
||||||
if (relativeLocation !== '' && !relativeLocation.endsWith('/')) relativeLocation += '/';
|
if (relativeLocation !== '' && !relativeLocation.endsWith('/')) relativeLocation += '/';
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
Copyright 2015, 2016 OpenMarket Ltd
|
Copyright 2015, 2016 OpenMarket Ltd
|
||||||
Copyright 2017 Vector Creations Ltd
|
Copyright 2017 Vector Creations Ltd
|
||||||
Copyright 2018, 2019 New Vector Ltd
|
Copyright 2018, 2019 New Vector Ltd
|
||||||
|
Copyright 2019 Michael Telatynski <7t3chguy@gmail.com>
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
@ -43,7 +44,6 @@ import PlatformPeg from 'matrix-react-sdk/lib/PlatformPeg';
|
||||||
sdk.loadSkin(require('../component-index'));
|
sdk.loadSkin(require('../component-index'));
|
||||||
import VectorConferenceHandler from 'matrix-react-sdk/lib/VectorConferenceHandler';
|
import VectorConferenceHandler from 'matrix-react-sdk/lib/VectorConferenceHandler';
|
||||||
import Promise from 'bluebird';
|
import Promise from 'bluebird';
|
||||||
import request from 'browser-request';
|
|
||||||
import * as languageHandler from 'matrix-react-sdk/lib/languageHandler';
|
import * as languageHandler from 'matrix-react-sdk/lib/languageHandler';
|
||||||
import {_t, _td, newTranslatableError} from 'matrix-react-sdk/lib/languageHandler';
|
import {_t, _td, newTranslatableError} from 'matrix-react-sdk/lib/languageHandler';
|
||||||
import AutoDiscoveryUtils from 'matrix-react-sdk/lib/utils/AutoDiscoveryUtils';
|
import AutoDiscoveryUtils from 'matrix-react-sdk/lib/utils/AutoDiscoveryUtils';
|
||||||
|
@ -66,8 +66,6 @@ import Olm from 'olm';
|
||||||
|
|
||||||
import CallHandler from 'matrix-react-sdk/lib/CallHandler';
|
import CallHandler from 'matrix-react-sdk/lib/CallHandler';
|
||||||
|
|
||||||
import {getVectorConfig} from './getconfig';
|
|
||||||
|
|
||||||
let lastLocationHashSet = null;
|
let lastLocationHashSet = null;
|
||||||
|
|
||||||
// Disable warnings for now: we use deprecated bluebird functions
|
// Disable warnings for now: we use deprecated bluebird functions
|
||||||
|
@ -119,7 +117,7 @@ function routeUrl(location) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function onHashChange(ev) {
|
function onHashChange(ev) {
|
||||||
if (decodeURIComponent(window.location.hash) == lastLocationHashSet) {
|
if (decodeURIComponent(window.location.hash) === lastLocationHashSet) {
|
||||||
// we just set this: no need to route it!
|
// we just set this: no need to route it!
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -159,7 +157,7 @@ function makeRegistrationUrl(params) {
|
||||||
|
|
||||||
const keys = Object.keys(params);
|
const keys = Object.keys(params);
|
||||||
for (let i = 0; i < keys.length; ++i) {
|
for (let i = 0; i < keys.length; ++i) {
|
||||||
if (i == 0) {
|
if (i === 0) {
|
||||||
url += '?';
|
url += '?';
|
||||||
} else {
|
} else {
|
||||||
url += '&';
|
url += '&';
|
||||||
|
@ -170,38 +168,6 @@ function makeRegistrationUrl(params) {
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getConfig(configJsonFilename) {
|
|
||||||
return new Promise(function(resolve, reject) {
|
|
||||||
request(
|
|
||||||
{ method: "GET", url: configJsonFilename },
|
|
||||||
(err, response, body) => {
|
|
||||||
if (err || response.status < 200 || response.status >= 300) {
|
|
||||||
// Lack of a config isn't an error, we should
|
|
||||||
// just use the defaults.
|
|
||||||
// Also treat a blank config as no config, assuming
|
|
||||||
// the status code is 0, because we don't get 404s
|
|
||||||
// from file: URIs so this is the only way we can
|
|
||||||
// not fail if the file doesn't exist when loading
|
|
||||||
// from a file:// URI.
|
|
||||||
if (response) {
|
|
||||||
if (response.status == 404 || (response.status == 0 && body == '')) {
|
|
||||||
resolve({});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
reject({err: err, response: response});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// We parse the JSON ourselves rather than use the JSON
|
|
||||||
// parameter, since this throws a parse error on empty
|
|
||||||
// which breaks if there's no config.json and we're
|
|
||||||
// loading from the filesystem (see above).
|
|
||||||
resolve(JSON.parse(body));
|
|
||||||
},
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function onTokenLoginCompleted() {
|
function onTokenLoginCompleted() {
|
||||||
// if we did a token login, we're now left with the token, hs and is
|
// if we did a token login, we're now left with the token, hs and is
|
||||||
// url as query params in the url; a little nasty but let's redirect to
|
// url as query params in the url; a little nasty but let's redirect to
|
||||||
|
@ -252,12 +218,12 @@ async function loadApp() {
|
||||||
PlatformPeg.set(new WebPlatform());
|
PlatformPeg.set(new WebPlatform());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load the config file. First try to load up a domain-specific config of the
|
const platform = PlatformPeg.get();
|
||||||
// form "config.$domain.json" and if that fails, fall back to config.json.
|
|
||||||
let configJson;
|
let configJson;
|
||||||
let configError;
|
let configError;
|
||||||
try {
|
try {
|
||||||
configJson = await getVectorConfig();
|
configJson = await platform.getConfig();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
configError = e;
|
configError = e;
|
||||||
}
|
}
|
||||||
|
@ -342,7 +308,6 @@ async function loadApp() {
|
||||||
Unable to load config file: please refresh the page to try again.
|
Unable to load config file: please refresh the page to try again.
|
||||||
</div>, document.getElementById('matrixchat'));
|
</div>, document.getElementById('matrixchat'));
|
||||||
} else if (validBrowser || acceptInvalidBrowser) {
|
} else if (validBrowser || acceptInvalidBrowser) {
|
||||||
const platform = PlatformPeg.get();
|
|
||||||
platform.startUpdater();
|
platform.startUpdater();
|
||||||
|
|
||||||
// Don't bother loading the app until the config is verified
|
// Don't bother loading the app until the config is verified
|
||||||
|
@ -410,7 +375,7 @@ function loadOlm() {
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
console.log("Using WebAssembly Olm");
|
console.log("Using WebAssembly Olm");
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
console.log("Failed to load Olm: trying legacy version");
|
console.log("Failed to load Olm: trying legacy version", e);
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const s = document.createElement('script');
|
const s = document.createElement('script');
|
||||||
s.src = 'olm_legacy.js'; // XXX: This should be cache-busted too
|
s.src = 'olm_legacy.js'; // XXX: This should be cache-busted too
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
Copyright 2016 Aviral Dasgupta
|
Copyright 2016 Aviral Dasgupta
|
||||||
Copyright 2016 OpenMarket Ltd
|
Copyright 2016 OpenMarket Ltd
|
||||||
Copyright 2018 New Vector Ltd
|
Copyright 2018 New Vector Ltd
|
||||||
|
Copyright 2019 Michael Telatynski <7t3chguy@gmail.com>
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
@ -101,6 +102,10 @@ export default class ElectronPlatform extends VectorBasePlatform {
|
||||||
this.stopUpdateCheck = this.stopUpdateCheck.bind(this);
|
this.stopUpdateCheck = this.stopUpdateCheck.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getConfig(): Promise<{}> {
|
||||||
|
return this._ipcCall('getConfig');
|
||||||
|
}
|
||||||
|
|
||||||
async onUpdateDownloaded(ev, updateInfo) {
|
async onUpdateDownloaded(ev, updateInfo) {
|
||||||
dis.dispatch({
|
dis.dispatch({
|
||||||
action: 'new_version',
|
action: 'new_version',
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
Copyright 2016 Aviral Dasgupta
|
Copyright 2016 Aviral Dasgupta
|
||||||
Copyright 2016 OpenMarket Ltd
|
Copyright 2016 OpenMarket Ltd
|
||||||
Copyright 2018 New Vector Ltd
|
Copyright 2018 New Vector Ltd
|
||||||
|
Copyright 2019 Michael Telatynski <7t3chguy@gmail.com>
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
@ -21,6 +22,7 @@ limitations under the License.
|
||||||
import BasePlatform from 'matrix-react-sdk/lib/BasePlatform';
|
import BasePlatform from 'matrix-react-sdk/lib/BasePlatform';
|
||||||
import { _t } from 'matrix-react-sdk/lib/languageHandler';
|
import { _t } from 'matrix-react-sdk/lib/languageHandler';
|
||||||
import dis from 'matrix-react-sdk/lib/dispatcher';
|
import dis from 'matrix-react-sdk/lib/dispatcher';
|
||||||
|
import {getVectorConfig} from "../getconfig";
|
||||||
|
|
||||||
import Favico from 'favico.js';
|
import Favico from 'favico.js';
|
||||||
|
|
||||||
|
@ -44,6 +46,10 @@ export default class VectorBasePlatform extends BasePlatform {
|
||||||
this.stopUpdateCheck = this.stopUpdateCheck.bind(this);
|
this.stopUpdateCheck = this.stopUpdateCheck.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getConfig(): Promise<{}> {
|
||||||
|
return getVectorConfig();
|
||||||
|
}
|
||||||
|
|
||||||
getHumanReadableName(): string {
|
getHumanReadableName(): string {
|
||||||
return 'Vector Base Platform'; // no translation required: only used for analytics
|
return 'Vector Base Platform'; // no translation required: only used for analytics
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue