style: rename platform to bridge (#452)

* style: rename platform to bridge

* chore: tsc
This commit is contained in:
Baptiste Grob
2020-08-25 16:56:32 +02:00
committed by GitHub
parent b2511455dd
commit da78399567
11 changed files with 45 additions and 31 deletions

View File

@@ -1,7 +1,7 @@
'use strict'; 'use strict';
declare const __VERSION__: string; declare const __VERSION__: string;
declare const __PLATFORM_WEB__: boolean; declare const __WEB__: boolean;
import angular from 'angular'; import angular from 'angular';
import { configRoutes } from './routes'; import { configRoutes } from './routes';
@@ -51,22 +51,22 @@ import {
import { trusted } from './filters'; import { trusted } from './filters';
import { isDev } from './utils'; import { isDev } from './utils';
import { Platform, WebPlatform } from './services/platform'; import { Bridge, BrowserBridge } from './services/bridge';
if (__PLATFORM_WEB__) { if (__WEB__) {
startApplication(new WebPlatform()); startApplication(new BrowserBridge());
} else { } else {
(window as any).startApplication = startApplication; (window as any).startApplication = startApplication;
} }
function startApplication(platform: Platform) { function startApplication(bridge: Bridge) {
angular.module('app', ['ngSanitize']); angular.module('app', ['ngSanitize']);
// Config // Config
angular angular
.module('app') .module('app')
.config(configRoutes) .config(configRoutes)
.constant('platform', platform) .constant('bridge', bridge)
.constant('appVersion', __VERSION__); .constant('appVersion', __VERSION__);
// Controllers // Controllers

View File

@@ -1,5 +1,5 @@
/** Platform-specific (i-e desktop/web) behavior is handled by a Platform object. */ /** Platform-specific (i-e Electron/browser) behavior is handled by a Bridge object. */
export interface Platform { export interface Bridge {
getKeychainValue(): Promise<unknown>; getKeychainValue(): Promise<unknown>;
setKeychainValue(value: any): Promise<void>; setKeychainValue(value: any): Promise<void>;
clearKeychainValue(): Promise<void>; clearKeychainValue(): Promise<void>;
@@ -7,7 +7,7 @@ export interface Platform {
const KEYCHAIN_STORAGE_KEY = 'keychain'; const KEYCHAIN_STORAGE_KEY = 'keychain';
export class WebPlatform implements Platform { export class BrowserBridge implements Bridge {
async getKeychainValue(): Promise<unknown> { async getKeychainValue(): Promise<unknown> {
const value = localStorage.getItem(KEYCHAIN_STORAGE_KEY); const value = localStorage.getItem(KEYCHAIN_STORAGE_KEY);
if (value) { if (value) {
@@ -21,4 +21,4 @@ export class WebPlatform implements Platform {
async clearKeychainValue(): Promise<void> { async clearKeychainValue(): Promise<void> {
localStorage.removeItem(KEYCHAIN_STORAGE_KEY); localStorage.removeItem(KEYCHAIN_STORAGE_KEY);
} }
} }

View File

@@ -13,7 +13,7 @@ import {
import angular from 'angular'; import angular from 'angular';
import { getPlatformString } from '@/utils'; import { getPlatformString } from '@/utils';
import { AlertService } from '@/services/alertService'; import { AlertService } from '@/services/alertService';
import { WebDeviceInterface } from '@/interface'; import { WebDeviceInterface } from '@/web_device_interface';
import { import {
DesktopManager, DesktopManager,
LockManager, LockManager,
@@ -26,7 +26,7 @@ import {
} from '@/services'; } from '@/services';
import { AppState } from '@/ui_models/app_state'; import { AppState } from '@/ui_models/app_state';
import { SNWebCrypto } from 'sncrypto/dist/sncrypto-web'; import { SNWebCrypto } from 'sncrypto/dist/sncrypto-web';
import { Platform } from '@/services/platform'; import { Bridge } from '@/services/bridge';
type WebServices = { type WebServices = {
appState: AppState appState: AppState
@@ -56,13 +56,13 @@ export class WebApplication extends SNApplication {
$timeout: ng.ITimeoutService, $timeout: ng.ITimeoutService,
scope: ng.IScope, scope: ng.IScope,
onDeinit: (app: WebApplication) => void, onDeinit: (app: WebApplication) => void,
platform: Platform, bridge: Bridge,
) { ) {
const namespace = ''; const namespace = '';
const deviceInterface = new WebDeviceInterface( const deviceInterface = new WebDeviceInterface(
namespace, namespace,
$timeout, $timeout,
platform bridge
); );
super( super(
Environment.Web, Environment.Web,

View File

@@ -11,7 +11,7 @@ import {
ThemeManager ThemeManager
} from '@/services'; } from '@/services';
import { AppState } from '@/ui_models/app_state'; import { AppState } from '@/ui_models/app_state';
import { Platform } from '@/services/platform'; import { Bridge } from '@/services/bridge';
type AppManagerChangeCallback = () => void type AppManagerChangeCallback = () => void
@@ -29,7 +29,7 @@ export class ApplicationGroup {
$compile: ng.ICompileService, $compile: ng.ICompileService,
$rootScope: ng.IRootScopeService, $rootScope: ng.IRootScopeService,
$timeout: ng.ITimeoutService, $timeout: ng.ITimeoutService,
private platform: Platform private bridge: Bridge
) { ) {
this.$compile = $compile; this.$compile = $compile;
this.$timeout = $timeout; this.$timeout = $timeout;
@@ -71,7 +71,7 @@ export class ApplicationGroup {
this.$timeout, this.$timeout,
scope, scope,
this.onApplicationDeinit, this.onApplicationDeinit,
this.platform this.bridge
); );
const appState = new AppState( const appState = new AppState(
this.$rootScope, this.$rootScope,

View File

@@ -1,6 +1,6 @@
import { DeviceInterface, getGlobalScope, SNApplication } from 'snjs'; import { DeviceInterface, getGlobalScope, SNApplication } from 'snjs';
import { Database } from '@/database'; import { Database } from '@/database';
import { Platform } from './services/platform'; import { Bridge } from './services/bridge';
export class WebDeviceInterface extends DeviceInterface { export class WebDeviceInterface extends DeviceInterface {
@@ -9,7 +9,7 @@ export class WebDeviceInterface extends DeviceInterface {
constructor( constructor(
namespace: string, namespace: string,
timeout: any, timeout: any,
private platform: Platform private bridge: Bridge
) { ) {
super( super(
namespace, namespace,
@@ -101,15 +101,15 @@ export class WebDeviceInterface extends DeviceInterface {
} }
getKeychainValue(): Promise<unknown> { getKeychainValue(): Promise<unknown> {
return this.platform.getKeychainValue(); return this.bridge.getKeychainValue();
} }
setKeychainValue(value: any) { setKeychainValue(value: any) {
return this.platform.setKeychainValue(value); return this.bridge.setKeychainValue(value);
} }
clearKeychainValue() { clearKeychainValue() {
return this.platform.clearKeychainValue(); return this.bridge.clearKeychainValue();
} }
openUrl(url: string) { openUrl(url: string) {

View File

@@ -0,0 +1,11 @@
/** Platform-specific (i-e Electron/browser) behavior is handled by a Bridge object. */
export interface Bridge {
getKeychainValue(): Promise<unknown>;
setKeychainValue(value: any): Promise<void>;
clearKeychainValue(): Promise<void>;
}
export declare class BrowserBridge implements Bridge {
getKeychainValue(): Promise<unknown>;
setKeychainValue(value: any): Promise<void>;
clearKeychainValue(): Promise<void>;
}

View File

@@ -5,7 +5,7 @@ import { PasswordWizardType } from '@/types';
import { SNApplication, Challenge, ProtectedAction } from 'snjs'; import { SNApplication, Challenge, ProtectedAction } from 'snjs';
import { DesktopManager, LockManager, ArchiveManager, NativeExtManager, StatusManager, ThemeManager, PreferencesManager, KeyboardManager } from '@/services'; import { DesktopManager, LockManager, ArchiveManager, NativeExtManager, StatusManager, ThemeManager, PreferencesManager, KeyboardManager } from '@/services';
import { AppState } from '@/ui_models/app_state'; import { AppState } from '@/ui_models/app_state';
import { Platform } from '@/services/platform'; import { Bridge } from '@/services/bridge';
declare type WebServices = { declare type WebServices = {
appState: AppState; appState: AppState;
desktopService: DesktopManager; desktopService: DesktopManager;
@@ -25,7 +25,7 @@ export declare class WebApplication extends SNApplication {
private currentAuthenticationElement?; private currentAuthenticationElement?;
editorGroup: EditorGroup; editorGroup: EditorGroup;
componentGroup: ComponentGroup; componentGroup: ComponentGroup;
constructor($compile: ng.ICompileService, $timeout: ng.ITimeoutService, scope: ng.IScope, onDeinit: (app: WebApplication) => void, platform: Platform); constructor($compile: ng.ICompileService, $timeout: ng.ITimeoutService, scope: ng.IScope, onDeinit: (app: WebApplication) => void, bridge: Bridge);
/** @override */ /** @override */
deinit(): void; deinit(): void;
setWebServices(services: WebServices): void; setWebServices(services: WebServices): void;

View File

@@ -1,16 +1,16 @@
/// <reference types="angular" /> /// <reference types="angular" />
import { WebApplication } from './application'; import { WebApplication } from './application';
import { Platform } from '@/services/platform'; import { Bridge } from '@/services/bridge';
declare type AppManagerChangeCallback = () => void; declare type AppManagerChangeCallback = () => void;
export declare class ApplicationGroup { export declare class ApplicationGroup {
private platform; private bridge;
$compile: ng.ICompileService; $compile: ng.ICompileService;
$rootScope: ng.IRootScopeService; $rootScope: ng.IRootScopeService;
$timeout: ng.ITimeoutService; $timeout: ng.ITimeoutService;
applications: WebApplication[]; applications: WebApplication[];
changeObservers: AppManagerChangeCallback[]; changeObservers: AppManagerChangeCallback[];
activeApplication?: WebApplication; activeApplication?: WebApplication;
constructor($compile: ng.ICompileService, $rootScope: ng.IRootScopeService, $timeout: ng.ITimeoutService, platform: Platform); constructor($compile: ng.ICompileService, $rootScope: ng.IRootScopeService, $timeout: ng.ITimeoutService, bridge: Bridge);
private createDefaultApplication; private createDefaultApplication;
/** @callback */ /** @callback */
onApplicationDeinit(application: WebApplication): void; onApplicationDeinit(application: WebApplication): void;

View File

@@ -22,7 +22,8 @@ export declare class PureViewCtrl<P = CtrlProps, S = CtrlState> {
/** @override */ /** @override */
getInitialState(): S; getInitialState(): S;
setState(state: Partial<S>): Promise<unknown>; setState(state: Partial<S>): Promise<unknown>;
updateUI(func: () => void): Promise<void>; /** @returns a promise that resolves after the UI has been updated. */
flushUI(): import("angular").IPromise<void>;
initProps(props: CtrlProps): void; initProps(props: CtrlProps): void;
addAppStateObserver(): void; addAppStateObserver(): void;
onAppStateEvent(eventName: any, data: any): void; onAppStateEvent(eventName: any, data: any): void;

View File

@@ -1,7 +1,9 @@
import { DeviceInterface, SNApplication } from 'snjs'; import { DeviceInterface, SNApplication } from 'snjs';
import { Bridge } from './services/bridge';
export declare class WebDeviceInterface extends DeviceInterface { export declare class WebDeviceInterface extends DeviceInterface {
private bridge;
private database; private database;
constructor(namespace: string, timeout: any); constructor(namespace: string, timeout: any, bridge: Bridge);
setApplication(application: SNApplication): void; setApplication(application: SNApplication): void;
deinit(): void; deinit(): void;
getRawStorageValue(key: string): Promise<string | null>; getRawStorageValue(key: string): Promise<string | null>;
@@ -22,7 +24,7 @@ export declare class WebDeviceInterface extends DeviceInterface {
saveRawDatabasePayloads(payloads: any[]): Promise<void>; saveRawDatabasePayloads(payloads: any[]): Promise<void>;
removeRawDatabasePayloadWithId(id: string): Promise<void>; removeRawDatabasePayloadWithId(id: string): Promise<void>;
removeAllRawDatabasePayloads(): Promise<void>; removeAllRawDatabasePayloads(): Promise<void>;
getKeychainValue(): Promise<any>; getKeychainValue(): Promise<unknown>;
setKeychainValue(value: any): Promise<void>; setKeychainValue(value: any): Promise<void>;
clearKeychainValue(): Promise<void>; clearKeychainValue(): Promise<void>;
openUrl(url: string): void; openUrl(url: string): void;

View File

@@ -12,7 +12,7 @@ module.exports = (env = {
plugins: [ plugins: [
new webpack.DefinePlugin({ new webpack.DefinePlugin({
__VERSION__: JSON.stringify(require('./package.json').version), __VERSION__: JSON.stringify(require('./package.json').version),
__PLATFORM_WEB__: JSON.stringify(env.platform === 'web'), __WEB__: JSON.stringify(env.platform === 'web'),
}), }),
new MiniCssExtractPlugin({ new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output // Options similar to the same options in webpackOptions.output