feat: remove ionic storage (#1839)

* feat: remove ionic storage

* grayscal when disconncted, rename local storage service for clarity

* remove storage from package lock

* update patchDB

Co-authored-by: Matt Hill <matthewonthemoon@gmail.com>
This commit is contained in:
Alex Inkin
2022-10-04 01:26:31 +03:00
committed by Aiden McClelland
parent 78ad5d5879
commit 141a390105
18 changed files with 115 additions and 179 deletions

View File

@@ -17,7 +17,6 @@
"@angular/platform-browser-dynamic": "^14.1.0", "@angular/platform-browser-dynamic": "^14.1.0",
"@angular/router": "^14.1.0", "@angular/router": "^14.1.0",
"@ionic/angular": "^6.1.15", "@ionic/angular": "^6.1.15",
"@ionic/storage-angular": "^3.0.6",
"@materia-ui/ngx-monaco-editor": "^6.0.0", "@materia-ui/ngx-monaco-editor": "^6.0.0",
"@start9labs/argon2": "^0.1.0", "@start9labs/argon2": "^0.1.0",
"@start9labs/emver": "^0.1.5", "@start9labs/emver": "^0.1.5",
@@ -3007,32 +3006,6 @@
"tslib": "^2.1.0" "tslib": "^2.1.0"
} }
}, },
"node_modules/@ionic/storage": {
"version": "3.0.6",
"resolved": "https://registry.npmjs.org/@ionic/storage/-/storage-3.0.6.tgz",
"integrity": "sha512-sw+zSJINIpbQCGZR9mEtb9N0WmZLuhcMVqOZJBqLuDACAMdXqG39zmp5nSVqhGI1/9X3nd0K5gVn6icyVfUnUg==",
"dependencies": {
"localforage": "^1.9.0"
}
},
"node_modules/@ionic/storage-angular": {
"version": "3.0.6",
"resolved": "https://registry.npmjs.org/@ionic/storage-angular/-/storage-angular-3.0.6.tgz",
"integrity": "sha512-ZXlIFWGU27aCxVFgZb0KFJFtWwnn6+HK6v0rMGzjN8f7oV2ewXaQ2dl1gTw/A8YoozTVPOFxwfFHCjhWLFR1Fw==",
"dependencies": {
"@ionic/storage": "^3.0.4",
"tslib": "^1.10.0"
},
"peerDependencies": {
"@angular/core": "*",
"rxjs": "*"
}
},
"node_modules/@ionic/storage-angular/node_modules/tslib": {
"version": "1.14.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz",
"integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg=="
},
"node_modules/@ionic/utils-array": { "node_modules/@ionic/utils-array": {
"version": "2.1.5", "version": "2.1.5",
"resolved": "https://registry.npmjs.org/@ionic/utils-array/-/utils-array-2.1.5.tgz", "resolved": "https://registry.npmjs.org/@ionic/utils-array/-/utils-array-2.1.5.tgz",
@@ -7941,11 +7914,6 @@
"node": ">=0.10.0" "node": ">=0.10.0"
} }
}, },
"node_modules/immediate": {
"version": "3.0.6",
"resolved": "https://registry.npmjs.org/immediate/-/immediate-3.0.6.tgz",
"integrity": "sha512-XXOFtyqDjNDAQxVfYxuF7g9Il/IbWmmlQg2MYKOH8ExIT1qg6xc4zyS3HaEEATgs1btfzxq15ciUiY7gjSXRGQ=="
},
"node_modules/immutable": { "node_modules/immutable": {
"version": "4.1.0", "version": "4.1.0",
"resolved": "https://registry.npmjs.org/immutable/-/immutable-4.1.0.tgz", "resolved": "https://registry.npmjs.org/immutable/-/immutable-4.1.0.tgz",
@@ -8709,14 +8677,6 @@
} }
} }
}, },
"node_modules/lie": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/lie/-/lie-3.1.1.tgz",
"integrity": "sha512-RiNhHysUjhrDQntfYSfY4MU24coXXdEOgw9WGcKHNeEwffDYbF//u87M1EWaMGzuFoSbqW0C9C6lEEhDOAswfw==",
"dependencies": {
"immediate": "~3.0.5"
}
},
"node_modules/lilconfig": { "node_modules/lilconfig": {
"version": "2.0.5", "version": "2.0.5",
"resolved": "https://registry.npmjs.org/lilconfig/-/lilconfig-2.0.5.tgz", "resolved": "https://registry.npmjs.org/lilconfig/-/lilconfig-2.0.5.tgz",
@@ -8883,14 +8843,6 @@
"node": ">= 12.13.0" "node": ">= 12.13.0"
} }
}, },
"node_modules/localforage": {
"version": "1.10.0",
"resolved": "https://registry.npmjs.org/localforage/-/localforage-1.10.0.tgz",
"integrity": "sha512-14/H1aX7hzBBmmh7sGPd+AOMkkIrHM3Z1PAyGgZigA1H1p5O5ANnMyWzvpAETtG68/dC4pC0ncy3+PPGzXZHPg==",
"dependencies": {
"lie": "3.1.1"
}
},
"node_modules/locate-path": { "node_modules/locate-path": {
"version": "5.0.0", "version": "5.0.0",
"resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz",
@@ -16712,30 +16664,6 @@
"tslib": "^2.1.0" "tslib": "^2.1.0"
} }
}, },
"@ionic/storage": {
"version": "3.0.6",
"resolved": "https://registry.npmjs.org/@ionic/storage/-/storage-3.0.6.tgz",
"integrity": "sha512-sw+zSJINIpbQCGZR9mEtb9N0WmZLuhcMVqOZJBqLuDACAMdXqG39zmp5nSVqhGI1/9X3nd0K5gVn6icyVfUnUg==",
"requires": {
"localforage": "^1.9.0"
}
},
"@ionic/storage-angular": {
"version": "3.0.6",
"resolved": "https://registry.npmjs.org/@ionic/storage-angular/-/storage-angular-3.0.6.tgz",
"integrity": "sha512-ZXlIFWGU27aCxVFgZb0KFJFtWwnn6+HK6v0rMGzjN8f7oV2ewXaQ2dl1gTw/A8YoozTVPOFxwfFHCjhWLFR1Fw==",
"requires": {
"@ionic/storage": "^3.0.4",
"tslib": "^1.10.0"
},
"dependencies": {
"tslib": {
"version": "1.14.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz",
"integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg=="
}
}
},
"@ionic/utils-array": { "@ionic/utils-array": {
"version": "2.1.5", "version": "2.1.5",
"resolved": "https://registry.npmjs.org/@ionic/utils-array/-/utils-array-2.1.5.tgz", "resolved": "https://registry.npmjs.org/@ionic/utils-array/-/utils-array-2.1.5.tgz",
@@ -20403,11 +20331,6 @@
"dev": true, "dev": true,
"optional": true "optional": true
}, },
"immediate": {
"version": "3.0.6",
"resolved": "https://registry.npmjs.org/immediate/-/immediate-3.0.6.tgz",
"integrity": "sha512-XXOFtyqDjNDAQxVfYxuF7g9Il/IbWmmlQg2MYKOH8ExIT1qg6xc4zyS3HaEEATgs1btfzxq15ciUiY7gjSXRGQ=="
},
"immutable": { "immutable": {
"version": "4.1.0", "version": "4.1.0",
"resolved": "https://registry.npmjs.org/immutable/-/immutable-4.1.0.tgz", "resolved": "https://registry.npmjs.org/immutable/-/immutable-4.1.0.tgz",
@@ -20978,14 +20901,6 @@
"webpack-sources": "^3.0.0" "webpack-sources": "^3.0.0"
} }
}, },
"lie": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/lie/-/lie-3.1.1.tgz",
"integrity": "sha512-RiNhHysUjhrDQntfYSfY4MU24coXXdEOgw9WGcKHNeEwffDYbF//u87M1EWaMGzuFoSbqW0C9C6lEEhDOAswfw==",
"requires": {
"immediate": "~3.0.5"
}
},
"lilconfig": { "lilconfig": {
"version": "2.0.5", "version": "2.0.5",
"resolved": "https://registry.npmjs.org/lilconfig/-/lilconfig-2.0.5.tgz", "resolved": "https://registry.npmjs.org/lilconfig/-/lilconfig-2.0.5.tgz",
@@ -21103,14 +21018,6 @@
"integrity": "sha512-HVl9ZqccQihZ7JM85dco1MvO9G+ONvxoGa9rkhzFsneGLKSUg1gJf9bWzhRhcvm2qChhWpebQhP44qxjKIUCaQ==", "integrity": "sha512-HVl9ZqccQihZ7JM85dco1MvO9G+ONvxoGa9rkhzFsneGLKSUg1gJf9bWzhRhcvm2qChhWpebQhP44qxjKIUCaQ==",
"dev": true "dev": true
}, },
"localforage": {
"version": "1.10.0",
"resolved": "https://registry.npmjs.org/localforage/-/localforage-1.10.0.tgz",
"integrity": "sha512-14/H1aX7hzBBmmh7sGPd+AOMkkIrHM3Z1PAyGgZigA1H1p5O5ANnMyWzvpAETtG68/dC4pC0ncy3+PPGzXZHPg==",
"requires": {
"lie": "3.1.1"
}
},
"locate-path": { "locate-path": {
"version": "5.0.0", "version": "5.0.0",
"resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz",

View File

@@ -31,7 +31,6 @@
"@angular/platform-browser-dynamic": "^14.1.0", "@angular/platform-browser-dynamic": "^14.1.0",
"@angular/router": "^14.1.0", "@angular/router": "^14.1.0",
"@ionic/angular": "^6.1.15", "@ionic/angular": "^6.1.15",
"@ionic/storage-angular": "^3.0.6",
"@materia-ui/ngx-monaco-editor": "^6.0.0", "@materia-ui/ngx-monaco-editor": "^6.0.0",
"@start9labs/argon2": "^0.1.0", "@start9labs/argon2": "^0.1.0",
"@start9labs/emver": "^0.1.5", "@start9labs/emver": "^0.1.5",

View File

@@ -10,7 +10,11 @@
<app-menu *ngIf="authService.isVerified$ | async"></app-menu> <app-menu *ngIf="authService.isVerified$ | async"></app-menu>
</ion-content> </ion-content>
</ion-menu> </ion-menu>
<ion-router-outlet id="main-content"></ion-router-outlet> <ion-router-outlet
id="main-content"
class="container"
[class.container_offline]="!(connection.connected$ | async)"
></ion-router-outlet>
</ion-split-pane> </ion-split-pane>
<section appPreloader></section> <section appPreloader></section>

View File

@@ -5,3 +5,11 @@
ion-split-pane { ion-split-pane {
--side-max-width: 280px; --side-max-width: 280px;
} }
.container {
transition: filter 0.3s;
&_offline {
filter: saturate(0) contrast(0.85);
}
}

View File

@@ -4,6 +4,7 @@ import { AuthService } from './services/auth.service'
import { SplitPaneTracker } from './services/split-pane.service' import { SplitPaneTracker } from './services/split-pane.service'
import { PatchDataService } from './services/patch-data.service' import { PatchDataService } from './services/patch-data.service'
import { PatchMonitorService } from './services/patch-monitor.service' import { PatchMonitorService } from './services/patch-monitor.service'
import { ConnectionService } from './services/connection.service'
@Component({ @Component({
selector: 'app-root', selector: 'app-root',
@@ -19,6 +20,7 @@ export class AppComponent implements OnDestroy {
private readonly patchMonitor: PatchMonitorService, private readonly patchMonitor: PatchMonitorService,
private readonly splitPane: SplitPaneTracker, private readonly splitPane: SplitPaneTracker,
readonly authService: AuthService, readonly authService: AuthService,
readonly connection: ConnectionService,
) {} ) {}
splitPaneVisible({ detail }: any) { splitPaneVisible({ detail }: any) {

View File

@@ -2,8 +2,6 @@ import { HttpClientModule } from '@angular/common/http'
import { NgModule } from '@angular/core' import { NgModule } from '@angular/core'
import { BrowserAnimationsModule } from '@angular/platform-browser/animations' import { BrowserAnimationsModule } from '@angular/platform-browser/animations'
import { IonicModule } from '@ionic/angular' import { IonicModule } from '@ionic/angular'
import { Drivers } from '@ionic/storage'
import { IonicStorageModule } from '@ionic/storage-angular'
import { MonacoEditorModule } from '@materia-ui/ngx-monaco-editor' import { MonacoEditorModule } from '@materia-ui/ngx-monaco-editor'
import { MarkdownModule, SharedPipesModule } from '@start9labs/shared' import { MarkdownModule, SharedPipesModule } from '@start9labs/shared'
@@ -30,12 +28,6 @@ import { ConnectionBarComponentModule } from './components/connection-bar/connec
mode: 'md', mode: 'md',
}), }),
AppRoutingModule, AppRoutingModule,
IonicStorageModule.forRoot({
storeName: '_embassykv',
dbKey: '_embassykey',
name: '_embassystorage',
driverOrder: [Drivers.LocalStorage],
}),
MenuModule, MenuModule,
PreloaderModule, PreloaderModule,
FooterModule, FooterModule,

View File

@@ -2,13 +2,12 @@ import { APP_INITIALIZER, Provider } from '@angular/core'
import { UntypedFormBuilder } from '@angular/forms' import { UntypedFormBuilder } from '@angular/forms'
import { Router, RouteReuseStrategy } from '@angular/router' import { Router, RouteReuseStrategy } from '@angular/router'
import { IonicRouteStrategy, IonNav } from '@ionic/angular' import { IonicRouteStrategy, IonNav } from '@ionic/angular'
import { Storage } from '@ionic/storage-angular'
import { WorkspaceConfig } from '@start9labs/shared' import { WorkspaceConfig } from '@start9labs/shared'
import { ApiService } from './services/api/embassy-api.service' import { ApiService } from './services/api/embassy-api.service'
import { MockApiService } from './services/api/embassy-mock-api.service' import { MockApiService } from './services/api/embassy-mock-api.service'
import { LiveApiService } from './services/api/embassy-live-api.service' import { LiveApiService } from './services/api/embassy-live-api.service'
import { AuthService } from './services/auth.service' import { AuthService } from './services/auth.service'
import { LocalStorageService } from './services/local-storage.service' import { ClientStorageService } from './services/client-storage.service'
import { FilterPackagesPipe } from '../../../marketplace/src/pipes/filter-packages.pipe' import { FilterPackagesPipe } from '../../../marketplace/src/pipes/filter-packages.pipe'
const { useMocks } = require('../../../../config.json') as WorkspaceConfig const { useMocks } = require('../../../../config.json') as WorkspaceConfig
@@ -27,23 +26,20 @@ export const APP_PROVIDERS: Provider[] = [
}, },
{ {
provide: APP_INITIALIZER, provide: APP_INITIALIZER,
deps: [Storage, AuthService, LocalStorageService, Router], deps: [AuthService, ClientStorageService, Router],
useFactory: appInitializer, useFactory: appInitializer,
multi: true, multi: true,
}, },
] ]
export function appInitializer( export function appInitializer(
storage: Storage,
auth: AuthService, auth: AuthService,
localStorage: LocalStorageService, localStorage: ClientStorageService,
router: Router, router: Router,
): () => Promise<void> { ): () => void {
return async () => { return () => {
await storage.create() auth.init()
await auth.init() localStorage.init()
await localStorage.init()
router.initialNavigation() router.initialNavigation()
} }
} }

