Added setting to disable checking for auto updates.

This commit is contained in:
Mikunj 2020-03-10 09:55:29 +11:00
parent d6c3f89fde
commit d10a8f0a6f
8 changed files with 93 additions and 5 deletions

View file

@ -1958,6 +1958,12 @@
"relink": {
"message": "Relink"
},
"autoUpdateSettingTitle": {
"message": "Auto Update"
},
"autoUpdateSettingDescription": {
"message": "Automatically check for updates on launch"
},
"autoUpdateNewVersionTitle": {
"message": "Session update available"
},

11
app/base_config.d.ts vendored Normal file
View file

@ -0,0 +1,11 @@
export interface BaseConfig {
set(keyPath: string, value: any): void
get(keyPath: string): any | undefined
remove(): void
}
interface Options {
allowMalformedOnStartup: boolean
}
export function start(name: string, targetPath: string, options: Options): BaseConfig;

3
app/user_config.d.ts vendored Normal file
View file

@ -0,0 +1,3 @@
import { BaseConfig } from "./base_config";
type UserConfig = BaseConfig

18
main.js
View file

@ -427,7 +427,7 @@ async function readyForUpdates() {
// Second, start checking for app updates
try {
await updater.start(getMainWindow, locale.messages, logger);
await updater.start(getMainWindow, userConfig, locale.messages, logger);
} catch (error) {
const log = logger || console;
log.error(
@ -1090,6 +1090,22 @@ ipc.on('set-media-permissions', (event, value) => {
}
});
// Loki - Auto updating
ipc.on('get-auto-update-enabled', event => {
const configValue = userConfig.get('autoUpdate');
// eslint-disable-next-line no-param-reassign
event.returnValue = typeof configValue !== 'boolean' ? true : configValue;
});
ipc.on('set-auto-update-enabled', (event, value) => {
userConfig.set('autoUpdate', !!value);
// Stop updater if user turned it off
if (!value) {
updater.stop();
}
});
function getDataFromMainWindow(name, callback) {
ipc.once(`get-success-${name}`, (_event, error, value) =>
callback(error, value)

View file

@ -211,8 +211,11 @@ window.getSettingValue = (settingID, comparisonValue = null) => {
// Eg. window.getSettingValue('theme', 'light')
// returns 'false' when the value is 'dark'.
// We need to get specific settings from the main process
if (settingID === 'media-permissions') {
return window.getMediaPermissions();
} else if (settingID === 'auto-update') {
return window.getAutoUpdateEnabled();
}
const settingVal = window.storage.get(settingID);
@ -220,6 +223,12 @@ window.getSettingValue = (settingID, comparisonValue = null) => {
};
window.setSettingValue = (settingID, value) => {
// For auto updating we need to pass the value to the main process
if (settingID === 'auto-update') {
window.setAutoUpdateEnabled(value);
return;
}
window.storage.put(settingID, value);
if (settingID === 'zoom-factor-setting') {
@ -231,6 +240,10 @@ window.setSettingValue = (settingID, value) => {
window.getMessageTTL = () => window.storage.get('message-ttl', 24);
window.getMediaPermissions = () => ipc.sendSync('get-media-permissions');
// Auto update setting
window.getAutoUpdateEnabled = () => ipc.sendSync('get-auto-update-enabled');
window.setAutoUpdateEnabled = (value) => ipc.send('set-auto-update-enabled', !!value);
ipc.on('get-ready-for-shutdown', async () => {
const { shutdown } = window.Events || {};
if (!shutdown) {

View file

@ -496,6 +496,19 @@ export class SettingsView extends React.Component<SettingsViewProps, State> {
content: {},
confirmationDialogParams: undefined,
},
{
id: 'auto-update',
title: window.i18n('autoUpdateSettingTitle'),
description: window.i18n('autoUpdateSettingDescription'),
hidden: false,
type: SessionSettingType.Toggle,
category: SessionSettingCategory.Privacy,
setFn: undefined,
comparisonValue: undefined,
onClick: undefined,
content: {},
confirmationDialogParams: undefined,
},
{
id: 'set-password',
title: window.i18n('setAccountPasswordTitle'),

View file

@ -1,12 +1,15 @@
import { get as getFromConfig } from 'config';
import { BrowserWindow } from 'electron';
import { start as startUpdater } from './updater';
import { start as startUpdater, stop as stopUpdater } from './updater';
import { LoggerType, MessagesType } from './common';
import { UserConfig } from '../../app/user_config';
let initialized = false;
let config: UserConfig;
export async function start(
getMainWindow: () => BrowserWindow,
userConfig: UserConfig,
messages?: MessagesType,
logger?: LoggerType
) {
@ -14,6 +17,7 @@ export async function start(
throw new Error('updater/start: Updates have already been initialized!');
}
initialized = true;
config = userConfig;
if (!messages) {
throw new Error('updater/start: Must provide messages!');
@ -40,8 +44,18 @@ export async function start(
await startUpdater(getMainWindow, messages, logger);
}
export function stop() {
if (initialized) {
stopUpdater();
initialized = false;
}
}
function autoUpdateDisabled() {
return (
process.mas || !getFromConfig('updatesEnabled') // 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
!config.get('autoUpdate') // User setting
);
}

View file

@ -3,6 +3,8 @@ import * as fs from 'fs-extra';
import { autoUpdater, UpdateInfo } from 'electron-updater';
import { app, BrowserWindow } from 'electron';
import { markShouldQuit } from '../../app/window_state';
import { UserConfig } from '../../app/user_config';
import {
getPrintableError,
LoggerType,
@ -15,6 +17,8 @@ import { gt as isVersionGreaterThan, parse as parseVersion } from 'semver';
let isUpdating = false;
let downloadIgnored = false;
let interval: NodeJS.Timeout;
let stopped = false;
const SECOND = 1000;
const MINUTE = SECOND * 60;
@ -30,23 +34,31 @@ export async function start(
autoUpdater.logger = logger;
autoUpdater.autoDownload = false;
setInterval(async () => {
interval = setInterval(async () => {
try {
await checkForUpdates(getMainWindow, messages, logger);
} catch (error) {
logger.error('auto-update: error:', getPrintableError(error));
}
}, INTERVAL);
stopped = false;
await checkForUpdates(getMainWindow, messages, logger);
}
export function stop() {
if (interval) {
clearInterval(interval);
stopped = true;
}
}
async function checkForUpdates(
getMainWindow: () => BrowserWindow,
messages: MessagesType,
logger: LoggerType
) {
if (isUpdating || downloadIgnored) {
if (stopped || isUpdating || downloadIgnored) {
return;
}