use readyForUpdates to trigger update from renderer

this is used to only start the updater once the fileserver returned use
the latest release
This commit is contained in:
Audric Ackermann 2022-03-21 16:29:07 +11:00
parent 234e9b160e
commit 89757a95a6
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4
18 changed files with 48 additions and 117 deletions

View File

@ -63,9 +63,7 @@ jobs:
- name: Lint Files - name: Lint Files
if: runner.os != 'Windows' if: runner.os != 'Windows'
run: | run: |
yarn format-full yarn lint-full
yarn eslint
yarn tslint
- name: Make linux use en_US locale - name: Make linux use en_US locale
if: runner.os == 'Linux' if: runner.os == 'Linux'

View File

@ -4,7 +4,6 @@ const process = require('process');
const { app } = require('electron'); const { app } = require('electron');
const { start } = require('./base_config'); const { start } = require('./base_config');
const config = require('./config');
let storageProfile; let storageProfile;
@ -16,10 +15,7 @@ const isValidInstance = typeof instance === 'string' && instance.length > 0;
const isProduction = environment === 'production' && !isValidInstance; const isProduction = environment === 'production' && !isValidInstance;
// Use seperate data directories for each different environment and app instances // Use seperate data directories for each different environment and app instances
// We should prioritise config values first if (!isProduction) {
if (config.has(storageProfile)) {
storageProfile = config.get('storageProfile');
} else if (!isProduction) {
storageProfile = environment; storageProfile = environment;
if (isValidInstance) { if (isValidInstance) {
storageProfile = storageProfile.concat(`-${instance}`); storageProfile = storageProfile.concat(`-${instance}`);

View File

@ -1,20 +1,4 @@
{ {
"serverUrl": "random.snode",
"localUrl": "localhost.loki",
"cdnUrl": "random.snode",
"contentProxyUrl": "",
"seedNodeList": [
{
"url": "https://storage.seed1.loki.network:4433/"
},
{
"url": "https://storage.seed3.loki.network:4433/"
},
{
"url": "https://public.loki.foundation:4433/"
}
],
"openDevTools": false,
"commitHash": "", "commitHash": "",
"import": false "import": false
} }

View File

@ -1,8 +0,0 @@
{
"seedNodeList": [
{
"url": "http://public.loki.foundation:38157/"
}
],
"openDevTools": false
}

View File

@ -1,3 +0,0 @@
{
"openDevTools": false
}

View File

@ -1,3 +0,0 @@
{
"openDevTools": true
}

View File

@ -1,3 +0,0 @@
{
"openDevTools": true
}

View File

@ -1,8 +0,0 @@
{
"seedNodeList": [
{
"url": "http://localhost:22129/"
}
],
"openDevTools": true
}

View File

@ -1,4 +0,0 @@
{
"storageProfile": "test",
"openDevTools": false
}

View File

@ -1,4 +0,0 @@
{
"storageProfile": "test",
"openDevTools": false
}

View File

@ -386,7 +386,7 @@
} }
let connectCount = 0; let connectCount = 0;
async function connect(firstRun) { async function connect() {
window.log.info('connect'); window.log.info('connect');
// Bootstrap our online/offline detection, only the first time we connect // Bootstrap our online/offline detection, only the first time we connect
@ -400,10 +400,6 @@
return; return;
} }
if (firstRun) {
window.readyForUpdates();
}
if (!Whisper.Registration.everDone()) { if (!Whisper.Registration.everDone()) {
return; return;
} }

14
main.js
View File

@ -157,17 +157,11 @@ function prepareURL(pathSegments, moreKeys) {
locale: locale.name, locale: locale.name,
version: app.getVersion(), version: app.getVersion(),
commitHash: config.get('commitHash'), commitHash: config.get('commitHash'),
serverUrl: config.get('serverUrl'),
localUrl: config.get('localUrl'),
cdnUrl: config.get('cdnUrl'),
// one day explain why we need to do this - neuroscr
seedNodeList: JSON.stringify(config.get('seedNodeList')),
environment: config.environment, environment: config.environment,
node_version: process.versions.node, node_version: process.versions.node,
hostname: os.hostname(), hostname: os.hostname(),
appInstance: process.env.NODE_APP_INSTANCE, appInstance: process.env.NODE_APP_INSTANCE,
proxyUrl: process.env.HTTPS_PROXY || process.env.https_proxy, proxyUrl: process.env.HTTPS_PROXY || process.env.https_proxy,
contentProxyUrl: config.contentProxyUrl,
appStartInitialSpellcheckSetting, appStartInitialSpellcheckSetting,
...moreKeys, ...moreKeys,
}, },
@ -346,7 +340,7 @@ async function createWindow() {
mainWindow.loadURL(prepareURL([__dirname, 'background.html'])); mainWindow.loadURL(prepareURL([__dirname, 'background.html']));
if (config.get('openDevTools')) { if ((process.env.NODE_APP_INSTANCE || '').startsWith('devprod')) {
// Open the DevTools. // Open the DevTools.
mainWindow.webContents.openDevTools({ mainWindow.webContents.openDevTools({
mode: 'bottom', mode: 'bottom',
@ -414,7 +408,7 @@ ipc.on('set-release-from-file-server', (_event, releaseGotFromFileServer) => {
let isReadyForUpdates = false; let isReadyForUpdates = false;
async function readyForUpdates() { async function readyForUpdates() {
console.log('isReadyForUpdates', isReadyForUpdates); console.log('[updater] isReadyForUpdates', isReadyForUpdates);
if (isReadyForUpdates) { if (isReadyForUpdates) {
return; return;
} }
@ -423,6 +417,7 @@ async function readyForUpdates() {
// Second, start checking for app updates // Second, start checking for app updates
try { try {
// if the user disabled auto updates, this will actually not start the updater
await updater.start(getMainWindow, userConfig, locale.messages, logger); await updater.start(getMainWindow, userConfig, locale.messages, logger);
} catch (error) { } catch (error) {
const log = logger || console; const log = logger || console;
@ -703,9 +698,6 @@ async function showMainWindow(sqlKey, passwordAttempt = false) {
} }
setupMenu(); setupMenu();
// Check updates
readyForUpdates();
} }
function setupMenu(options) { function setupMenu(options) {

View File

@ -15,10 +15,8 @@
"main": "main.js", "main": "main.js",
"scripts": { "scripts": {
"postinstall": "electron-builder install-app-deps && rimraf node_modules/dtrace-provider", "postinstall": "electron-builder install-app-deps && rimraf node_modules/dtrace-provider",
"start": "cross-env NODE_APP_INSTANCE=$MULTI electron .",
"start-prod": "cross-env NODE_ENV=production NODE_APP_INSTANCE=devprod$MULTI electron .", "start-prod": "cross-env NODE_ENV=production NODE_APP_INSTANCE=devprod$MULTI electron .",
"grunt": "yarn clean-transpile && grunt", "grunt": "yarn clean-transpile && grunt",
"grunt:dev": "yarn clean-transpile; yarn grunt dev --force",
"generate": "yarn grunt --force", "generate": "yarn grunt --force",
"build-release": "run-script-os", "build-release": "run-script-os",
"build-release-non-linux": "cross-env SIGNAL_ENV=production electron-builder --config.extraMetadata.environment=production --publish=never --config.directories.output=release", "build-release-non-linux": "cross-env SIGNAL_ENV=production electron-builder --config.extraMetadata.environment=production --publish=never --config.directories.output=release",
@ -26,26 +24,20 @@
"build-release:macos": "yarn build-release-non-linux", "build-release:macos": "yarn build-release-non-linux",
"build-release:linux": "yarn sedtoDeb; yarn build-release-non-linux && yarn sedtoAppImage && yarn build-release-non-linux && yarn sedtoDeb", "build-release:linux": "yarn sedtoDeb; yarn build-release-non-linux && yarn sedtoAppImage && yarn build-release-non-linux && yarn sedtoDeb",
"build-release-publish": "run-script-os", "build-release-publish": "run-script-os",
"build-release-publish-non-linux": "$(yarn bin)/electron-builder --config.extraMetadata.environment=$SIGNAL_ENV --publish=always", "build-release-publish-non-linux": "cross-env SIGNAL_ENV=production $(yarn bin)/electron-builder --config.extraMetadata.environment=$SIGNAL_ENV --publish=always",
"build-release-publish:win32": "yarn build-release-publish-non-linux", "build-release-publish:win32": "yarn build-release-publish-non-linux",
"build-release-publish:macos": "yarn build-release-publish-non-linux", "build-release-publish:macos": "yarn build-release-publish-non-linux",
"build-release-publish:linux": "yarn sedtoDeb; yarn build-release-publish-non-linux && yarn sedtoAppImage && yarn build-release-publish-non-linux && yarn sedtoDeb", "build-release-publish:linux": "yarn sedtoDeb; yarn build-release-publish-non-linux && yarn sedtoAppImage && yarn build-release-publish-non-linux && yarn sedtoDeb",
"build-module-protobuf": "pbjs --target static-module --wrap commonjs --out ts/protobuf/compiled.js protos/*.proto && pbts --out ts/protobuf/compiled.d.ts ts/protobuf/compiled.js --force-long", "appImage": "yarn sedtoAppImage; yarn build-release-non-linux; yarn sedtoDeb",
"clean-module-protobuf": "rimraf ts/protobuf/compiled.d.ts ts/protobuf/compiled.js", "build-protobuf": "pbjs --target static-module --wrap commonjs --out ts/protobuf/compiled.js protos/*.proto && pbts --out ts/protobuf/compiled.d.ts ts/protobuf/compiled.js --force-long",
"build-protobuf": "yarn build-module-protobuf", "test": "mocha --recursive --exit --timeout 10000 \"./ts/test/**/*_test.js\" ",
"clean-protobuf": "yarn clean-module-protobuf", "lint-full": "yarn format-full && eslint . && tslint --format stylish --project .",
"test": "yarn test-node",
"test-node": "mocha --recursive --exit --timeout 10000 \"./ts/test/**/*_test.js\" ",
"eslint-full": "eslint .",
"lint-full": "yarn format-full && yarn lint-files-full",
"lint-files-full": "yarn eslint-full && yarn tslint",
"tslint": "tslint --format stylish --project .",
"format-full": "prettier --list-different --write \"*.{css,js,json,scss,ts,tsx}\" \"./**/*.{css,js,json,scss,ts,tsx}\"", "format-full": "prettier --list-different --write \"*.{css,js,json,scss,ts,tsx}\" \"./**/*.{css,js,json,scss,ts,tsx}\"",
"transpile": "tsc --incremental", "transpile": "tsc --incremental",
"transpile:watch": "yarn grunt --force; tsc -w", "transpile:watch": "yarn grunt --force; tsc -w",
"integration-test": "mocha --recursive --exit --timeout 30000 \"./ts/test-integration/**/*.test.js\" \"./ts/test/*.test.js\"", "integration-test": "mocha --recursive --exit --timeout 30000 \"./ts/test-integration/**/*.test.js\" \"./ts/test/*.test.js\"",
"clean-transpile": "rimraf 'ts/**/*.js' 'ts/*.js' 'ts/*.js.map' 'ts/**/*.js.map' && rimraf tsconfig.tsbuildinfo;", "clean-transpile": "rimraf 'ts/**/*.js' 'ts/*.js' 'ts/*.js.map' 'ts/**/*.js.map' && rimraf tsconfig.tsbuildinfo;",
"ready": "yarn clean-transpile; yarn grunt && yarn lint-full && yarn test", "ready": "yarn grunt && yarn lint-full && yarn test",
"sedtoAppImage": "sed -i 's/\"target\": \\[\"deb\", \"rpm\", \"freebsd\"\\]/\"target\": \"AppImage\"/g' package.json", "sedtoAppImage": "sed -i 's/\"target\": \\[\"deb\", \"rpm\", \"freebsd\"\\]/\"target\": \"AppImage\"/g' package.json",
"sedtoDeb": "sed -i 's/\"target\": \"AppImage\"/\"target\": \\[\"deb\", \"rpm\", \"freebsd\"\\]/g' package.json" "sedtoDeb": "sed -i 's/\"target\": \"AppImage\"/\"target\": \\[\"deb\", \"rpm\", \"freebsd\"\\]/g' package.json"
}, },
@ -65,7 +57,6 @@
"color": "^3.1.2", "color": "^3.1.2",
"config": "1.28.1", "config": "1.28.1",
"country-code-lookup": "^0.0.19", "country-code-lookup": "^0.0.19",
"cross-env": "^6.0.3",
"curve25519-js": "^0.0.4", "curve25519-js": "^0.0.4",
"dompurify": "^2.0.7", "dompurify": "^2.0.7",
"electron-is-dev": "^1.1.0", "electron-is-dev": "^1.1.0",
@ -162,6 +153,7 @@
"chai": "^4.3.4", "chai": "^4.3.4",
"chai-as-promised": "^7.1.1", "chai-as-promised": "^7.1.1",
"chai-bytes": "^0.1.2", "chai-bytes": "^0.1.2",
"cross-env": "^6.0.3",
"electron": "^13.6.2", "electron": "^13.6.2",
"electron-builder": "22.8.0", "electron-builder": "22.8.0",
"electron-notarize": "^0.2.0", "electron-notarize": "^0.2.0",

View File

@ -211,7 +211,17 @@ window.ReactDOM = require('react-dom');
window.clipboard = clipboard; window.clipboard = clipboard;
window.getSeedNodeList = () => JSON.parse(config.seedNodeList); window.getSeedNodeList = () => [
{
url: 'https://storage.seed1.loki.network:4433/',
},
{
url: 'https://storage.seed3.loki.network:4433/',
},
{
url: 'https://public.loki.foundation:4433/',
},
];
const { locale: localFromEnv } = config; const { locale: localFromEnv } = config;
window.i18n = i18n.setup(localFromEnv, localeMessages); window.i18n = i18n.setup(localFromEnv, localeMessages);

View File

@ -169,7 +169,7 @@ const cleanUpMediasInterval = DURATION.MINUTES * 60;
// every 10 minutes we fetch from the fileserver to check for a new release // every 10 minutes we fetch from the fileserver to check for a new release
// * if there is none, no request to github are made. // * if there is none, no request to github are made.
// * if there is a version on the fileserver more recent than our current, we fetch github to get the UpdateInfos and trigger an update as usual (asking user via dialog) // * if there is a version on the fileserver more recent than our current, we fetch github to get the UpdateInfos and trigger an update as usual (asking user via dialog)
const fetchReleaseFromFileServerInterval = DURATION.MINUTES * 10; const fetchReleaseFromFileServerInterval = 1000 * 60; // try to fetch the latest release from the fileserver every minute
const setupTheme = () => { const setupTheme = () => {
const theme = window.Events.getThemeSetting(); const theme = window.Events.getThemeSetting();
@ -274,10 +274,14 @@ const CallContainer = () => {
async function fetchReleaseFromFSAndUpdateMain() { async function fetchReleaseFromFSAndUpdateMain() {
try { try {
window.log.warn('[updater] about to fetchReleaseFromFSAndUpdateMain');
const latest = await getLatestDesktopReleaseFileToFsV2(); const latest = await getLatestDesktopReleaseFileToFsV2();
window.log.warn('[updater] fetched latest release from fsv2: ', latest);
if (isString(latest) && !isEmpty(latest)) { if (isString(latest) && !isEmpty(latest)) {
ipcRenderer.send('set-release-from-file-server', latest); ipcRenderer.send('set-release-from-file-server', latest);
window.readyForUpdates();
} }
} catch (e) { } catch (e) {
window.log.warn(e); window.log.warn(e);

View File

@ -4,7 +4,7 @@ import { LoggerType, MessagesType } from './common';
import { UserConfig } from '../../app/user_config'; import { UserConfig } from '../../app/user_config';
let initialized = false; let initialized = false;
let config: UserConfig; let localUserConfig: UserConfig;
export async function start( export async function start(
getMainWindow: () => BrowserWindow, getMainWindow: () => BrowserWindow,
@ -27,16 +27,9 @@ export async function start(
throw new Error('updater/start: Must provide logger!'); throw new Error('updater/start: Must provide logger!');
} }
initialized = true; initialized = true;
config = userConfig; // reused below localUserConfig = userConfig; // reused below
if (autoUpdateDisabled()) { if (autoUpdateDisabled()) {
/*
If you really want to enable auto-updating in dev mode
You need to create a dev-app-update.yml file.
A sample can be found in dev-app-update.yml.sample.
After that you can change `updatesEnabled` to `true` in the default config.
*/
logger.info('updater/start: Updates disabled - not starting new version checks'); logger.info('updater/start: Updates disabled - not starting new version checks');
return; return;
@ -54,7 +47,7 @@ export function stop() {
function autoUpdateDisabled() { function autoUpdateDisabled() {
// We need to ensure that if auto update is not present in the user config then we assume it is on by default // We need to ensure that if auto update is not present in the user config then we assume it is on by default
const userSetting = config.get('autoUpdate'); const userSetting = localUserConfig.get('autoUpdate');
const autoUpdate = typeof userSetting !== 'boolean' || userSetting; const autoUpdate = typeof userSetting !== 'boolean' || userSetting;
return ( return (

View File

@ -19,10 +19,6 @@ let downloadIgnored = false;
let interval: NodeJS.Timeout | undefined; let interval: NodeJS.Timeout | undefined;
let stopped = false; let stopped = false;
const SECOND = 1000;
const MINUTE = SECOND * 60;
const INTERVAL = MINUTE * 1;
export async function start( export async function start(
getMainWindow: () => BrowserWindow, getMainWindow: () => BrowserWindow,
messages: MessagesType, messages: MessagesType,
@ -45,7 +41,7 @@ export async function start(
} catch (error) { } catch (error) {
logger.error('auto-update: error:', getPrintableError(error)); logger.error('auto-update: error:', getPrintableError(error));
} }
}, INTERVAL); }, 1000 * 60 * 10); // trigger and try to update every 10 minutes to let the file gets downloaded if we are updating
stopped = false; stopped = false;
await checkForUpdates(getMainWindow, messages, logger); await checkForUpdates(getMainWindow, messages, logger);
@ -64,17 +60,19 @@ async function checkForUpdates(
messages: MessagesType, messages: MessagesType,
logger: LoggerType logger: LoggerType
) { ) {
logger.info('[updater] checkForUpdates');
if (stopped || isUpdating || downloadIgnored) { if (stopped || isUpdating || downloadIgnored) {
return; return;
} }
const canUpdate = await canAutoUpdate(); const canUpdate = await canAutoUpdate();
logger.info('[updater] canUpdate', canUpdate);
if (!canUpdate) { if (!canUpdate) {
logger.info('checkForUpdates canAutoUpdate false'); logger.info('checkForUpdates canAutoUpdate false');
return; return;
} }
logger.info('auto-update: checkForUpdates...'); logger.info('[updater] checkForUpdates...');
isUpdating = true; isUpdating = true;
@ -83,17 +81,17 @@ async function checkForUpdates(
? ((getMainWindow() as any).getLatestDesktopRelease() as string | undefined) ? ((getMainWindow() as any).getLatestDesktopRelease() as string | undefined)
: undefined; : undefined;
logger.info('checkForUpdates latestVersionFromFsFromRenderer', latestVersionFromFsFromRenderer); logger.info('[updater] latestVersionFromFsFromRenderer', latestVersionFromFsFromRenderer);
if (!latestVersionFromFsFromRenderer || !latestVersionFromFsFromRenderer?.length) { if (!latestVersionFromFsFromRenderer || !latestVersionFromFsFromRenderer?.length) {
logger.info( logger.info(
'testVersionFromFsFromRenderer was not updated yet by renderer. Skipping update check' '[updater] testVersionFromFsFromRenderer was not updated yet by renderer. Skipping update check'
); );
return; return;
} }
const currentVersion = autoUpdater.currentVersion.toString(); const currentVersion = autoUpdater.currentVersion.toString();
const isMoreRecent = isVersionGreaterThan(latestVersionFromFsFromRenderer, currentVersion); const isMoreRecent = isVersionGreaterThan(latestVersionFromFsFromRenderer, currentVersion);
logger.info('checkForUpdates isMoreRecent', isMoreRecent); logger.info('[updater] checkForUpdates isMoreRecent', isMoreRecent);
if (!isMoreRecent) { if (!isMoreRecent) {
logger.info( logger.info(
`Fileserver has no update so we are not looking for an update from github current:${currentVersion} fromFileServer:${latestVersionFromFsFromRenderer}` `Fileserver has no update so we are not looking for an update from github current:${currentVersion} fromFileServer:${latestVersionFromFsFromRenderer}`
@ -104,27 +102,27 @@ async function checkForUpdates(
// Get the update using electron-updater, this fetches from github // Get the update using electron-updater, this fetches from github
const result = await autoUpdater.checkForUpdates(); const result = await autoUpdater.checkForUpdates();
logger.info('checkForUpdates github fetch result:', result); logger.info('[updater] checkForUpdates got github response back ');
if (!result.updateInfo) { if (!result.updateInfo) {
logger.info('auto-update: no update info received'); logger.info('[updater] no update info received');
return; return;
} }
try { try {
const hasUpdate = isUpdateAvailable(result.updateInfo); const hasUpdate = isUpdateAvailable(result.updateInfo);
logger.info('checkForUpdates hasUpdate:', hasUpdate); logger.info('[updater] hasUpdate:', hasUpdate);
if (!hasUpdate) { if (!hasUpdate) {
logger.info('auto-update: no update available'); logger.info('[updater] no update available');
return; return;
} }
logger.info('auto-update: showing download dialog...'); logger.info('[updater] showing download dialog...');
const shouldDownload = await showDownloadUpdateDialog(getMainWindow(), messages); const shouldDownload = await showDownloadUpdateDialog(getMainWindow(), messages);
logger.info('checkForUpdates shouldDownload:', shouldDownload); logger.info('[updater] shouldDownload:', shouldDownload);
if (!shouldDownload) { if (!shouldDownload) {
downloadIgnored = true; downloadIgnored = true;
@ -139,13 +137,13 @@ async function checkForUpdates(
} }
// Update downloaded successfully, we should ask the user to update // Update downloaded successfully, we should ask the user to update
logger.info('auto-update: showing update dialog...'); logger.info('[updater] showing update dialog...');
const shouldUpdate = await showUpdateDialog(getMainWindow(), messages); const shouldUpdate = await showUpdateDialog(getMainWindow(), messages);
if (!shouldUpdate) { if (!shouldUpdate) {
return; return;
} }
logger.info('auto-update: calling quitAndInstall...'); logger.info('[updater] calling quitAndInstall...');
markShouldQuit(); markShouldQuit();
autoUpdater.quitAndInstall(); autoUpdater.quitAndInstall();
} finally { } finally {

1
ts/window.d.ts vendored
View File

@ -59,6 +59,7 @@ declare global {
userConfig: any; userConfig: any;
versionInfo: any; versionInfo: any;
getConversations: () => ConversationCollection; getConversations: () => ConversationCollection;
readyForUpdates: () => void;
MediaRecorder: any; MediaRecorder: any;
contextMenuShown: boolean; contextMenuShown: boolean;