View File

@@ -46,9 +46,8 @@ export class LoginPage {
}) })
this.password = '' this.password = ''
this.authService this.authService.setVerified()
.setVerified() this.router.navigate([''], { replaceUrl: true })
.then(() => this.router.navigate([''], { replaceUrl: true }))
} catch (e: any) { } catch (e: any) {
// code 7 is for incorrect password // code 7 is for incorrect password
this.error = e.code === 7 ? 'Invalid Password' : e.message this.error = e.code === 7 ? 'Invalid Password' : e.message

View File

@@ -15,7 +15,7 @@ import {
PackageDataEntry, PackageDataEntry,
PackageState, PackageState,
} from 'src/app/services/patch-db/data-model' } from 'src/app/services/patch-db/data-model'
import { LocalStorageService } from 'src/app/services/local-storage.service' import { ClientStorageService } from 'src/app/services/client-storage.service'
import { MarketplaceService } from 'src/app/services/marketplace.service' import { MarketplaceService } from 'src/app/services/marketplace.service'
import { hasCurrentDeps } from 'src/app/util/has-deps' import { hasCurrentDeps } from 'src/app/util/has-deps'
import { ApiService } from 'src/app/services/api/embassy-api.service' import { ApiService } from 'src/app/services/api/embassy-api.service'
@@ -37,13 +37,13 @@ export class MarketplaceShowControlsComponent {
@Input() @Input()
localPkg!: PackageDataEntry | null localPkg!: PackageDataEntry | null
readonly showDevTools$ = this.localStorageService.showDevTools$ readonly showDevTools$ = this.ClientStorageService.showDevTools$
readonly PackageState = PackageState readonly PackageState = PackageState
constructor( constructor(
private readonly alertCtrl: AlertController, private readonly alertCtrl: AlertController,
private readonly localStorageService: LocalStorageService, private readonly ClientStorageService: ClientStorageService,
@Inject(AbstractMarketplaceService) @Inject(AbstractMarketplaceService)
private readonly marketplaceService: MarketplaceService, private readonly marketplaceService: MarketplaceService,
private readonly loadingCtrl: LoadingController, private readonly loadingCtrl: LoadingController,

View File

@@ -11,7 +11,7 @@ import {
} from 'src/app/modals/generic-input/generic-input.component' } from 'src/app/modals/generic-input/generic-input.component'
import { ApiService } from 'src/app/services/api/embassy-api.service' import { ApiService } from 'src/app/services/api/embassy-api.service'
import { ServerConfigService } from 'src/app/services/server-config.service' import { ServerConfigService } from 'src/app/services/server-config.service'
import { LocalStorageService } from '../../../services/local-storage.service' import { ClientStorageService } from '../../../services/client-storage.service'
import { import {
ServerNameInfo, ServerNameInfo,
ServerNameService, ServerNameService,
@@ -36,7 +36,7 @@ export class PreferencesPage {
private readonly modalCtrl: ModalController, private readonly modalCtrl: ModalController,
private readonly api: ApiService, private readonly api: ApiService,
private readonly toastCtrl: ToastController, private readonly toastCtrl: ToastController,
private readonly localStorageService: LocalStorageService, private readonly ClientStorageService: ClientStorageService,
private readonly patch: PatchDB<DataModel>, private readonly patch: PatchDB<DataModel>,
private readonly serverNameService: ServerNameService, private readonly serverNameService: ServerNameService,
readonly serverConfig: ServerConfigService, readonly serverConfig: ServerConfigService,
@@ -83,7 +83,7 @@ export class PreferencesPage {
this.clicks++ this.clicks++
if (this.clicks >= 5) { if (this.clicks >= 5) {
this.clicks = 0 this.clicks = 0
const newVal = await this.localStorageService.toggleShowDevTools() const newVal = this.ClientStorageService.toggleShowDevTools()
const toast = await this.toastCtrl.create({ const toast = await this.toastCtrl.create({
header: newVal ? 'Dev tools unlocked' : 'Dev tools hidden', header: newVal ? 'Dev tools unlocked' : 'Dev tools hidden',
position: 'bottom', position: 'bottom',

View File

@@ -12,7 +12,7 @@ import { ServerNameService } from 'src/app/services/server-name.service'
import { Observable, of } from 'rxjs' import { Observable, of } from 'rxjs'
import { ErrorToastService } from '@start9labs/shared' import { ErrorToastService } from '@start9labs/shared'
import { EOSService } from 'src/app/services/eos.service' import { EOSService } from 'src/app/services/eos.service'
import { LocalStorageService } from 'src/app/services/local-storage.service' import { ClientStorageService } from 'src/app/services/client-storage.service'
import { OSUpdatePage } from 'src/app/modals/os-update/os-update.page' import { OSUpdatePage } from 'src/app/modals/os-update/os-update.page'
import { getAllPackages } from '../../../util/get-package-data' import { getAllPackages } from '../../../util/get-package-data'
import { AuthService } from 'src/app/services/auth.service' import { AuthService } from 'src/app/services/auth.service'
@@ -29,7 +29,7 @@ export class ServerShowPage {
readonly server$ = this.patch.watch$('server-info') readonly server$ = this.patch.watch$('server-info')
readonly name$ = this.serverNameService.name$ readonly name$ = this.serverNameService.name$
readonly showUpdate$ = this.eosService.showUpdate$ readonly showUpdate$ = this.eosService.showUpdate$
readonly showDiskRepair$ = this.localStorageService.showDiskRepair$ readonly showDiskRepair$ = this.ClientStorageService.showDiskRepair$
constructor( constructor(
private readonly alertCtrl: AlertController, private readonly alertCtrl: AlertController,
@@ -41,7 +41,7 @@ export class ServerShowPage {
private readonly route: ActivatedRoute, private readonly route: ActivatedRoute,
private readonly patch: PatchDB<DataModel>, private readonly patch: PatchDB<DataModel>,
private readonly eosService: EOSService, private readonly eosService: EOSService,
private readonly localStorageService: LocalStorageService, private readonly ClientStorageService: ClientStorageService,
private readonly serverNameService: ServerNameService, private readonly serverNameService: ServerNameService,
private readonly authService: AuthService, private readonly authService: AuthService,
) {} ) {}
@@ -511,11 +511,11 @@ export class ServerShowPage {
return 0 return 0
} }
async addClick() { addClick() {
this.clicks++ this.clicks++
if (this.clicks >= 5) { if (this.clicks >= 5) {
this.clicks = 0 this.clicks = 0
await this.localStorageService.toggleShowDiskRepair() this.ClientStorageService.toggleShowDiskRepair()
} }
setTimeout(() => { setTimeout(() => {
this.clicks = Math.max(this.clicks - 1, 0) this.clicks = Math.max(this.clicks - 1, 0)

View File

@@ -946,7 +946,7 @@ export class MockApiService extends ApiService {
private async mockRevision<T>(patch: Operation<T>[]): Promise<void> { private async mockRevision<T>(patch: Operation<T>[]): Promise<void> {
if (!this.sequence) { if (!this.sequence) {
const { sequence } = await this.bootstrapper.init() const { sequence } = this.bootstrapper.init()
this.sequence = sequence this.sequence = sequence
} }
const revision = { const revision = {
@@ -961,7 +961,7 @@ export class MockApiService extends ApiService {
response: T | null = null, response: T | null = null,
): Promise<T> { ): Promise<T> {
if (!this.sequence) { if (!this.sequence) {
const { sequence } = await this.bootstrapper.init() const { sequence } = this.bootstrapper.init()
this.sequence = sequence this.sequence = sequence
} }

View File

@@ -1,8 +1,8 @@
import { Injectable, NgZone } from '@angular/core' import { Injectable, NgZone } from '@angular/core'
import { ReplaySubject } from 'rxjs' import { ReplaySubject } from 'rxjs'
import { distinctUntilChanged, map } from 'rxjs/operators' import { distinctUntilChanged, map } from 'rxjs/operators'
import { Storage } from '@ionic/storage-angular'
import { Router } from '@angular/router' import { Router } from '@angular/router'
import { StorageService } from './storage.service'
export enum AuthState { export enum AuthState {
UNVERIFIED, UNVERIFIED,
@@ -21,13 +21,13 @@ export class AuthService {
) )
constructor( constructor(
private readonly storage: Storage, private readonly storage: StorageService,
private readonly zone: NgZone, private readonly zone: NgZone,
private readonly router: Router, private readonly router: Router,
) {} ) {}
async init(): Promise<void> { init(): void {
const loggedIn = await this.storage.get(this.LOGGED_IN_KEY) const loggedIn = this.storage.get(this.LOGGED_IN_KEY)
if (loggedIn) { if (loggedIn) {
this.setVerified() this.setVerified()
} else { } else {
@@ -35,8 +35,8 @@ export class AuthService {
} }
} }
async setVerified(): Promise<void> { setVerified(): void {
await this.storage.set(this.LOGGED_IN_KEY, true) this.storage.set(this.LOGGED_IN_KEY, true)
this.authState$.next(AuthState.VERIFIED) this.authState$.next(AuthState.VERIFIED)
} }

View File

@@ -0,0 +1,34 @@
import { Injectable } from '@angular/core'
import { BehaviorSubject } from 'rxjs'
import { StorageService } from './storage.service'
const SHOW_DEV_TOOLS = 'SHOW_DEV_TOOLS'
const SHOW_DISK_REPAIR = 'SHOW_DISK_REPAIR'
@Injectable({
providedIn: 'root',
})
export class ClientStorageService {
readonly showDevTools$ = new BehaviorSubject<boolean>(false)
readonly showDiskRepair$ = new BehaviorSubject<boolean>(false)
constructor(private readonly storage: StorageService) {}
init() {
this.showDevTools$.next(!!this.storage.get(SHOW_DEV_TOOLS))
this.showDiskRepair$.next(!!this.storage.get(SHOW_DISK_REPAIR))
}
toggleShowDevTools(): boolean {
const newVal = !this.storage.get(SHOW_DEV_TOOLS)
this.storage.set(SHOW_DEV_TOOLS, newVal)
this.showDevTools$.next(newVal)
return newVal
}
toggleShowDiskRepair(): boolean {
const newVal = !this.storage.get(SHOW_DISK_REPAIR)
this.storage.set(SHOW_DISK_REPAIR, newVal)
this.showDiskRepair$.next(newVal)
return newVal
}
}

View File

@@ -1,36 +0,0 @@
import { Injectable } from '@angular/core'
import { Storage } from '@ionic/storage-angular'
import { BehaviorSubject } from 'rxjs'
const SHOW_DEV_TOOLS = 'SHOW_DEV_TOOLS'
const SHOW_DISK_REPAIR = 'SHOW_DISK_REPAIR'
@Injectable({
providedIn: 'root',
})
export class LocalStorageService {
readonly showDevTools$ = new BehaviorSubject<boolean>(false)
readonly showDiskRepair$ = new BehaviorSubject<boolean>(false)
constructor(private readonly storage: Storage) {}
async init() {
const devTools = await this.storage.get(SHOW_DEV_TOOLS)
this.showDevTools$.next(!!devTools)
const diskRepair = await this.storage.get(SHOW_DISK_REPAIR)
this.showDiskRepair$.next(!!diskRepair)
}
async toggleShowDevTools(): Promise<boolean> {
const newVal = !(await this.storage.get(SHOW_DEV_TOOLS))
await this.storage.set(SHOW_DEV_TOOLS, newVal)
this.showDevTools$.next(newVal)
return newVal
}
async toggleShowDiskRepair(): Promise<boolean> {
const newVal = !(await this.storage.get(SHOW_DISK_REPAIR))
await this.storage.set(SHOW_DISK_REPAIR, newVal)
this.showDiskRepair$.next(newVal)
return newVal
}
}

View File

@@ -1,7 +1,7 @@
import { Bootstrapper, DBCache } from 'patch-db-client' import { Bootstrapper, DBCache } from 'patch-db-client'
import { DataModel } from 'src/app/services/patch-db/data-model' import { DataModel } from 'src/app/services/patch-db/data-model'
import { Injectable } from '@angular/core' import { Injectable } from '@angular/core'
import { Storage } from '@ionic/storage-angular' import { StorageService } from '../storage.service'
@Injectable({ @Injectable({
providedIn: 'root', providedIn: 'root',
@@ -9,16 +9,17 @@ import { Storage } from '@ionic/storage-angular'
export class LocalStorageBootstrap implements Bootstrapper<DataModel> { export class LocalStorageBootstrap implements Bootstrapper<DataModel> {
static CONTENT_KEY = 'patch-db-cache' static CONTENT_KEY = 'patch-db-cache'
constructor(private readonly storage: Storage) {} constructor(private readonly storage: StorageService) {}
async init(): Promise<DBCache<DataModel>> { init(): DBCache<DataModel> {
const cache: DBCache<DataModel> = await this.storage.get( const cache = this.storage.get<DBCache<DataModel>>(
LocalStorageBootstrap.CONTENT_KEY, LocalStorageBootstrap.CONTENT_KEY,
) )
return cache || { sequence: 0, data: {} as DataModel } return cache || { sequence: 0, data: {} as DataModel }
} }
async update(cache: DBCache<DataModel>): Promise<void> { update(cache: DBCache<DataModel>): void {
await this.storage.set(LocalStorageBootstrap.CONTENT_KEY, cache) this.storage.set(LocalStorageBootstrap.CONTENT_KEY, cache)
} }
} }

View File

@@ -0,0 +1,30 @@
import { Inject, Injectable } from '@angular/core'
import { DOCUMENT } from '@angular/common'
const PREFIX = '_embassystorage/_embassykv/'
@Injectable({
providedIn: 'root',
})
export class StorageService {
private readonly storage = this.document.defaultView!.localStorage
constructor(@Inject(DOCUMENT) private readonly document: Document) {}
get<T>(key: string): T {
return JSON.parse(String(this.storage.getItem(`${PREFIX}${key}`)))
}
set<T>(key: string, value: T) {
this.storage.setItem(`${PREFIX}${key}`, JSON.stringify(value))
}
clear() {
Array.from(
{ length: this.storage.length },
(_, i) => this.storage.key(i) || '',
)
.filter(key => key.startsWith(PREFIX))
.forEach(key => this.storage.removeItem(key))
}
}