Make sure updater do not hit github before checking fileserver
This commit is contained in:
parent
49bae1925d
commit
234e9b160e
|
@ -14,7 +14,6 @@
|
|||
"url": "https://public.loki.foundation:4433/"
|
||||
}
|
||||
],
|
||||
"updatesEnabled": false,
|
||||
"openDevTools": false,
|
||||
"commitHash": "",
|
||||
"import": false
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
{
|
||||
"openDevTools": false,
|
||||
"updatesEnabled": false
|
||||
"openDevTools": false
|
||||
}
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
{
|
||||
"openDevTools": true,
|
||||
"updatesEnabled": false
|
||||
"openDevTools": true
|
||||
}
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
{
|
||||
"openDevTools": true,
|
||||
"updatesEnabled": false
|
||||
"openDevTools": true
|
||||
}
|
||||
|
|
|
@ -1,3 +1 @@
|
|||
{
|
||||
"updatesEnabled": true
|
||||
}
|
||||
{}
|
||||
|
|
18
main.js
18
main.js
|
@ -76,6 +76,8 @@ const { installPermissionsHandler } = require('./app/permissions');
|
|||
|
||||
let appStartInitialSpellcheckSetting = true;
|
||||
|
||||
let latestDesktopRelease;
|
||||
|
||||
async function getSpellCheckSetting() {
|
||||
const json = await sql.getItemById('spell-check');
|
||||
// Default to `true` if setting doesn't exist yet
|
||||
|
@ -398,29 +400,27 @@ async function createWindow() {
|
|||
// when you should delete the corresponding element.
|
||||
mainWindow = null;
|
||||
});
|
||||
|
||||
mainWindow.getLatestDesktopRelease = () => latestDesktopRelease;
|
||||
}
|
||||
|
||||
ipc.on('show-window', () => {
|
||||
showWindow();
|
||||
});
|
||||
|
||||
ipc.on('set-release-from-file-server', (_event, releaseGotFromFileServer) => {
|
||||
latestDesktopRelease = releaseGotFromFileServer;
|
||||
});
|
||||
|
||||
let isReadyForUpdates = false;
|
||||
async function readyForUpdates() {
|
||||
console.log('isReadyForUpdates', isReadyForUpdates);
|
||||
if (isReadyForUpdates) {
|
||||
return;
|
||||
}
|
||||
|
||||
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
|
||||
try {
|
||||
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 { uploadOurAvatar } from '../../interactions/conversationInteractions';
|
||||
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
|
||||
|
||||
|
@ -51,6 +51,8 @@ import { IncomingCallDialog } from '../calling/IncomingCallDialog';
|
|||
import { SessionIconButton } from '../icon';
|
||||
import { SessionToastContainer } from '../SessionToastContainer';
|
||||
import { LeftPaneSectionContainer } from './LeftPaneSectionContainer';
|
||||
import { getLatestDesktopReleaseFileToFsV2 } from '../../session/apis/file_server_api/FileServerApiV2';
|
||||
import { ipcRenderer } from 'electron';
|
||||
|
||||
const Section = (props: { type: SectionType }) => {
|
||||
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 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).
|
||||
* 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(() => {
|
||||
void fetchReleaseFromFSAndUpdateMain();
|
||||
}, fetchReleaseFromFileServerInterval);
|
||||
|
||||
if (!ourPrimaryConversation) {
|
||||
window?.log?.warn('ActionsPanel: ourPrimaryConversation is not set');
|
||||
return null;
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import { get as getFromConfig } from 'config';
|
||||
import { BrowserWindow } from 'electron';
|
||||
import { start as startUpdater, stop as stopUpdater } from './updater';
|
||||
import { LoggerType, MessagesType } from './common';
|
||||
|
@ -10,14 +9,16 @@ let config: UserConfig;
|
|||
export async function start(
|
||||
getMainWindow: () => BrowserWindow,
|
||||
userConfig: UserConfig,
|
||||
messages?: MessagesType,
|
||||
logger?: LoggerType
|
||||
messages: MessagesType,
|
||||
logger: LoggerType
|
||||
) {
|
||||
if (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) {
|
||||
throw new Error('updater/start: Must provide messages!');
|
||||
|
@ -25,6 +26,8 @@ export async function start(
|
|||
if (!logger) {
|
||||
throw new Error('updater/start: Must provide logger!');
|
||||
}
|
||||
initialized = true;
|
||||
config = userConfig; // reused below
|
||||
|
||||
if (autoUpdateDisabled()) {
|
||||
/*
|
||||
|
@ -56,7 +59,6 @@ function autoUpdateDisabled() {
|
|||
|
||||
return (
|
||||
process.mas || // From Electron: Mac App Store build
|
||||
!getFromConfig('updatesEnabled') || // Hard coded config
|
||||
// tslint:disable-next-line: no-backbone-get-set-outside-model
|
||||
!autoUpdate // User setting
|
||||
);
|
||||
|
|
|
@ -21,7 +21,7 @@ let stopped = false;
|
|||
|
||||
const SECOND = 1000;
|
||||
const MINUTE = SECOND * 60;
|
||||
const INTERVAL = MINUTE * 30;
|
||||
const INTERVAL = MINUTE * 1;
|
||||
|
||||
export async function start(
|
||||
getMainWindow: () => BrowserWindow,
|
||||
|
@ -70,16 +70,42 @@ async function checkForUpdates(
|
|||
|
||||
const canUpdate = await canAutoUpdate();
|
||||
if (!canUpdate) {
|
||||
logger.info('checkForUpdates canAutoUpdate false');
|
||||
return;
|
||||
}
|
||||
|
||||
logger.info('auto-update: checking for update...');
|
||||
logger.info('auto-update: checkForUpdates...');
|
||||
|
||||
isUpdating = true;
|
||||
|
||||
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();
|
||||
|
||||
logger.info('checkForUpdates github fetch result:', result);
|
||||
|
||||
if (!result.updateInfo) {
|
||||
logger.info('auto-update: no update info received');
|
||||
|
||||
|
@ -88,6 +114,8 @@ async function checkForUpdates(
|
|||
|
||||
try {
|
||||
const hasUpdate = isUpdateAvailable(result.updateInfo);
|
||||
logger.info('checkForUpdates hasUpdate:', hasUpdate);
|
||||
|
||||
if (!hasUpdate) {
|
||||
logger.info('auto-update: no update available');
|
||||
|
||||
|
@ -96,6 +124,8 @@ async function checkForUpdates(
|
|||
|
||||
logger.info('auto-update: showing download dialog...');
|
||||
const shouldDownload = await showDownloadUpdateDialog(getMainWindow(), messages);
|
||||
logger.info('checkForUpdates shouldDownload:', shouldDownload);
|
||||
|
||||
if (!shouldDownload) {
|
||||
downloadIgnored = true;
|
||||
|
||||
|
|
Loading…
Reference in New Issue