mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 04:01:58 +00:00
* refactor: isolate network toast and login redirect to separate services * chore: remove accidentally committed sketch of a service * chore: tidying things up * feat: add `GlobalModule` encapsulating all global subscription services * remove angular build cache when building deps * chore: fix more issues found while testing * chore: fix issues reported by testing * chore: fix template error * chore: fix server-info * chore: fix server-info * fix: switch to Observable to fix race conditions * fix embassy name display on load * update patchdb * clean up patch data watch Co-authored-by: Lucy Cifferello <12953208+elvece@users.noreply.github.com>
119 lines
3.0 KiB
TypeScript
119 lines
3.0 KiB
TypeScript
import { Injectable } from '@angular/core'
|
|
import { AlertInput, AlertButton } from '@ionic/core'
|
|
import { ApiService } from './api/embassy-api.service'
|
|
import { ConfigSpec } from 'src/app/pkg-config/config-types'
|
|
import { AlertController, LoadingController } from '@ionic/angular'
|
|
import { ErrorToastService } from '@start9labs/shared'
|
|
|
|
@Injectable({
|
|
providedIn: 'root',
|
|
})
|
|
export class ServerConfigService {
|
|
constructor(
|
|
private readonly loadingCtrl: LoadingController,
|
|
private readonly errToast: ErrorToastService,
|
|
private readonly alertCtrl: AlertController,
|
|
private readonly embassyApi: ApiService,
|
|
) {}
|
|
|
|
async presentAlert(key: string, current?: any): Promise<HTMLIonAlertElement> {
|
|
const spec = serverConfig[key]
|
|
|
|
let inputs: AlertInput[]
|
|
let buttons: AlertButton[] = [
|
|
{
|
|
text: 'Cancel',
|
|
role: 'cancel',
|
|
},
|
|
{
|
|
text: 'Save',
|
|
handler: async (data: any) => {
|
|
const loader = await this.loadingCtrl.create({
|
|
spinner: 'lines',
|
|
message: 'Saving...',
|
|
cssClass: 'loader',
|
|
})
|
|
loader.present()
|
|
|
|
try {
|
|
await this.saveFns[key](data)
|
|
} catch (e: any) {
|
|
this.errToast.present(e)
|
|
} finally {
|
|
loader.dismiss()
|
|
}
|
|
},
|
|
cssClass: 'enter-click',
|
|
},
|
|
]
|
|
|
|
switch (spec.type) {
|
|
case 'boolean':
|
|
inputs = [
|
|
{
|
|
name: 'enabled',
|
|
type: 'radio',
|
|
label: 'Enabled',
|
|
value: true,
|
|
checked: current,
|
|
},
|
|
{
|
|
name: 'disabled',
|
|
type: 'radio',
|
|
label: 'Disabled',
|
|
value: false,
|
|
checked: !current,
|
|
},
|
|
]
|
|
break
|
|
default:
|
|
return
|
|
}
|
|
|
|
const alert = await this.alertCtrl.create({
|
|
header: spec.name,
|
|
message: spec.description,
|
|
inputs,
|
|
buttons,
|
|
})
|
|
await alert.present()
|
|
return alert
|
|
}
|
|
|
|
// async presentModalForm (key: string) {
|
|
// const modal = await this.modalCtrl.create({
|
|
// component: AppActionInputPage,
|
|
// componentProps: {
|
|
// title: serverConfig[key].name,
|
|
// spec: (serverConfig[key] as ValueSpecObject).spec,
|
|
// },
|
|
// })
|
|
|
|
// modal.onWillDismiss().then(res => {
|
|
// if (!res.data) return
|
|
// this.saveFns[key](res.data)
|
|
// })
|
|
|
|
// await modal.present()
|
|
// }
|
|
|
|
saveFns: { [key: string]: (val: any) => Promise<any> } = {
|
|
'auto-check-updates': async (enabled: boolean) => {
|
|
return this.embassyApi.setDbValue({
|
|
pointer: '/auto-check-updates',
|
|
value: enabled,
|
|
})
|
|
},
|
|
}
|
|
}
|
|
|
|
export const serverConfig: ConfigSpec = {
|
|
'auto-check-updates': {
|
|
type: 'boolean',
|
|
name: 'Auto Check for Updates',
|
|
description:
|
|
'If enabled, EmbassyOS will automatically check for updates of itself. Updating will still require your approval and action. Updates will never be performed automatically.',
|
|
default: true,
|
|
},
|
|
}
|