feat: New one-click Home Server, now in Labs. Launch your own self-hosted server instance with just 1 click from the Preferences window. (#2341)

This commit is contained in:
Mo
2023-07-03 08:30:48 -05:00
committed by GitHub
parent d79e7b14b1
commit 96f42643a9
367 changed files with 5895 additions and 570 deletions

View File

@@ -48,6 +48,13 @@ export class DesktopManager
void this.backups.importWatchedDirectoryChanges(changes)
}
async handleHomeServerStarted(serverUrl: string): Promise<void> {
const userIsSignedIn = this.application.sessions.isSignedIn()
if (!userIsSignedIn) {
await this.application.setCustomHost(serverUrl)
}
}
beginTextBackupsTimer() {
if (this.textBackupsInterval) {
clearInterval(this.textBackupsInterval)

View File

@@ -10,7 +10,11 @@ export {
FileBackupReadToken,
FileBackupReadChunkResponse,
FileDownloadProgress,
HomeServerManagerInterface,
HomeServerStatus,
PlaintextBackupsMapping,
DesktopWatchedDirectoriesChanges,
DesktopWatchedDirectoriesChange,
HomeServerEnvironmentConfiguration,
DirectoryManagerInterface,
} from '@standardnotes/snjs'

View File

@@ -12,6 +12,9 @@ import {
GetSortedPayloadsByPriority,
DatabaseFullEntryLoadChunk,
DatabaseFullEntryLoadChunkResponse,
ApplicationInterface,
namespacedKey,
RawStorageKey,
} from '@standardnotes/snjs'
import { Database } from '../Database'
@@ -30,6 +33,12 @@ export abstract class WebOrDesktopDevice implements WebOrDesktopDeviceInterface
this.databases.push(database)
}
removeApplication(application: ApplicationInterface): void {
const database = this.databaseForIdentifier(application.identifier)
database.deinit()
this.databases = this.databases.filter((db) => db !== database)
}
public async getJsonParsedRawStorageValue(key: string): Promise<unknown | undefined> {
const value = await this.getRawStorageValue(key)
if (value == undefined) {
@@ -87,6 +96,11 @@ export abstract class WebOrDesktopDevice implements WebOrDesktopDeviceInterface
localStorage.clear()
}
async removeRawStorageValuesForIdentifier(identifier: ApplicationIdentifier) {
await this.removeRawStorageValue(namespacedKey(identifier, RawStorageKey.SnjsVersion))
await this.removeRawStorageValue(namespacedKey(identifier, RawStorageKey.StorageObject))
}
async openDatabase(identifier: ApplicationIdentifier) {
this.databaseForIdentifier(identifier).unlock()
return new Promise((resolve, reject) => {

View File

@@ -24,7 +24,7 @@ describe('web application', () => {
SNLog.onLog = console.log
SNLog.onError = console.error
beforeEach(() => {
beforeEach(async () => {
const identifier = '123'
window.matchMedia = jest.fn().mockReturnValue({ matches: false, addListener: jest.fn() })
@@ -34,7 +34,7 @@ describe('web application', () => {
appVersion: '1.2.3',
setApplication: jest.fn(),
openDatabase: jest.fn().mockReturnValue(Promise.resolve()),
getRawStorageValue: jest.fn().mockImplementation((key) => {
getRawStorageValue: jest.fn().mockImplementation(async (key) => {
if (key === namespacedKey(identifier, RawStorageKey.SnjsVersion)) {
return '10.0.0'
}
@@ -49,7 +49,7 @@ describe('web application', () => {
componentManager.legacyGetDefaultEditor = jest.fn()
Object.defineProperty(application, 'componentManager', { value: componentManager })
application.prepareForLaunch({ receiveChallenge: jest.fn() })
await application.prepareForLaunch({ receiveChallenge: jest.fn() })
})
describe('geDefaultEditorIdentifier', () => {

View File

@@ -90,8 +90,12 @@ export class WebApplication extends SNApplication implements WebApplicationInter
deviceInterface.environment === Environment.Mobile ? 250 : ApplicationOptionsDefaults.sleepBetweenBatches,
allowMultipleSelection: deviceInterface.environment !== Environment.Mobile,
allowNoteSelectionStatePersistence: deviceInterface.environment !== Environment.Mobile,
u2fAuthenticatorRegistrationPromptFunction: startRegistration,
u2fAuthenticatorVerificationPromptFunction: startAuthentication,
u2fAuthenticatorRegistrationPromptFunction: startRegistration as unknown as (
registrationOptions: Record<string, unknown>,
) => Promise<Record<string, unknown>>,
u2fAuthenticatorVerificationPromptFunction: startAuthentication as unknown as (
authenticationOptions: Record<string, unknown>,
) => Promise<Record<string, unknown>>,
})
if (isDev) {