Skip to content

Commit a6a1344

Browse files
committed
added auto check updates and ota updates options to settings
1 parent ad96baf commit a6a1344

9 files changed

Lines changed: 161 additions & 43 deletions

File tree

native/app/Source/Application.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ class Application {
5757
}
5858

5959
self.settings = Settings()
60-
updater.automaticallyChecksForUpdates = true
6160

6261
Networking.startMonitor()
6362

native/app/Source/Settings/Settings.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,17 @@ class Settings: StoreSubscriber {
3838
}
3939
}
4040

41+
static var doAutoCheckUpdates = Application.store.state.settings.doAutoCheckUpdates {
42+
didSet {
43+
Application.updater.automaticallyChecksForUpdates = doAutoCheckUpdates
44+
}
45+
}
46+
4147
init() {
4248
self.setupStateListener()
4349
({
4450
Settings.iconMode = Application.store.state.settings.iconMode
51+
Settings.doAutoCheckUpdates = Application.store.state.settings.doAutoCheckUpdates
4552
})()
4653
}
4754

@@ -56,6 +63,9 @@ class Settings: StoreSubscriber {
5663
if (state.iconMode != Settings.iconMode) {
5764
Settings.iconMode = state.iconMode
5865
}
66+
if (state.doAutoCheckUpdates != Settings.doAutoCheckUpdates) {
67+
Settings.doAutoCheckUpdates = state.doAutoCheckUpdates
68+
}
5969
}
6070

6171
static var launchOnStartup: Bool {

native/app/Source/Settings/SettingsDataBus.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,34 @@ class SettingsDataBus: DataBus {
5959

6060
return "Crash Report collection consent has been set"
6161
}
62+
63+
self.on(.GET, "/auto-check-updates") { data, _ in
64+
return [ "doAutoCheckUpdates": self.state.doAutoCheckUpdates ]
65+
}
66+
67+
self.on(.POST, "/auto-check-updates") { data, _ in
68+
let doAutoCheckUpdates = data["doAutoCheckUpdates"] as? Bool
69+
if doAutoCheckUpdates == nil {
70+
throw "Invalid 'doAutoCheckUpdates' parameter, must be a Boolean"
71+
}
72+
Application.dispatchAction(SettingsAction.setDoAutoCheckUpdates(doAutoCheckUpdates!))
73+
74+
return "Auto check updates option has been set"
75+
}
76+
77+
self.on(.GET, "/ota-updates") { data, _ in
78+
return [ "doOTAUpdates": self.state.doOTAUpdates ]
79+
}
80+
81+
self.on(.POST, "/ota-updates") { data, _ in
82+
let doOTAUpdates = data["doOTAUpdates"] as? Bool
83+
if doOTAUpdates == nil {
84+
throw "Invalid 'doOTAUpdates' parameter, must be a Boolean"
85+
}
86+
Application.dispatchAction(SettingsAction.setDoOTAUpdates(doOTAUpdates!))
87+
88+
return "OTA updates option has been set"
89+
}
6290

6391
}
6492
}

native/app/Source/Settings/SettingsState.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@ import ReSwift
1414
struct SettingsState: State {
1515
var iconMode: IconMode = .both
1616
var doCollectCrashReports = false
17+
var doAutoCheckUpdates = true
18+
var doOTAUpdates = true
1719
}
1820

1921
enum SettingsAction: Action {
2022
case setIconMode(IconMode)
2123
case setDoCollectCrashReports(Bool)
24+
case setDoAutoCheckUpdates(Bool)
25+
case setDoOTAUpdates(Bool)
2226
}
2327

2428
func SettingsStateReducer(action: Action, state: SettingsState?) -> SettingsState {
@@ -28,6 +32,10 @@ func SettingsStateReducer(action: Action, state: SettingsState?) -> SettingsStat
2832
state.iconMode = iconMode
2933
case .setDoCollectCrashReports(let doCollect)?:
3034
state.doCollectCrashReports = doCollect
35+
case .setDoAutoCheckUpdates(let doAutoCheckUpdates)?:
36+
state.doAutoCheckUpdates = doAutoCheckUpdates
37+
case .setDoOTAUpdates(let doOTAUpdates)?:
38+
state.doOTAUpdates = doOTAUpdates
3139
case .none:
3240
break
3341
}

