* refactor: menuRow directive to MenuRow component * refactor: migrate footer to react * refactor: migrate actions menu to react * refactor: migrate history menu to react * fix: click outside handler use capture to trigger event before re-render occurs which would otherwise cause node.contains to return incorrect result (specifically for the account menu) * refactor: migrate revision preview modal to react * refactor: migrate permissions modal to react * refactor: migrate password wizard to react * refactor: remove unused input modal directive * refactor: remove unused delay hide component * refactor: remove unused filechange directive * refactor: remove unused elemReady directive * refactor: remove unused sn-enter directive * refactor: remove unused lowercase directive * refactor: remove unused autofocus directive * refactor(wip): note view to react * refactor: use mutation observer to deinit textarea listeners * refactor: migrate challenge modal to react * refactor: migrate note group view to react * refactor(wip): migrate remaining classes * fix: navigation parent ref * refactor: fully remove angular assets * fix: account switcher * fix: application view state * refactor: remove unused password wizard type * fix: revision preview and permissions modal * fix: remove angular comment * refactor: react panel resizers for editor * feat: simple panel resizer * fix: use simple panel resizer everywhere * fix: simplify panel resizer state * chore: rename simple panel resizer to panel resizer * refactor: simplify column layout * fix: editor mount safety check * fix: use inline onLoad callback for iframe, as setting onload after it loads will never call it * chore: fix note view test * chore(deps): upgrade snjs
150 lines
3.8 KiB
TypeScript
150 lines
3.8 KiB
TypeScript
import { WebCrypto } from '@/crypto';
|
|
import { AlertService } from '@/services/alertService';
|
|
import { ArchiveManager } from '@/services/archiveManager';
|
|
import { AutolockService } from '@/services/autolock_service';
|
|
import { Bridge } from '@/services/bridge';
|
|
import { DesktopManager } from '@/services/desktopManager';
|
|
import { IOService } from '@/services/ioService';
|
|
import { StatusManager } from '@/services/statusManager';
|
|
import { ThemeManager } from '@/services/themeManager';
|
|
import { AppState } from '@/ui_models/app_state';
|
|
import { WebDeviceInterface } from '@/web_device_interface';
|
|
import {
|
|
DeinitSource,
|
|
Platform,
|
|
SNApplication,
|
|
NoteGroupController,
|
|
removeFromArray,
|
|
} from '@standardnotes/snjs';
|
|
|
|
type WebServices = {
|
|
appState: AppState;
|
|
desktopService: DesktopManager;
|
|
autolockService: AutolockService;
|
|
archiveService: ArchiveManager;
|
|
statusManager: StatusManager;
|
|
themeService: ThemeManager;
|
|
io: IOService;
|
|
};
|
|
|
|
export enum WebAppEvent {
|
|
NewUpdateAvailable = 'NewUpdateAvailable',
|
|
DesktopWindowGainedFocus = 'DesktopWindowGainedFocus',
|
|
DesktopWindowLostFocus = 'DesktopWindowLostFocus',
|
|
}
|
|
|
|
export type WebEventObserver = (event: WebAppEvent) => void;
|
|
|
|
export class WebApplication extends SNApplication {
|
|
private webServices!: WebServices;
|
|
public noteControllerGroup: NoteGroupController;
|
|
private webEventObservers: WebEventObserver[] = [];
|
|
|
|
constructor(
|
|
deviceInterface: WebDeviceInterface,
|
|
platform: Platform,
|
|
identifier: string,
|
|
defaultSyncServerHost: string,
|
|
public bridge: Bridge,
|
|
enableUnfinishedFeatures: boolean,
|
|
webSocketUrl: string
|
|
) {
|
|
super(
|
|
bridge.environment,
|
|
platform,
|
|
deviceInterface,
|
|
WebCrypto,
|
|
new AlertService(),
|
|
identifier,
|
|
[],
|
|
defaultSyncServerHost,
|
|
bridge.appVersion,
|
|
enableUnfinishedFeatures,
|
|
webSocketUrl
|
|
);
|
|
deviceInterface.setApplication(this);
|
|
this.noteControllerGroup = new NoteGroupController(this);
|
|
}
|
|
|
|
/** @override */
|
|
deinit(source: DeinitSource): void {
|
|
for (const service of Object.values(this.webServices)) {
|
|
if ('deinit' in service) {
|
|
service.deinit?.(source);
|
|
}
|
|
(service as any).application = undefined;
|
|
}
|
|
this.webServices = {} as WebServices;
|
|
this.noteControllerGroup.deinit();
|
|
this.webEventObservers.length = 0;
|
|
/**
|
|
* Allow any pending renders to complete before destroying the global
|
|
* application instance and all its services
|
|
*/
|
|
setTimeout(() => {
|
|
super.deinit(source);
|
|
if (source === DeinitSource.SignOut) {
|
|
this.bridge.onSignOut();
|
|
}
|
|
}, 0);
|
|
}
|
|
|
|
setWebServices(services: WebServices): void {
|
|
this.webServices = services;
|
|
}
|
|
|
|
public addWebEventObserver(observer: WebEventObserver): () => void {
|
|
this.webEventObservers.push(observer);
|
|
return () => {
|
|
removeFromArray(this.webEventObservers, observer);
|
|
};
|
|
}
|
|
|
|
public notifyWebEvent(event: WebAppEvent): void {
|
|
for (const observer of this.webEventObservers) {
|
|
observer(event);
|
|
}
|
|
}
|
|
|
|
public getAppState(): AppState {
|
|
return this.webServices.appState;
|
|
}
|
|
|
|
public getDesktopService(): DesktopManager {
|
|
return this.webServices.desktopService;
|
|
}
|
|
|
|
public getAutolockService() {
|
|
return this.webServices.autolockService;
|
|
}
|
|
|
|
public getArchiveService() {
|
|
return this.webServices.archiveService;
|
|
}
|
|
|
|
getStatusManager() {
|
|
return this.webServices.statusManager;
|
|
}
|
|
|
|
public getThemeService() {
|
|
return this.webServices.themeService;
|
|
}
|
|
|
|
public get io() {
|
|
return this.webServices.io;
|
|
}
|
|
|
|
async checkForSecurityUpdate() {
|
|
return this.protocolUpgradeAvailable();
|
|
}
|
|
|
|
downloadBackup(): void | Promise<void> {
|
|
return this.bridge.downloadBackup();
|
|
}
|
|
|
|
async signOutAndDeleteLocalBackups(): Promise<void> {
|
|
await this.bridge.deleteLocalBackups();
|
|
return this.signOut();
|
|
}
|
|
}
|