chore: add server switcher (#2717)
* wip * wip2 * refactor: use radio button group * chore: add persisting host per workspace * chore: header style * chore: update server picker title style * chore: margin * chore: label * chore: remove separator * rename migration to latest snjs version --------- Co-authored-by: Aman Harwara <amanharwara@protonmail.com>
This commit is contained in:
@@ -576,10 +576,10 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
||||
return compareVersions(userVersion, ProtocolVersion.V004) >= 0
|
||||
}
|
||||
|
||||
public async setCustomHost(host: string): Promise<void> {
|
||||
public async setCustomHost(host: string, websocketUrl?: string): Promise<void> {
|
||||
await this.setHost.execute(host)
|
||||
|
||||
this.sockets.setWebSocketUrl(undefined)
|
||||
this.sockets.setWebSocketUrl(websocketUrl)
|
||||
}
|
||||
|
||||
public getUserPasswordCreationDate(): Date | undefined {
|
||||
|
||||
@@ -1528,6 +1528,7 @@ export class Dependencies {
|
||||
this.get<HttpService>(TYPES.HttpService),
|
||||
this.get<DiskStorageService>(TYPES.DiskStorageService),
|
||||
this.options.defaultHost,
|
||||
this.options.identifier,
|
||||
this.get<InMemoryStore>(TYPES.InMemoryStore),
|
||||
this.get<PureCryptoInterface>(TYPES.Crypto),
|
||||
this.get<SessionStorageMapper>(TYPES.SessionStorageMapper),
|
||||
|
||||
27
packages/snjs/lib/Migrations/Versions/2_204_8.ts
Normal file
27
packages/snjs/lib/Migrations/Versions/2_204_8.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { ApplicationStage, StorageKey } from '@standardnotes/services'
|
||||
import { Migration } from '@Lib/Migrations/Migration'
|
||||
|
||||
export class Migration2_204_8 extends Migration {
|
||||
static override version(): string {
|
||||
return '2.204.8'
|
||||
}
|
||||
|
||||
protected registerStageHandlers(): void {
|
||||
this.registerStageHandler(ApplicationStage.Launched_10, async () => {
|
||||
await this.migrateHostKeyStoredToWorkspaceIdentified()
|
||||
|
||||
this.markDone()
|
||||
})
|
||||
}
|
||||
|
||||
private async migrateHostKeyStoredToWorkspaceIdentified(): Promise<void> {
|
||||
const existingHostKeyValue = this.services.storageService.getValue<string | undefined>(StorageKey.ServerHost)
|
||||
if (existingHostKeyValue === undefined) {
|
||||
return
|
||||
}
|
||||
|
||||
this.services.storageService.setValue(`${StorageKey.ServerHost}:${this.services.identifier}`, existingHostKeyValue)
|
||||
|
||||
await this.services.storageService.removeValue(StorageKey.ServerHost)
|
||||
}
|
||||
}
|
||||
@@ -106,6 +106,7 @@ export class LegacyApiService
|
||||
private httpService: HttpServiceInterface,
|
||||
private storageService: DiskStorageService,
|
||||
private host: string,
|
||||
private workspaceIdentifier: string,
|
||||
private inMemoryStore: KeyValueStoreInterface<string>,
|
||||
private crypto: PureCryptoInterface,
|
||||
private sessionStorageMapper: MapperInterface<Session, Record<string, unknown>>,
|
||||
@@ -142,14 +143,16 @@ export class LegacyApiService
|
||||
}
|
||||
|
||||
public loadHost(): string {
|
||||
const storedValue = this.storageService.getValue<string | undefined>(StorageKey.ServerHost)
|
||||
const storedValue = this.storageService.getValue<string | undefined>(
|
||||
`${StorageKey.ServerHost}:${this.workspaceIdentifier}`,
|
||||
)
|
||||
this.host = storedValue || this.host
|
||||
return this.host
|
||||
}
|
||||
|
||||
public async setHost(host: string): Promise<void> {
|
||||
this.host = host
|
||||
this.storageService.setValue(StorageKey.ServerHost, host)
|
||||
this.storageService.setValue(`${StorageKey.ServerHost}:${this.workspaceIdentifier}`, host)
|
||||
}
|
||||
|
||||
public getHost(): string {
|
||||
|
||||
@@ -169,7 +169,7 @@ export class SessionManager
|
||||
}
|
||||
}
|
||||
|
||||
const serverHost = this.storage.getValue<string>(StorageKey.ServerHost)
|
||||
const serverHost = this.storage.getValue<string | undefined>(`${StorageKey.ServerHost}:${this.workspaceIdentifier}`)
|
||||
if (serverHost) {
|
||||
void this.apiService.setHost(serverHost)
|
||||
this.httpService.setHost(serverHost)
|
||||
|
||||
4
packages/snjs/lib/Url/DefaultHost.ts
Normal file
4
packages/snjs/lib/Url/DefaultHost.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export enum DefaultHost {
|
||||
Api = 'https://api.standardnotes.com',
|
||||
WebSocket = 'wss://sockets.standardnotes.com',
|
||||
}
|
||||
1
packages/snjs/lib/Url/index.ts
Normal file
1
packages/snjs/lib/Url/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './DefaultHost'
|
||||
@@ -7,6 +7,7 @@ export * from './Log'
|
||||
export * from './Migrations'
|
||||
export * from './Services'
|
||||
export * from './Types'
|
||||
export * from './Url'
|
||||
export * from './Version'
|
||||
export { KeyParamsOrigination } from '@standardnotes/common'
|
||||
export * from '@standardnotes/domain-core'
|
||||
|
||||
Reference in New Issue
Block a user