native/app/Source/UI/UI.swift

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -302,32 +302,45 @@ class UI: StoreSubscriber {
302302
UI.viewController.load(url)
303303
}
304304
}
305-
306-
remoteIsReachable() { reachable in
307-
if reachable {
308-
Console.log("Loading Remote UI")
309-
startUILoad(Constants.UI_ENDPOINT_URL)
310-
self.getRemoteVersion { remoteVersion in
311-
if remoteVersion != nil {
312-
let fs = FileManager.default
313-
if fs.fileExists(atPath: UI.remoteZipPath.path) {
314-
UI.unarchiveZip()
315-
let currentVersion = try? String(contentsOf: UI.localPath.appendingPathComponent("version.txt"))
316-
if (currentVersion?.trim() != remoteVersion?.trim()) {
317-
self.cacheRemote()
318-
}
319-
} else {
305+
306+
func loadRemote () {
307+
Console.log("Loading Remote UI")
308+
startUILoad(Constants.UI_ENDPOINT_URL)
309+
self.getRemoteVersion { remoteVersion in
310+
if remoteVersion != nil {
311+
let fs = FileManager.default
312+
if fs.fileExists(atPath: UI.remoteZipPath.path) {
313+
UI.unarchiveZip()
314+
let currentVersion = try? String(contentsOf: UI.localPath.appendingPathComponent("version.txt"))
315+
if (currentVersion?.trim() != remoteVersion?.trim()) {
320316
self.cacheRemote()
321317
}
318+
} else {
319+
self.cacheRemote()
322320
}
323321
}
324-
} else {
325-
Console.log("Loading Local UI")
326-
UI.unarchiveZip()
327-
let url = URL(string: "\(UI.localPath)/index.html")!
328-
startUILoad(url)
329322
}
330323
}
324+
325+
func loadLocal () {
326+
Console.log("Loading Local UI")
327+
UI.unarchiveZip()
328+
let url = URL(string: "\(UI.localPath)/index.html")!
329+
startUILoad(url)
330+
}
331+
332+
if (Application.store.state.settings.doOTAUpdates) {
333+
remoteIsReachable() { reachable in
334+
if reachable {
335+
loadRemote()
336+
} else {
337+
loadLocal()
338+
}
339+
}
340+
} else {
341+
loadLocal()
342+
}
343+
331344
}
332345

333346
private static func getRemoteVersion (_ completion: @escaping (String?) -> Void) {

ui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ui",
3-
"version": "1.4.1",
3+
"version": "1.4.2",
44
"scripts": {
55
"lint": "npx eslint .",
66
"start": "ng serve --port 8080 --host 0.0.0.0 --disable-host-check",

ui/src/app/components/options/options.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div fxLayout="column" fxLayoutAlign="space-around start" fxLayoutGap="15px">
1+
<div fxLayout="column" fxLayoutAlign="space-around start" fxLayoutGap="10px">
22
<div *ngFor="let row of options" fxLayout="row" style="width: 100%" fxLayoutGap="10px" fxLayoutAlign="space-between center">
33
<div *ngFor="let option of row" [ngStyle]="getOptionStyle(option, row)">
44
<!-- Checkbox -->
@@ -7,7 +7,7 @@
77
class="pointer"
88
[eqmTooltip]="!option.tooltipAsComponent && option.tooltip"
99
(click)="toggleCheckbox(option)">
10-
<eqm-checkbox [labelSide]="option.label && 'right'" [interactive]="false" [checked]="option.value">{{option.label}}</eqm-checkbox>
10+
<eqm-checkbox [labelSide]="!!option.label ? 'right' : undefined" [interactive]="false" [checked]="option.value">{{option.label}}</eqm-checkbox>
1111
<eqm-question *ngIf="option.tooltip && option.tooltipAsComponent" [eqmTooltip]="option.tooltip"></eqm-question>
1212
</div>
1313

ui/src/app/sections/settings/settings.component.ts

Lines changed: 61 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,24 +107,54 @@ and make it a more stable product.
107107
action: this.update.bind(this)
108108
}
109109

110+
autoCheckUpdatesOption: CheckboxOption = {
111+
type: 'checkbox',
112+
value: false,
113+
label: 'Check Automatically',
114+
toggled: doAutoCheckUpdates => {
115+
this.settingsService.setDoAutoCheckUpdates({
116+
doAutoCheckUpdates
117+
})
118+
}
119+
}
120+
121+
otaUpdatesOption: CheckboxOption = {
122+
type: 'checkbox',
123+
value: false,
124+
label: 'OTA User Interface Updates',
125+
toggled: doOTAUpdates => {
126+
this.settingsService.setDoOTAUpdates({
127+
doOTAUpdates
128+
})
129+
}
130+
}
131+
110132
settings: Options = [
133+
[ { type: 'label', label: 'Settings' } ],
134+
[ this.iconModeOption ],
111135
[
112-
this.iconModeOption
113-
],
114-
[
115-
this.updateOption,
116-
this.uninstallOption
136+
this.replaceKnobsWithSlidersOption,
137+
this.launchOnStartupOption
117138
],
118139

140+
[ { type: 'divider', orientation: 'horizontal' } ],
141+
142+
[ { type: 'label', label: 'Updates' } ],
119143
[
120-
this.replaceKnobsWithSlidersOption,
121-
this.launchOnStartupOption
144+
this.updateOption
122145
],
146+
123147
[ { type: 'divider', orientation: 'horizontal' } ],
148+
149+
// Privacy
124150
[ { type: 'label', label: 'Privacy' } ],
125151
[
126152
this.doCollectTelemetryOption
127-
]
153+
],
154+
155+
[ { type: 'divider', orientation: 'horizontal' } ],
156+
// Misc
157+
[ this.uninstallOption ]
128158
]
129159

130160
constructor (
@@ -163,10 +193,30 @@ and make it a more stable product.
163193
this.replaceKnobsWithSlidersOption.value = UISettings.replaceKnobsWithSliders
164194
this.doCollectTelemetryOption.value = UISettings.doCollectTelemetry
165195

166-
// Crash report consent was only available from v1.1.0
196+
// Some settings that are only available from v1.1.0
167197
if (new SemanticVersion(info.version).isGreaterThanOrEqualTo('1.1.0')) {
168-
this.doCollectCrashReportsOption.value = await this.settingsService.getDoCollectCrashReports()
169-
this.settings.push([
198+
const [
199+
doCollectCrashReports,
200+
doAutoCheckUpdates,
201+
doOTAUpdates
202+
] = await Promise.all([
203+
this.settingsService.getDoCollectCrashReports(),
204+
this.settingsService.getDoAutoCheckUpdates(),
205+
this.settingsService.getDoOTAUpdates()
206+
])
207+
208+
this.doCollectCrashReportsOption.value = doCollectCrashReports
209+
this.autoCheckUpdatesOption.value = doAutoCheckUpdates
210+
this.otaUpdatesOption.value = doOTAUpdates
211+
212+
// Add Update options
213+
this.settings.splice(this.settings.length - 6, 0, [
214+
this.autoCheckUpdatesOption,
215+
this.otaUpdatesOption
216+
])
217+
218+
// Add Privacy option
219+
this.settings.splice(this.settings.length - 2, 0, [
170220
this.doCollectCrashReportsOption
171221
])
172222
}

ui/src/app/sections/settings/settings.service.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,22 @@ export class SettingsService extends DataService {
3939
setDoCollectCrashReports ({ doCollectCrashReports }: { doCollectCrashReports: boolean }) {
4040
return this.request({ method: 'POST', endpoint: '/collect-crash-reports', data: { doCollectCrashReports } })
4141
}
42-
// async getMode () {
43-
// const { mode } = await this.request({ method: 'GET', endpoint: '/mode' })
44-
// return mode as UIMode
45-
// }
46-
47-
// setMode (mode: UIMode) {
48-
// return this.request({ method: 'POST', endpoint: '/mode', data: { mode } })
49-
// }
42+
43+
async getDoAutoCheckUpdates (): Promise<boolean> {
44+
const { doAutoCheckUpdates } = await this.request({ method: 'GET', endpoint: '/auto-check-updates' })
45+
return doAutoCheckUpdates
46+
}
47+
48+
setDoAutoCheckUpdates ({ doAutoCheckUpdates }: { doAutoCheckUpdates: boolean }) {
49+
return this.request({ method: 'POST', endpoint: '/auto-check-updates', data: { doAutoCheckUpdates } })
50+
}
51+
52+
async getDoOTAUpdates (): Promise<boolean> {
53+
const { doOTAUpdates } = await this.request({ method: 'GET', endpoint: '/ota-updates' })
54+
return doOTAUpdates
55+
}
56+
57+
setDoOTAUpdates ({ doOTAUpdates }: { doOTAUpdates: boolean }) {
58+
return this.request({ method: 'POST', endpoint: '/ota-updates', data: { doOTAUpdates } })
59+
}
5060
}

0 commit comments

Comments
 (0)