From 89757a95a66dde3828ce5a3a9a70bc18abd573e8 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Mon, 21 Mar 2022 16:29:07 +1100 Subject: [PATCH] use readyForUpdates to trigger update from renderer this is used to only start the updater once the fileserver returned use the latest release --- .github/workflows/pull-request.yml | 4 +--- app/user_config.js | 6 +---- config/default.json | 16 ------------- config/development.json | 8 ------- config/integration-test.json | 3 --- config/production-devprod.json | 3 --- config/production-devprod1.json | 3 --- config/swarm-testing.json | 8 ------- config/test-lib.json | 4 ---- config/test.json | 4 ---- js/background.js | 6 +---- main.js | 14 +++-------- package.json | 22 ++++++----------- preload.js | 12 +++++++++- ts/components/leftpane/ActionsPanel.tsx | 6 ++++- ts/updater/index.ts | 13 +++------- ts/updater/updater.ts | 32 ++++++++++++------------- ts/window.d.ts | 1 + 18 files changed, 48 insertions(+), 117 deletions(-) delete mode 100644 config/development.json delete mode 100644 config/integration-test.json delete mode 100644 config/production-devprod.json delete mode 100644 config/production-devprod1.json delete mode 100644 config/swarm-testing.json delete mode 100644 config/test-lib.json delete mode 100644 config/test.json diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 607f2b8db..cb8330afc 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -63,9 +63,7 @@ jobs: - name: Lint Files if: runner.os != 'Windows' run: | - yarn format-full - yarn eslint - yarn tslint + yarn lint-full - name: Make linux use en_US locale if: runner.os == 'Linux' diff --git a/app/user_config.js b/app/user_config.js index 0829c2968..671a1c217 100644 --- a/app/user_config.js +++ b/app/user_config.js @@ -4,7 +4,6 @@ const process = require('process'); const { app } = require('electron'); const { start } = require('./base_config'); -const config = require('./config'); let storageProfile; @@ -16,10 +15,7 @@ const isValidInstance = typeof instance === 'string' && instance.length > 0; const isProduction = environment === 'production' && !isValidInstance; // Use seperate data directories for each different environment and app instances -// We should prioritise config values first -if (config.has(storageProfile)) { - storageProfile = config.get('storageProfile'); -} else if (!isProduction) { +if (!isProduction) { storageProfile = environment; if (isValidInstance) { storageProfile = storageProfile.concat(`-${instance}`); diff --git a/config/default.json b/config/default.json index eb0af8788..2eb222d03 100644 --- a/config/default.json +++ b/config/default.json @@ -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": "", "import": false } diff --git a/config/development.json b/config/development.json deleted file mode 100644 index de5685da7..000000000 --- a/config/development.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "seedNodeList": [ - { - "url": "http://public.loki.foundation:38157/" - } - ], - "openDevTools": false -} diff --git a/config/integration-test.json b/config/integration-test.json deleted file mode 100644 index ce063c126..000000000 --- a/config/integration-test.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "openDevTools": false -} diff --git a/config/production-devprod.json b/config/production-devprod.json deleted file mode 100644 index 7791e7862..000000000 --- a/config/production-devprod.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "openDevTools": true -} diff --git a/config/production-devprod1.json b/config/production-devprod1.json deleted file mode 100644 index 7791e7862..000000000 --- a/config/production-devprod1.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "openDevTools": true -} diff --git a/config/swarm-testing.json b/config/swarm-testing.json deleted file mode 100644 index d96c1116e..000000000 --- a/config/swarm-testing.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "seedNodeList": [ - { - "url": "http://localhost:22129/" - } - ], - "openDevTools": true -} diff --git a/config/test-lib.json b/config/test-lib.json deleted file mode 100644 index ade27eef3..000000000 --- a/config/test-lib.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "storageProfile": "test", - "openDevTools": false -} diff --git a/config/test.json b/config/test.json deleted file mode 100644 index ade27eef3..000000000 --- a/config/test.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "storageProfile": "test", - "openDevTools": false -} diff --git a/js/background.js b/js/background.js index 3eb206470..541c9645c 100644 --- a/js/background.js +++ b/js/background.js @@ -386,7 +386,7 @@ } let connectCount = 0; - async function connect(firstRun) { + async function connect() { window.log.info('connect'); // Bootstrap our online/offline detection, only the first time we connect @@ -400,10 +400,6 @@ return; } - if (firstRun) { - window.readyForUpdates(); - } - if (!Whisper.Registration.everDone()) { return; } diff --git a/main.js b/main.js index 59255c614..19d9dda5d 100644 --- a/main.js +++ b/main.js @@ -157,17 +157,11 @@ function prepareURL(pathSegments, moreKeys) { locale: locale.name, version: app.getVersion(), 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, node_version: process.versions.node, hostname: os.hostname(), appInstance: process.env.NODE_APP_INSTANCE, proxyUrl: process.env.HTTPS_PROXY || process.env.https_proxy, - contentProxyUrl: config.contentProxyUrl, appStartInitialSpellcheckSetting, ...moreKeys, }, @@ -346,7 +340,7 @@ async function createWindow() { mainWindow.loadURL(prepareURL([__dirname, 'background.html'])); - if (config.get('openDevTools')) { + if ((process.env.NODE_APP_INSTANCE || '').startsWith('devprod')) { // Open the DevTools. mainWindow.webContents.openDevTools({ mode: 'bottom', @@ -414,7 +408,7 @@ ipc.on('set-release-from-file-server', (_event, releaseGotFromFileServer) => { let isReadyForUpdates = false; async function readyForUpdates() { - console.log('isReadyForUpdates', isReadyForUpdates); + console.log('[updater] isReadyForUpdates', isReadyForUpdates); if (isReadyForUpdates) { return; } @@ -423,6 +417,7 @@ async function readyForUpdates() { // Second, start checking for app updates try { + // if the user disabled auto updates, this will actually not start the updater await updater.start(getMainWindow, userConfig, locale.messages, logger); } catch (error) { const log = logger || console; @@ -703,9 +698,6 @@ async function showMainWindow(sqlKey, passwordAttempt = false) { } setupMenu(); - - // Check updates - readyForUpdates(); } function setupMenu(options) { diff --git a/package.json b/package.json index 742aec818..fa7f96910 100644 --- a/package.json +++ b/package.json @@ -15,10 +15,8 @@ "main": "main.js", "scripts": { "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 .", "grunt": "yarn clean-transpile && grunt", - "grunt:dev": "yarn clean-transpile; yarn grunt dev --force", "generate": "yarn grunt --force", "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", @@ -26,26 +24,20 @@ "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-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: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-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", - "clean-module-protobuf": "rimraf ts/protobuf/compiled.d.ts ts/protobuf/compiled.js", - "build-protobuf": "yarn build-module-protobuf", - "clean-protobuf": "yarn clean-module-protobuf", - "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 .", + "appImage": "yarn sedtoAppImage; yarn build-release-non-linux; yarn sedtoDeb", + "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", + "test": "mocha --recursive --exit --timeout 10000 \"./ts/test/**/*_test.js\" ", + "lint-full": "yarn format-full && eslint . && tslint --format stylish --project .", "format-full": "prettier --list-different --write \"*.{css,js,json,scss,ts,tsx}\" \"./**/*.{css,js,json,scss,ts,tsx}\"", "transpile": "tsc --incremental", "transpile:watch": "yarn grunt --force; tsc -w", "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;", - "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", "sedtoDeb": "sed -i 's/\"target\": \"AppImage\"/\"target\": \\[\"deb\", \"rpm\", \"freebsd\"\\]/g' package.json" }, @@ -65,7 +57,6 @@ "color": "^3.1.2", "config": "1.28.1", "country-code-lookup": "^0.0.19", - "cross-env": "^6.0.3", "curve25519-js": "^0.0.4", "dompurify": "^2.0.7", "electron-is-dev": "^1.1.0", @@ -162,6 +153,7 @@ "chai": "^4.3.4", "chai-as-promised": "^7.1.1", "chai-bytes": "^0.1.2", + "cross-env": "^6.0.3", "electron": "^13.6.2", "electron-builder": "22.8.0", "electron-notarize": "^0.2.0", diff --git a/preload.js b/preload.js index 3d1cef324..e0c56b2d6 100644 --- a/preload.js +++ b/preload.js @@ -211,7 +211,17 @@ window.ReactDOM = require('react-dom'); 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; window.i18n = i18n.setup(localFromEnv, localeMessages); diff --git a/ts/components/leftpane/ActionsPanel.tsx b/ts/components/leftpane/ActionsPanel.tsx index 3dd6d69eb..189f86103 100644 --- a/ts/components/leftpane/ActionsPanel.tsx +++ b/ts/components/leftpane/ActionsPanel.tsx @@ -169,7 +169,7 @@ const cleanUpMediasInterval = DURATION.MINUTES * 60; // 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 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 theme = window.Events.getThemeSetting(); @@ -274,10 +274,14 @@ const CallContainer = () => { async function fetchReleaseFromFSAndUpdateMain() { try { + window.log.warn('[updater] about to fetchReleaseFromFSAndUpdateMain'); + const latest = await getLatestDesktopReleaseFileToFsV2(); + window.log.warn('[updater] fetched latest release from fsv2: ', latest); if (isString(latest) && !isEmpty(latest)) { ipcRenderer.send('set-release-from-file-server', latest); + window.readyForUpdates(); } } catch (e) { window.log.warn(e); diff --git a/ts/updater/index.ts b/ts/updater/index.ts index 6c4e8e136..1bc27bc14 100644 --- a/ts/updater/index.ts +++ b/ts/updater/index.ts @@ -4,7 +4,7 @@ import { LoggerType, MessagesType } from './common'; import { UserConfig } from '../../app/user_config'; let initialized = false; -let config: UserConfig; +let localUserConfig: UserConfig; export async function start( getMainWindow: () => BrowserWindow, @@ -27,16 +27,9 @@ export async function start( throw new Error('updater/start: Must provide logger!'); } initialized = true; - config = userConfig; // reused below + localUserConfig = userConfig; // reused below 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'); return; @@ -54,7 +47,7 @@ export function stop() { 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 - const userSetting = config.get('autoUpdate'); + const userSetting = localUserConfig.get('autoUpdate'); const autoUpdate = typeof userSetting !== 'boolean' || userSetting; return ( diff --git a/ts/updater/updater.ts b/ts/updater/updater.ts index 5f1662b63..2867fcae0 100644 --- a/ts/updater/updater.ts +++ b/ts/updater/updater.ts @@ -19,10 +19,6 @@ let downloadIgnored = false; let interval: NodeJS.Timeout | undefined; let stopped = false; -const SECOND = 1000; -const MINUTE = SECOND * 60; -const INTERVAL = MINUTE * 1; - export async function start( getMainWindow: () => BrowserWindow, messages: MessagesType, @@ -45,7 +41,7 @@ export async function start( } catch (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; await checkForUpdates(getMainWindow, messages, logger); @@ -64,17 +60,19 @@ async function checkForUpdates( messages: MessagesType, logger: LoggerType ) { + logger.info('[updater] checkForUpdates'); if (stopped || isUpdating || downloadIgnored) { return; } const canUpdate = await canAutoUpdate(); + logger.info('[updater] canUpdate', canUpdate); if (!canUpdate) { logger.info('checkForUpdates canAutoUpdate false'); return; } - logger.info('auto-update: checkForUpdates...'); + logger.info('[updater] checkForUpdates...'); isUpdating = true; @@ -83,17 +81,17 @@ async function checkForUpdates( ? ((getMainWindow() as any).getLatestDesktopRelease() as string | undefined) : undefined; - logger.info('checkForUpdates latestVersionFromFsFromRenderer', latestVersionFromFsFromRenderer); + logger.info('[updater] latestVersionFromFsFromRenderer', latestVersionFromFsFromRenderer); if (!latestVersionFromFsFromRenderer || !latestVersionFromFsFromRenderer?.length) { logger.info( - 'testVersionFromFsFromRenderer was not updated yet by renderer. Skipping update check' + '[updater] testVersionFromFsFromRenderer was not updated yet by renderer. Skipping update check' ); return; } const currentVersion = autoUpdater.currentVersion.toString(); const isMoreRecent = isVersionGreaterThan(latestVersionFromFsFromRenderer, currentVersion); - logger.info('checkForUpdates isMoreRecent', isMoreRecent); + logger.info('[updater] checkForUpdates isMoreRecent', isMoreRecent); if (!isMoreRecent) { logger.info( `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 const result = await autoUpdater.checkForUpdates(); - logger.info('checkForUpdates github fetch result:', result); + logger.info('[updater] checkForUpdates got github response back '); if (!result.updateInfo) { - logger.info('auto-update: no update info received'); + logger.info('[updater] no update info received'); return; } try { const hasUpdate = isUpdateAvailable(result.updateInfo); - logger.info('checkForUpdates hasUpdate:', hasUpdate); + logger.info('[updater] hasUpdate:', hasUpdate); if (!hasUpdate) { - logger.info('auto-update: no update available'); + logger.info('[updater] no update available'); return; } - logger.info('auto-update: showing download dialog...'); + logger.info('[updater] showing download dialog...'); const shouldDownload = await showDownloadUpdateDialog(getMainWindow(), messages); - logger.info('checkForUpdates shouldDownload:', shouldDownload); + logger.info('[updater] shouldDownload:', shouldDownload); if (!shouldDownload) { downloadIgnored = true; @@ -139,13 +137,13 @@ async function checkForUpdates( } // 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); if (!shouldUpdate) { return; } - logger.info('auto-update: calling quitAndInstall...'); + logger.info('[updater] calling quitAndInstall...'); markShouldQuit(); autoUpdater.quitAndInstall(); } finally { diff --git a/ts/window.d.ts b/ts/window.d.ts index a075e8a5b..bfb8aa8c7 100644 --- a/ts/window.d.ts +++ b/ts/window.d.ts @@ -59,6 +59,7 @@ declare global { userConfig: any; versionInfo: any; getConversations: () => ConversationCollection; + readyForUpdates: () => void; MediaRecorder: any; contextMenuShown: boolean;