Skip to content

Commit a99745e

Browse files
committed
Fix update settings UI on platforms where updates not configurable
1 parent 67a416c commit a99745e

File tree

10 files changed

+78
-7
lines changed

10 files changed

+78
-7
lines changed

src/controllers/updates_controller.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,23 @@ function build(): express.Router {
177177
});
178178

179179
controller.get('/self-update', async (_request, response) => {
180+
// If the gateway is running inside a snap then auto updates are always
181+
// enabled and can not be manually triggered from the UI
182+
if (Platform.isSnap()) {
183+
response.json({
184+
available: true,
185+
enabled: true,
186+
configurable: false,
187+
triggerable: false,
188+
});
189+
return;
190+
}
180191
if (!Platform.implemented('getSelfUpdateStatus')) {
181192
response.json({
182193
available: false,
183194
enabled: false,
195+
configurable: false,
196+
triggerable: false,
184197
});
185198
} else {
186199
response.json(Platform.getSelfUpdateStatus());

src/platforms/darwin.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ class DarwinPlatform extends BasePlatform {
6060
return {
6161
available: false,
6262
enabled: false,
63+
configurable: false,
64+
triggerable: false,
6365
};
6466
}
6567

src/platforms/linux-arch.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ class LinuxArchPlatform extends BasePlatform {
4545
return {
4646
available: false,
4747
enabled: false,
48+
configurable: false,
49+
triggerable: false,
4850
};
4951
}
5052

src/platforms/linux-debian.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export class LinuxDebianPlatform extends BasePlatform {
2020
return {
2121
available: false,
2222
enabled: false,
23+
configurable: false,
24+
triggerable: false,
2325
};
2426
}
2527

src/platforms/linux-raspbian.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,8 @@ class LinuxRaspbianPlatform extends BasePlatform {
799799
return {
800800
available: timerExists,
801801
enabled: proc.status === 0,
802+
configurable: true,
803+
triggerable: true,
802804
};
803805
}
804806

src/platforms/linux-ubuntu-core.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import ip from 'ip';
1010
import { Netmask } from 'netmask';
1111
import BasePlatform from './base';
1212
import NetworkManager, { ConnectionSettings } from './utilities/network-manager';
13-
import { LanMode, NetworkAddresses, WirelessNetwork } from './types';
13+
import { LanMode, NetworkAddresses, WirelessNetwork, SelfUpdateStatus } from './types';
1414

1515
export class LinuxUbuntuCorePlatform extends BasePlatform {
1616
/**
@@ -294,6 +294,27 @@ export class LinuxUbuntuCorePlatform extends BasePlatform {
294294
}
295295
return true;
296296
}
297+
298+
/**
299+
* Determine whether or not the gateway can auto-update itself.
300+
*
301+
* @returns {Object} {
302+
* available: <bool>,
303+
* enabled: <bool>,
304+
* configurable: <bool>,
305+
* triggerable: <bool>
306+
* }
307+
*/
308+
getSelfUpdateStatus(): SelfUpdateStatus {
309+
// Automatic updates are supported on Ubuntu Core but can not be disabled
310+
// or manually triggered from the UI
311+
return {
312+
available: true,
313+
enabled: true,
314+
configurable: false,
315+
triggerable: false,
316+
};
317+
}
297318
}
298319

299320
export default new LinuxUbuntuCorePlatform();

src/platforms/linux-ubuntu.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,29 @@
77
*/
88

99
import { LinuxUbuntuCorePlatform } from './linux-ubuntu-core';
10+
import { SelfUpdateStatus } from './types';
1011

11-
class LinuxUbuntuPlatform extends LinuxUbuntuCorePlatform {}
12+
class LinuxUbuntuPlatform extends LinuxUbuntuCorePlatform {
13+
/**
14+
* Determine whether or not the gateway can auto-update itself.
15+
*
16+
* @returns {Object} {
17+
* available: <bool>,
18+
* enabled: <bool>,
19+
* configurable: <bool>,
20+
* triggerable: <bool>
21+
* }
22+
*/
23+
getSelfUpdateStatus(): SelfUpdateStatus {
24+
// Automatic updates are not supported on Ubuntu
25+
// (snaps are detected separately in Platform.ts)
26+
return {
27+
available: false,
28+
enabled: false,
29+
configurable: false,
30+
triggerable: false,
31+
};
32+
}
33+
}
1234

1335
export default new LinuxUbuntuPlatform();

src/platforms/types.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
export interface SelfUpdateStatus {
2-
available: boolean;
3-
enabled: boolean;
2+
available: boolean; // Automatic updates are possible
3+
enabled: boolean; // Automatic updates are enabled
4+
configurable: boolean; // Automatic updates can be turned on and off
5+
triggerable: boolean; // Updates can be manually triggered by the user
46
}
57

68
export interface LanMode {

static/css/settings.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,8 @@
751751
background-image: url('/images/authorization.svg');
752752
}
753753

754-
#update-now.hidden {
754+
#update-now.hidden,
755+
#up-to-date-container.hidden {
755756
display: none;
756757
}
757758

static/js/views/settings.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,6 +1437,7 @@ const SettingsScreen = {
14371437
},
14381438

14391439
fetchUpdateInfo: function () {
1440+
const upToDateContainerElt = document.getElementById('up-to-date-container');
14401441
const upToDateElt = document.getElementById('update-settings-up-to-date');
14411442
const updateNow = document.getElementById('update-now');
14421443
const versionElt = document.getElementById('update-settings-version');
@@ -1467,15 +1468,18 @@ const SettingsScreen = {
14671468
}
14681469

14691470
this.elements.update.enableSelfUpdatesCheckbox.checked = support.enabled;
1470-
this.elements.update.enableSelfUpdatesCheckbox.disabled = !support.available;
1471+
this.elements.update.enableSelfUpdatesCheckbox.disabled =
1472+
!support.available || !support.configurable;
14711473

14721474
if (support.available) {
14731475
statusElt.textContent = statusText;
14741476
} else {
14751477
statusElt.classList.add('hidden');
14761478
}
14771479

1478-
if (support.available) {
1480+
if (support.available && !support.triggerable) {
1481+
upToDateContainerElt.classList.add('hidden');
1482+
} else if (support.available) {
14791483
upToDateElt.textContent = fluent.getMessage('checking-for-updates');
14801484
updateNow.classList.add('hidden');
14811485

0 commit comments

Comments
 (0)