Update: Hide update enabled checkbox if no update server configured.

This hides the update checkbox if the update server is not configured, so
that the users don't get confused by a checkbox that doesn't do anything
(and therefore don't manually check for updates).

Signed-off-by: Mark Yen <mark.yen@suse.com>
This commit is contained in:
Mark Yen
2021-08-03 14:15:20 -07:00
parent 5a7a665a20
commit e480fe1937
5 changed files with 40 additions and 5 deletions

View File

@@ -29,5 +29,5 @@ nsis:
oneClick: false # Needed for restart prompt
publish:
provider: custom
upgradeServer: https://upgrade-server.example.com/v1/checkupgrade
#upgradeServer: https://upgrade-server.example.com/v1/checkupgrade
vPrefixedTagName: true

View File

@@ -3,6 +3,7 @@
<div class="version">
<span class="versionInfo"><b>Version:</b> {{ version }}</span>
<Checkbox
v-if="updatePossible"
v-model="updatesEnabled"
class="updatesEnabled"
label="Check for updates automatically"
@@ -68,6 +69,10 @@ class UpdateStatus extends UpdateStatusProps {
this.$emit('enabled', value);
}
get updatePossible() {
return !!this.updateState?.configured;
}
get hasUpdate() {
return this.updatesEnabled && !!this.updateState?.available;
}

View File

@@ -75,6 +75,7 @@ describe('UpdateStatus.vue', () => {
const wrapper = wrap({
enabled: true,
updateState: {
configured: true,
available: true,
downloaded: false,
info: {

View File

@@ -6,6 +6,14 @@ import LonghornProvider, { GithubReleaseAsset, LonghornProviderOptions } from '.
export class NsisLonghornUpdater extends NsisUpdater {
protected configOnDisk = new Lazy<LonghornProviderOptions>(() => this['loadUpdateConfig']());
get hasUpdateConfiguration(): Promise<boolean> {
return (async() => {
const config = await this.configOnDisk.value;
return !!config.upgradeServer;
})();
}
protected async getUpdateInfoAndProvider() {
if (this['clientPromise'] === null) {
const config = await this.configOnDisk.value;
@@ -24,6 +32,14 @@ export class NsisLonghornUpdater extends NsisUpdater {
export class MacLonghornUpdater extends MacUpdater {
protected configOnDisk = new Lazy<LonghornProviderOptions>(() => this['loadUpdateConfig']());
get hasUpdateConfiguration(): Promise<boolean> {
return (async() => {
const config = await this.configOnDisk.value;
return !!config.upgradeServer;
})();
}
protected async getUpdateInfoAndProvider() {
if (this['clientPromise'] === null) {
const config = await this.configOnDisk.value;

View File

@@ -15,26 +15,33 @@ import * as window from '@/window';
import { MacLonghornUpdater, NsisLonghornUpdater } from './LonghornUpdater';
import { hasQueuedUpdate, setHasQueuedUpdate } from './LonghornProvider';
interface CustomAppUpdater extends AppUpdater {
hasUpdateConfiguration: Promise<boolean>;
}
const console = new Console(Logging.update.stream);
let autoUpdater: AppUpdater;
let autoUpdater: CustomAppUpdater;
let enabled = false;
export type UpdateState = {
configured: boolean;
available: boolean;
downloaded: boolean;
error?: Error;
info?: UpdateInfo;
progress?: ProgressInfo;
}
const updateState: UpdateState = { available: false, downloaded: false };
const updateState: UpdateState = {
configured: false, available: false, downloaded: false
};
ipcMain.on('update-state', () => {
window.send('update-state', updateState);
});
function newUpdater(): AppUpdater {
let updater: AppUpdater;
function newUpdater(): CustomAppUpdater {
let updater: CustomAppUpdater;
try {
switch (os.platform()) {
@@ -114,6 +121,12 @@ export default async function setupUpdate(settings: Settings, doInstall = false)
}
autoUpdater ||= newUpdater();
if (!await autoUpdater.hasUpdateConfiguration) {
return false;
}
updateState.configured = true;
window.send('update-state', updateState);
if (doInstall && await hasQueuedUpdate()) {
console.log('Update is cached; forcing re-check to install.');