Make sure updater do not hit github before checking fileserver

pull/2224/head
Audric Ackermann 3 years ago
parent 49bae1925d
commit 234e9b160e
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -14,7 +14,6 @@
"url": "https://public.loki.foundation:4433/" "url": "https://public.loki.foundation:4433/"
} }
], ],
"updatesEnabled": false,
"openDevTools": false, "openDevTools": false,
"commitHash": "", "commitHash": "",
"import": false "import": false

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

@ -1,4 +1,3 @@
{ {
"openDevTools": true, "openDevTools": true
"updatesEnabled": false
} }

@ -1,4 +1,3 @@
{ {
"openDevTools": true, "openDevTools": true
"updatesEnabled": false
} }

@ -1,3 +1 @@
{ {}
"updatesEnabled": true
}

@ -76,6 +76,8 @@ const { installPermissionsHandler } = require('./app/permissions');
let appStartInitialSpellcheckSetting = true; let appStartInitialSpellcheckSetting = true;
let latestDesktopRelease;
async function getSpellCheckSetting() { async function getSpellCheckSetting() {
const json = await sql.getItemById('spell-check'); const json = await sql.getItemById('spell-check');
// Default to `true` if setting doesn't exist yet // Default to `true` if setting doesn't exist yet
@ -398,29 +400,27 @@ async function createWindow() {
// when you should delete the corresponding element. // when you should delete the corresponding element.
mainWindow = null; mainWindow = null;
}); });
mainWindow.getLatestDesktopRelease = () => latestDesktopRelease;
} }
ipc.on('show-window', () => { ipc.on('show-window', () => {
showWindow(); showWindow();
}); });
ipc.on('set-release-from-file-server', (_event, releaseGotFromFileServer) => {
latestDesktopRelease = releaseGotFromFileServer;
});
let isReadyForUpdates = false; let isReadyForUpdates = false;
async function readyForUpdates() { async function readyForUpdates() {
console.log('isReadyForUpdates', isReadyForUpdates);
if (isReadyForUpdates) { if (isReadyForUpdates) {
return; return;
} }
isReadyForUpdates = true; isReadyForUpdates = true;
// disable for now
/*
// First, install requested sticker pack
const incomingUrl = getIncomingUrl(process.argv);
if (incomingUrl) {
handleSgnlLink(incomingUrl);
}
*/
// Second, start checking for app updates // Second, start checking for app updates
try { try {
await updater.start(getMainWindow, userConfig, locale.messages, logger); await updater.start(getMainWindow, userConfig, locale.messages, logger);

@ -34,7 +34,7 @@ import { conversationChanged, conversationRemoved } from '../../state/ducks/conv
import { editProfileModal, onionPathModal } from '../../state/ducks/modalDialog'; import { editProfileModal, onionPathModal } from '../../state/ducks/modalDialog';
import { uploadOurAvatar } from '../../interactions/conversationInteractions'; import { uploadOurAvatar } from '../../interactions/conversationInteractions';
import { ModalContainer } from '../dialog/ModalContainer'; import { ModalContainer } from '../dialog/ModalContainer';
import { debounce } from 'lodash'; import { debounce, isEmpty, isString } from 'lodash';
// tslint:disable-next-line: no-import-side-effect no-submodule-imports // tslint:disable-next-line: no-import-side-effect no-submodule-imports
@ -51,6 +51,8 @@ import { IncomingCallDialog } from '../calling/IncomingCallDialog';
import { SessionIconButton } from '../icon'; import { SessionIconButton } from '../icon';
import { SessionToastContainer } from '../SessionToastContainer'; import { SessionToastContainer } from '../SessionToastContainer';
import { LeftPaneSectionContainer } from './LeftPaneSectionContainer'; import { LeftPaneSectionContainer } from './LeftPaneSectionContainer';
import { getLatestDesktopReleaseFileToFsV2 } from '../../session/apis/file_server_api/FileServerApiV2';
import { ipcRenderer } from 'electron';
const Section = (props: { type: SectionType }) => { const Section = (props: { type: SectionType }) => {
const ourNumber = useSelector(getOurNumber); const ourNumber = useSelector(getOurNumber);
@ -162,7 +164,12 @@ const Section = (props: { type: SectionType }) => {
} }
}; };
const cleanUpMediasInterval = DURATION.MINUTES * 30; 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 setupTheme = () => { const setupTheme = () => {
const theme = window.Events.getThemeSetting(); const theme = window.Events.getThemeSetting();
@ -265,6 +272,18 @@ const CallContainer = () => {
); );
}; };
async function fetchReleaseFromFSAndUpdateMain() {
try {
const latest = await getLatestDesktopReleaseFileToFsV2();
if (isString(latest) && !isEmpty(latest)) {
ipcRenderer.send('set-release-from-file-server', latest);
}
} catch (e) {
window.log.warn(e);
}
}
/** /**
* ActionsPanel is the far left banner (not the left pane). * ActionsPanel is the far left banner (not the left pane).
* The panel with buttons to switch between the message/contact/settings/theme views * The panel with buttons to switch between the message/contact/settings/theme views
@ -289,6 +308,10 @@ export const ActionsPanel = () => {
useInterval(cleanUpOldDecryptedMedias, startCleanUpMedia ? cleanUpMediasInterval : null); useInterval(cleanUpOldDecryptedMedias, startCleanUpMedia ? cleanUpMediasInterval : null);
useInterval(() => {
void fetchReleaseFromFSAndUpdateMain();
}, fetchReleaseFromFileServerInterval);
if (!ourPrimaryConversation) { if (!ourPrimaryConversation) {
window?.log?.warn('ActionsPanel: ourPrimaryConversation is not set'); window?.log?.warn('ActionsPanel: ourPrimaryConversation is not set');
return null; return null;

@ -1,4 +1,3 @@
import { get as getFromConfig } from 'config';
import { BrowserWindow } from 'electron'; import { BrowserWindow } from 'electron';
import { start as startUpdater, stop as stopUpdater } from './updater'; import { start as startUpdater, stop as stopUpdater } from './updater';
import { LoggerType, MessagesType } from './common'; import { LoggerType, MessagesType } from './common';
@ -10,14 +9,16 @@ let config: UserConfig;
export async function start( export async function start(
getMainWindow: () => BrowserWindow, getMainWindow: () => BrowserWindow,
userConfig: UserConfig, userConfig: UserConfig,
messages?: MessagesType, messages: MessagesType,
logger?: LoggerType logger: LoggerType
) { ) {
if (initialized) { if (initialized) {
throw new Error('updater/start: Updates have already been initialized!'); throw new Error('updater/start: Updates have already been initialized!');
} }
initialized = true;
config = userConfig; if (!userConfig) {
throw new Error('updater/start: userConfig is needed!');
}
if (!messages) { if (!messages) {
throw new Error('updater/start: Must provide messages!'); throw new Error('updater/start: Must provide messages!');
@ -25,6 +26,8 @@ export async function start(
if (!logger) { if (!logger) {
throw new Error('updater/start: Must provide logger!'); throw new Error('updater/start: Must provide logger!');
} }
initialized = true;
config = userConfig; // reused below
if (autoUpdateDisabled()) { if (autoUpdateDisabled()) {
/* /*
@ -56,7 +59,6 @@ function autoUpdateDisabled() {
return ( return (
process.mas || // From Electron: Mac App Store build process.mas || // From Electron: Mac App Store build
!getFromConfig('updatesEnabled') || // Hard coded config
// tslint:disable-next-line: no-backbone-get-set-outside-model // tslint:disable-next-line: no-backbone-get-set-outside-model
!autoUpdate // User setting !autoUpdate // User setting
); );

@ -21,7 +21,7 @@ let stopped = false;
const SECOND = 1000; const SECOND = 1000;
const MINUTE = SECOND * 60; const MINUTE = SECOND * 60;
const INTERVAL = MINUTE * 30; const INTERVAL = MINUTE * 1;
export async function start( export async function start(
getMainWindow: () => BrowserWindow, getMainWindow: () => BrowserWindow,
@ -70,16 +70,42 @@ async function checkForUpdates(
const canUpdate = await canAutoUpdate(); const canUpdate = await canAutoUpdate();
if (!canUpdate) { if (!canUpdate) {
logger.info('checkForUpdates canAutoUpdate false');
return; return;
} }
logger.info('auto-update: checking for update...'); logger.info('auto-update: checkForUpdates...');
isUpdating = true; isUpdating = true;
try { try {
// Get the update using electron-updater const latestVersionFromFsFromRenderer = getMainWindow()
? ((getMainWindow() as any).getLatestDesktopRelease() as string | undefined)
: undefined;
logger.info('checkForUpdates latestVersionFromFsFromRenderer', latestVersionFromFsFromRenderer);
if (!latestVersionFromFsFromRenderer || !latestVersionFromFsFromRenderer?.length) {
logger.info(
'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);
if (!isMoreRecent) {
logger.info(
`Fileserver has no update so we are not looking for an update from github current:${currentVersion} fromFileServer:${latestVersionFromFsFromRenderer}`
);
return;
}
// 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);
if (!result.updateInfo) { if (!result.updateInfo) {
logger.info('auto-update: no update info received'); logger.info('auto-update: no update info received');
@ -88,6 +114,8 @@ async function checkForUpdates(
try { try {
const hasUpdate = isUpdateAvailable(result.updateInfo); const hasUpdate = isUpdateAvailable(result.updateInfo);
logger.info('checkForUpdates hasUpdate:', hasUpdate);
if (!hasUpdate) { if (!hasUpdate) {
logger.info('auto-update: no update available'); logger.info('auto-update: no update available');
@ -96,6 +124,8 @@ async function checkForUpdates(
logger.info('auto-update: showing download dialog...'); logger.info('auto-update: showing download dialog...');
const shouldDownload = await showDownloadUpdateDialog(getMainWindow(), messages); const shouldDownload = await showDownloadUpdateDialog(getMainWindow(), messages);
logger.info('checkForUpdates shouldDownload:', shouldDownload);
if (!shouldDownload) { if (!shouldDownload) {
downloadIgnored = true; downloadIgnored = true;

Loading…
Cancel
Save