ui: fix PR comments

This commit is contained in:
Aaron Greenspan
2021-01-18 11:40:13 -07:00
committed by Aiden McClelland
parent 50b887fcb9
commit d5d0ea3ade
4 changed files with 118 additions and 48 deletions

View File

@@ -59,8 +59,8 @@ export class ServerConfigService {
description: 'On launch, EmabssyOS will automatically check for updates of itself and your installed services. Updating still requires user approval and action. No updates will ever be performed automatically.',
default: true,
},
saveFn: (val: string) => {
return this.apiService.patchServerConfig('autoCheckUpdates', val).then(() => this.serverModel.update({ name: val }))
saveFn: (val: boolean) => {
return this.apiService.patchServerConfig('autoCheckUpdates', val).then(() => this.serverModel.update({ autoCheckUpdates: val }))
},
},
// password: {
@@ -121,5 +121,5 @@ export class ServerConfigService {
interface SpecAndSaveFn {
spec: ValueSpec
saveFn: (val: string) => Promise<any>
saveFn: (val: any) => Promise<any>
}

View File

@@ -90,21 +90,31 @@ export class SyncNotifier {
}
private async handleUpdateCheck (server: Readonly<S9Server>) {
debugSync('handleUpdateCheck', server)
if (!server.autoCheckUpdates || this.checkedForUpdates) return
this.checkedForUpdates = true
debugSync('handleUpdateCheck', 'checkedForUpdates=true')
if (server.versionLatest && this.emver.compare(server.versionInstalled, server.versionLatest) === -1) {
return this.presentAlertNewOS(server.versionLatest)
debugSync('handleUpdateCheck', 'OS Update')
// if cancel selected, move on to newApps
const { update } = await this.presentAlertNewOS(server.versionLatest)
debugSync('handleUpdateCheck', 'OS Update', 'response', update)
if (update) {
return this.updateEmbassyOS(server.versionLatest).catch(e => alert(e))
}
}
try {
debugSync('handleUpdateCheck', 'Apps Check')
const availableApps = await this.apiService.getAvailableApps()
if (!!availableApps.find(app => this.emver.compare(app.versionInstalled, app.versionLatest) === -1)) {
debugSync('handleUpdateCheck', 'Apps Check', 'new apps found')
return this.presentAlertNewApps()
}
} catch {
this.checkedForUpdates = false
} catch (e) {
console.error(`Exception checking for new apps: `, e)
}
}
@@ -112,42 +122,44 @@ export class SyncNotifier {
const alert = await this.alertCtrl.create({
backdropDismiss: true,
header: 'Updates Available!',
message: 'New service updates are availbale in the Marketplace.',
message: 'New service updates are available in the Marketplace.',
buttons: [
{
text: 'Cancel',
role: 'cancel'
role: 'cancel',
},
{
text: 'View in Marketplace',
handler: () => {
return this.navCtrl.navigateForward('/services/marketplace')
}
}
]
},
},
],
})
await alert.present()
}
private async presentAlertNewOS (versionLatest: string) {
const alert = await this.alertCtrl.create({
backdropDismiss: true,
header: 'New EmbassyOS Version!',
message: `Update EmbassyOS to version ${versionLatest}?`,
buttons: [
{
text: 'Not now',
role: 'cancel'
},
{
text: 'Update',
handler: () => {
return this.updateEmbassyOS(versionLatest)
}
}
]
private async presentAlertNewOS (versionLatest: string): Promise<{ cancel?: true, update?: true }> {
return new Promise(async resolve => {
const alert = await this.alertCtrl.create({
backdropDismiss: true,
header: 'New EmbassyOS Version!',
message: `Update EmbassyOS to version ${versionLatest}?`,
buttons: [
{
text: 'Not now',
role: 'cancel',
handler: () => resolve({ cancel: true }),
},
{
text: 'Update',
handler: () => resolve({ update: true }),
},
],
})
await alert.present()
})
await alert.present()
}
private async updateEmbassyOS (versionLatest: string) {
@@ -159,3 +171,47 @@ export class SyncNotifier {
.catch(e => alert(e))
}
}
// @TODO: remove
function debugSync (...desc: any[]) {
console.log(`sync: `, ...desc)
}
// return new Promise(async resolve => {
// const confirm = await this.alertController.create({
// cssClass: 'alert-demo',
// header: 'Warning',
// message: `<h6>This is a <i>hosted</i> instance of Burn After Reading.</h6>
// <p>Since you are not the server operator, you can never be 100% certain that your data are private or secure.</p>
// <p>You can run your own, private instance with the click of a button using the Start9 Embassy.</p>`,
// buttons: [
// {
// text: 'Run my Own',
// handler: () => {
// const a = document.createElement('a')
// const site = (this.config.isConsulate || !this.config.isTor) ? 'https://start9labs.com' : 'http://privacy34kn4ez3y3nijweec6w4g54i3g54sdv7r5mr6soma3w4begyd.onion/'
// a.href = site
// a.target = '_blank'
// pauseFor(500).then(() => a.click())
// return resolve()
// },
// },
// {
// text: 'Use Demo',
// role: 'cancel',
// handler: () => resolve(),
// },
// ],
// })
// await confirm.present()
// const alert = document.getElementsByClassName('alert-demo').item(0)
// this.cleanup(
// fromEvent(alert, 'keyup')
// .pipe(filter((k: KeyboardEvent) => isEnter(k)))
// .subscribe(() => confirm.dismiss()),
// )
// })
// }