Feature/shared refactor (#1176)

* refactor: move most of the shared entities to @start8labs/shared library
This commit is contained in:
Alex Inkin
2022-02-15 18:13:05 +03:00
committed by GitHub
parent 1769f7e2e6
commit 7c26b18c73
164 changed files with 2908 additions and 2860 deletions

View File

@@ -16,17 +16,16 @@ import {
ModalController,
ToastController,
} from '@ionic/angular'
import { Emver } from './services/emver.service'
import { SplitPaneTracker } from './services/split-pane.service'
import { ToastButton } from '@ionic/core'
import { PatchDbService } from './services/patch-db/patch-db.service'
import { ServerStatus, UIData } from './services/patch-db/data-model'
import {
ConnectionFailure,
ConnectionService,
} from './services/connection.service'
import { ConfigService } from './services/config.service'
import { debounce, isEmptyObject } from './util/misc.util'
import { debounce, isEmptyObject, Emver } from '@start9labs/shared'
import { ServerStatus, UIData } from 'src/app/services/patch-db/data-model'
import { ErrorToastService } from './services/error-toast.service'
import { Subscription } from 'rxjs'
import { LocalStorageService } from './services/local-storage.service'
@@ -42,7 +41,7 @@ import { OSWelcomePage } from './modals/os-welcome/os-welcome.page'
export class AppComponent {
@HostListener('document:keydown.enter', ['$event'])
@debounce()
handleKeyboardEvent () {
handleKeyboardEvent() {
const elems = document.getElementsByClassName('enter-click')
const elem = elems[elems.length - 1] as HTMLButtonElement
if (!elem || elem.classList.contains('no-click') || elem.disabled) return
@@ -87,7 +86,7 @@ export class AppComponent {
},
]
constructor (
constructor(
private readonly storage: Storage,
private readonly authService: AuthService,
private readonly router: Router,
@@ -110,7 +109,7 @@ export class AppComponent {
this.init()
}
async init () {
async init() {
await this.storage.create()
await this.authService.init()
await this.localStorageService.init()
@@ -181,7 +180,7 @@ export class AppComponent {
})
}
async goToWebsite (): Promise<void> {
async goToWebsite(): Promise<void> {
let url: string
if (this.config.isTor()) {
url =
@@ -192,7 +191,7 @@ export class AppComponent {
window.open(url, '_blank', 'noreferrer')
}
async presentAlertLogout () {
async presentAlertLogout() {
const alert = await this.alertCtrl.create({
header: 'Caution',
message:
@@ -215,13 +214,13 @@ export class AppComponent {
await alert.present()
}
private checkForEosUpdate (ui: UIData): void {
private checkForEosUpdate(ui: UIData): void {
if (ui['auto-check-updates']) {
this.eosService.getEOS()
}
}
private async showEosWelcome (ackVersion: string): Promise<void> {
private async showEosWelcome(ackVersion: string): Promise<void> {
if (!this.config.skipStartupAlerts && ackVersion !== this.config.version) {
const modal = await this.modalCtrl.create({
component: OSWelcomePage,
@@ -240,12 +239,12 @@ export class AppComponent {
}
// should wipe cache independant of actual BE logout
private async logout () {
private async logout() {
this.embassyApi.logout({})
this.authService.setUnverified()
}
private watchConnection (): Subscription {
private watchConnection(): Subscription {
return this.connectionService
.watchFailure$()
.pipe(distinctUntilChanged(), debounceTime(500))
@@ -278,7 +277,7 @@ export class AppComponent {
})
}
private watchRouter (): Subscription {
private watchRouter(): Subscription {
return this.router.events
.pipe(filter((e: RoutesRecognized) => !!e.urlAfterRedirects))
.subscribe(e => {
@@ -289,7 +288,7 @@ export class AppComponent {
})
}
private watchStatus (): Subscription {
private watchStatus(): Subscription {
return this.patch
.watch$('server-info', 'status-info', 'updated')
.subscribe(isUpdated => {
@@ -300,7 +299,7 @@ export class AppComponent {
}
m
private watchUpdateProgress (): Subscription {
private watchUpdateProgress(): Subscription {
return this.patch
.watch$('server-info', 'status-info', 'update-progress')
.subscribe(progress => {
@@ -308,7 +307,7 @@ export class AppComponent {
})
}
private watchVersion (): Subscription {
private watchVersion(): Subscription {
return this.patch.watch$('server-info', 'version').subscribe(version => {
if (this.emver.compare(this.config.version, version) !== 0) {
this.presentAlertRefreshNeeded()
@@ -316,7 +315,7 @@ export class AppComponent {
})
}
private watchNotifications (): Subscription {
private watchNotifications(): Subscription {
let previous: number
return this.patch
.watch$('server-info', 'unread-notification-count')
@@ -328,7 +327,7 @@ export class AppComponent {
})
}
private async presentAlertRefreshNeeded () {
private async presentAlertRefreshNeeded() {
const alert = await this.alertCtrl.create({
backdropDismiss: false,
header: 'Refresh Needed',
@@ -347,7 +346,7 @@ export class AppComponent {
await alert.present()
}
private async presentToastUpdated () {
private async presentToastUpdated() {
if (this.updateToast) return
this.updateToast = await this.toastCtrl.create({
@@ -377,7 +376,7 @@ export class AppComponent {
await this.updateToast.present()
}
private async presentToastNotifications () {
private async presentToastNotifications() {
if (this.notificationToast) return
this.notificationToast = await this.toastCtrl.create({
@@ -407,7 +406,7 @@ export class AppComponent {
await this.notificationToast.present()
}
private async presentToastOffline (
private async presentToastOffline(
message: string | IonicSafeString,
link?: string,
) {
@@ -448,7 +447,7 @@ export class AppComponent {
await this.offlineToast.present()
}
private async restart (): Promise<void> {
private async restart(): Promise<void> {
const loader = await this.loadingCtrl.create({
spinner: 'lines',
message: 'Restarting...',
@@ -465,7 +464,7 @@ export class AppComponent {
}
}
splitPaneVisible (e: any) {
splitPaneVisible(e: any) {
this.splitPane.sidebarOpen$.next(e.detail.visible)
}
}