-
-
Notifications
You must be signed in to change notification settings - Fork 423
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve bridge and exported types
- Loading branch information
Showing
6 changed files
with
68 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,23 @@ | ||
import { PurePayload, Environment } from "snjs"; | ||
/** | ||
* This file will be imported by desktop, so we make sure imports are not | ||
* carrying too much code with them that's not tree-shakeable. | ||
*/ | ||
import { Environment } from 'snjs/lib/platforms'; | ||
export { Environment }; | ||
|
||
/** Platform-specific (i-e Electron/browser) behavior is handled by a Bridge object. */ | ||
export interface Bridge { | ||
environment: Environment, | ||
readonly appVersion: string; | ||
environment: Environment; | ||
|
||
getKeychainValue(): Promise<unknown>; | ||
setKeychainValue(value: any): Promise<void>; | ||
clearKeychainValue(): Promise<void>; | ||
|
||
extensionsServerHost?: string; | ||
syncComponents(payloads: PurePayload[]): void; | ||
syncComponents(payloads: unknown[]): void; | ||
onMajorDataChange(): void; | ||
onInitialDataLoad(): void; | ||
onSearch(text?: string): void; | ||
downloadBackup(): void; | ||
} | ||
|
||
const KEYCHAIN_STORAGE_KEY = 'keychain'; | ||
|
||
export class BrowserBridge implements Bridge { | ||
environment = Environment.Web; | ||
|
||
async getKeychainValue(): Promise<unknown> { | ||
const value = localStorage.getItem(KEYCHAIN_STORAGE_KEY); | ||
if (value) { | ||
return JSON.parse(value); | ||
} | ||
} | ||
|
||
async setKeychainValue(value: any): Promise<void> { | ||
localStorage.setItem(KEYCHAIN_STORAGE_KEY, JSON.stringify(value)); | ||
} | ||
|
||
async clearKeychainValue(): Promise<void> { | ||
localStorage.removeItem(KEYCHAIN_STORAGE_KEY); | ||
} | ||
|
||
/** No-ops */ | ||
|
||
syncComponents() { | ||
} | ||
onMajorDataChange() { | ||
} | ||
onInitialDataLoad() { | ||
} | ||
onSearch() { | ||
} | ||
downloadBackup() { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Bridge } from "./bridge"; | ||
import { Environment } from 'snjs'; | ||
|
||
const KEYCHAIN_STORAGE_KEY = 'keychain'; | ||
|
||
export class BrowserBridge implements Bridge { | ||
constructor(public appVersion: string) {} | ||
environment = Environment.Web; | ||
|
||
async getKeychainValue(): Promise<unknown> { | ||
const value = localStorage.getItem(KEYCHAIN_STORAGE_KEY); | ||
if (value) { | ||
return JSON.parse(value); | ||
} | ||
} | ||
|
||
async setKeychainValue(value: any): Promise<void> { | ||
localStorage.setItem(KEYCHAIN_STORAGE_KEY, JSON.stringify(value)); | ||
} | ||
|
||
async clearKeychainValue(): Promise<void> { | ||
localStorage.removeItem(KEYCHAIN_STORAGE_KEY); | ||
} | ||
|
||
/** No-ops */ | ||
|
||
syncComponents() {} | ||
onMajorDataChange() {} | ||
onInitialDataLoad() {} | ||
onSearch() {} | ||
downloadBackup() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { Bridge } from "./services/bridge"; | ||
|
||
export type StartApplication = ( | ||
defaultSyncServerHost: string, | ||
bridge: Bridge | ||
) => Promise<void>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export {}; | ||
import { Bridge } from './services/bridge'; | ||
export declare type StartApplication = (defaultSyncServerHost: string, bridge: Bridge) => Promise<void>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters