internal: move home server into internal flag

This commit is contained in:
Mo
2023-07-05 10:53:10 -05:00
parent d4db3e055c
commit c9c93d143a
16 changed files with 47 additions and 29 deletions

View File

@@ -28,6 +28,7 @@ export function initializeApplication(args: { app: Electron.App; ipcMain: Electr
if (isDev()) { if (isDev()) {
/** Expose the app's state as a global variable. Useful for debugging */ /** Expose the app's state as a global variable. Useful for debugging */
// eslint-disable-next-line @typescript-eslint/no-explicit-any
;(global as any).appState = state ;(global as any).appState = state
setTimeout(() => { setTimeout(() => {
@@ -124,7 +125,6 @@ async function finishApplicationInitialization({ app, shell, state }: { app: App
}) })
if (state.isRunningVersionForFirstTime()) { if (state.isRunningVersionForFirstTime()) {
console.log('Clearing window cache')
await windowState.window.webContents.session.clearCache() await windowState.window.webContents.session.clearCache()
} }

View File

@@ -4,7 +4,7 @@ import {
HomeServerManagerInterface, HomeServerManagerInterface,
HomeServerEnvironmentConfiguration, HomeServerEnvironmentConfiguration,
} from '@web/Application/Device/DesktopSnjsExports' } from '@web/Application/Device/DesktopSnjsExports'
import { HomeServer, HomeServerInterface } from '@standardnotes/home-server' import { HomeServerInterface } from '@standardnotes/home-server'
import { WebContents } from 'electron' import { WebContents } from 'electron'
import { MessageToWebApp } from '../../Shared/IpcMessages' import { MessageToWebApp } from '../../Shared/IpcMessages'
@@ -127,7 +127,7 @@ export class HomeServerManager implements HomeServerManagerInterface {
} }
async startHomeServer(): Promise<string | undefined> { async startHomeServer(): Promise<string | undefined> {
this.doNotInstantiateHomeServerOnWindowsUntilItIsSupported() await this.lazyLoadHomeServerOnApplicablePlatforms()
if (!this.homeServer) { if (!this.homeServer) {
return return
@@ -265,9 +265,17 @@ export class HomeServerManager implements HomeServerManagerInterface {
return configuration return configuration
} }
private doNotInstantiateHomeServerOnWindowsUntilItIsSupported(): void { private async lazyLoadHomeServerOnApplicablePlatforms(): Promise<void> {
if (!isWindows() && !this.homeServer) { if (isWindows()) {
this.homeServer = new HomeServer() return
} }
if (this.homeServer) {
return
}
const { HomeServer } = await import('@standardnotes/home-server')
this.homeServer = new HomeServer()
} }
} }

View File

@@ -61,6 +61,7 @@ export async function createWindowState({
const services = await createWindowServices(window, appState, appLocale) const services = await createWindowServices(window, appState, appLocale)
require('@electron/remote/main').enable(window.webContents) require('@electron/remote/main').enable(window.webContents)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
;(global as any).RemoteBridge = new RemoteBridge( ;(global as any).RemoteBridge = new RemoteBridge(
window, window,
Keychain, Keychain,

View File

@@ -22,6 +22,8 @@ process.once('loaded', function () {
setHomeServerStartedHandler: (handler: MainEventHandler) => setHomeServerStartedHandler: (handler: MainEventHandler) =>
ipcRenderer.on(MessageToWebApp.HomeServerStarted, handler), ipcRenderer.on(MessageToWebApp.HomeServerStarted, handler),
setConsoleLogHandler: (handler: MainEventHandler) => ipcRenderer.on(MessageToWebApp.ConsoleLog, handler),
} }
contextBridge.exposeInMainWorld('electronMainEvents', mainEvents) contextBridge.exposeInMainWorld('electronMainEvents', mainEvents)

View File

@@ -150,8 +150,13 @@ window.electronMainEvents.setWindowFocusedHandler(() => {
window.webClient.windowGainedFocus() window.webClient.windowGainedFocus()
}) })
window.electronMainEvents.setInstallComponentCompleteHandler((_: IpcRendererEvent, data: any) => { window.electronMainEvents.setConsoleLogHandler((_: IpcRendererEvent, message: unknown) => {
void window.webClient.onComponentInstallationComplete(data.component, undefined) window.webClient.consoleLog(message as string)
})
window.electronMainEvents.setInstallComponentCompleteHandler((_: IpcRendererEvent, data: unknown) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
void window.webClient.onComponentInstallationComplete((data as any).component, undefined)
}) })
window.electronMainEvents.setWatchedDirectoriesChangeHandler((_: IpcRendererEvent, changes: unknown) => { window.electronMainEvents.setWatchedDirectoriesChangeHandler((_: IpcRendererEvent, changes: unknown) => {

View File

@@ -9,4 +9,5 @@ export interface ElectronMainEvents {
setInstallComponentCompleteHandler(handler: MainEventHandler): void setInstallComponentCompleteHandler(handler: MainEventHandler): void
setWatchedDirectoriesChangeHandler(handler: MainEventHandler): void setWatchedDirectoriesChangeHandler(handler: MainEventHandler): void
setHomeServerStartedHandler(handler: MainEventHandler): void setHomeServerStartedHandler(handler: MainEventHandler): void
setConsoleLogHandler(handler: MainEventHandler): void
} }

View File

@@ -5,6 +5,7 @@ export enum MessageToWebApp {
InstallComponentComplete = 'install-component-complete', InstallComponentComplete = 'install-component-complete',
WatchedDirectoriesChanges = 'watched-directories-changes', WatchedDirectoriesChanges = 'watched-directories-changes',
HomeServerStarted = 'home-server-started', HomeServerStarted = 'home-server-started',
ConsoleLog = 'console-log',
} }
export enum MessageToMainProcess { export enum MessageToMainProcess {

View File

@@ -2,6 +2,7 @@
"compilerOptions": { "compilerOptions": {
"target": "ES2019", "target": "ES2019",
"moduleResolution": "node", "moduleResolution": "node",
"module": "es2020",
"types": ["node"], "types": ["node"],
"allowJs": true, "allowJs": true,
"noEmit": false, "noEmit": false,

View File

@@ -18,6 +18,8 @@ export interface DesktopClientRequiresWebMethods {
windowLostFocus(): void windowLostFocus(): void
consoleLog(message: string): void
onComponentInstallationComplete(componentData: DecryptedTransferPayload, error: unknown): Promise<void> onComponentInstallationComplete(componentData: DecryptedTransferPayload, error: unknown): Promise<void>
handleWatchedDirectoriesChanges(changes: DesktopWatchedDirectoriesChanges): Promise<void> handleWatchedDirectoriesChanges(changes: DesktopWatchedDirectoriesChanges): Promise<void>

View File

@@ -1,3 +1,4 @@
export enum InternalFeature { export enum InternalFeature {
Vaults = 'vaults', Vaults = 'vaults',
HomeServer = 'home-server',
} }

View File

@@ -5,9 +5,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
# [3.165.0](https://github.com/standardnotes/app/compare/@standardnotes/web@3.164.3...@standardnotes/web@3.165.0) (2023-07-04) # [3.165.0](https://github.com/standardnotes/app/compare/@standardnotes/web@3.164.3...@standardnotes/web@3.165.0) (2023-07-04)
### Features **Note:** Version bump only for package @standardnotes/web
* New one-click Home Server, now in Labs. Launch your own self-hosted server instance with just 1 click from the Preferences window. ([#2345](https://github.com/standardnotes/app/issues/2345)) ([0552878](https://github.com/standardnotes/app/commit/05528782a4e9684dbd86fd12b77eb86727d6c414))
## [3.164.3](https://github.com/standardnotes/app/compare/@standardnotes/web@3.164.2...@standardnotes/web@3.164.3) (2023-07-04) ## [3.164.3](https://github.com/standardnotes/app/compare/@standardnotes/web@3.164.2...@standardnotes/web@3.164.3) (2023-07-04)

View File

@@ -1,19 +1,5 @@
{ {
"versions": [ "versions": [
{
"version": "3.165.0",
"title": "[3.165.0](https://github.com/standardnotes/app/compare/@standardnotes/web@3.164.3...@standardnotes/web@3.165.0) (2023-07-04)",
"date": null,
"body": "### Features\n\n* New one-click Home Server, now in Labs. Launch your own self-hosted server instance with just 1 click from the Preferences window. ([#2345](https://github.com/standardnotes/app/issues/2345)) ([0552878](https://github.com/standardnotes/app/commit/05528782a4e9684dbd86fd12b77eb86727d6c414))",
"parsed": {
"_": [
"New one-click Home Server, now in Labs. Launch your own self-hosted server instance with just 1 click from the Preferences window. (#2345) (0552878)"
],
"Features": [
"New one-click Home Server, now in Labs. Launch your own self-hosted server instance with just 1 click from the Preferences window. (#2345) (0552878)"
]
}
},
{ {
"version": "3.164.3", "version": "3.164.3",
"title": "[3.164.3](https://github.com/standardnotes/app/compare/@standardnotes/web@3.164.2...@standardnotes/web@3.164.3) (2023-07-04)", "title": "[3.164.3](https://github.com/standardnotes/app/compare/@standardnotes/web@3.164.2...@standardnotes/web@3.164.3) (2023-07-04)",

View File

@@ -4,6 +4,7 @@ import { WebApplicationInterface } from '@standardnotes/ui-services'
export class DevMode { export class DevMode {
constructor(private application: WebApplicationInterface) { constructor(private application: WebApplicationInterface) {
InternalFeatureService.get().enableFeature(InternalFeature.Vaults) InternalFeatureService.get().enableFeature(InternalFeature.Vaults)
InternalFeatureService.get().enableFeature(InternalFeature.HomeServer)
} }
/** Valid only when running a mock event publisher on port 3124 */ /** Valid only when running a mock event publisher on port 3124 */

View File

@@ -176,6 +176,11 @@ export class DesktopManager
} }
} }
consoleLog(message: string): void {
// eslint-disable-next-line no-console
console.log(message)
}
async onComponentInstallationComplete(componentData: DecryptedTransferPayload<ComponentContent>) { async onComponentInstallationComplete(componentData: DecryptedTransferPayload<ComponentContent>) {
const component = this.application.items.findItem(componentData.uuid) const component = this.application.items.findItem(componentData.uuid)
if (!component) { if (!component) {

View File

@@ -5,7 +5,7 @@ import { PackageProvider } from './Panes/General/Advanced/Packages/Provider/Pack
import { securityPrefsHasBubble } from './Panes/Security/securityPrefsHasBubble' import { securityPrefsHasBubble } from './Panes/Security/securityPrefsHasBubble'
import { PreferenceId } from '@standardnotes/ui-services' import { PreferenceId } from '@standardnotes/ui-services'
import { isDesktopApplication } from '@/Utils' import { isDesktopApplication } from '@/Utils'
import { featureTrunkVaultsEnabled } from '@/FeatureTrunk' import { featureTrunkHomeServerEnabled, featureTrunkVaultsEnabled } from '@/FeatureTrunk'
interface PreferencesMenuItem { interface PreferencesMenuItem {
readonly id: PreferenceId readonly id: PreferenceId
@@ -47,9 +47,7 @@ const READY_PREFERENCES_MENU_ITEMS: PreferencesMenuItem[] = [
{ id: 'help-feedback', label: 'Help & feedback', icon: 'help', order: 11 }, { id: 'help-feedback', label: 'Help & feedback', icon: 'help', order: 11 },
] ]
const DESKTOP_PREFERENCES_MENU_ITEMS: PreferencesMenuItem[] = [ const DESKTOP_PREFERENCES_MENU_ITEMS: PreferencesMenuItem[] = []
{ id: 'home-server', label: 'Home Server', icon: 'server', order: 5 },
]
export class PreferencesMenu { export class PreferencesMenu {
private _selectedPane: PreferenceId = 'account' private _selectedPane: PreferenceId = 'account'
@@ -62,6 +60,10 @@ export class PreferencesMenu {
READY_PREFERENCES_MENU_ITEMS.splice(3, 0, { id: 'vaults', label: 'Vaults', icon: 'safe-square', order: 5 }) READY_PREFERENCES_MENU_ITEMS.splice(3, 0, { id: 'vaults', label: 'Vaults', icon: 'safe-square', order: 5 })
} }
if (featureTrunkHomeServerEnabled()) {
DESKTOP_PREFERENCES_MENU_ITEMS.push({ id: 'home-server', label: 'Home Server', icon: 'server', order: 5 })
}
let menuItems = this._enableUnfinishedFeatures ? PREFERENCES_MENU_ITEMS : READY_PREFERENCES_MENU_ITEMS let menuItems = this._enableUnfinishedFeatures ? PREFERENCES_MENU_ITEMS : READY_PREFERENCES_MENU_ITEMS
if (isDesktopApplication()) { if (isDesktopApplication()) {

View File

@@ -11,3 +11,7 @@ export function featureTrunkEnabled(trunk: FeatureTrunkName): boolean {
export function featureTrunkVaultsEnabled(): boolean { export function featureTrunkVaultsEnabled(): boolean {
return InternalFeatureService.get().isFeatureEnabled(InternalFeature.Vaults) return InternalFeatureService.get().isFeatureEnabled(InternalFeature.Vaults)
} }
export function featureTrunkHomeServerEnabled(): boolean {
return InternalFeatureService.get().isFeatureEnabled(InternalFeature.HomeServer)
}