Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -4,12 +4,13 @@ import {
HomeServerManagerInterface,
HomeServerEnvironmentConfiguration,
} from '@web/Application/Device/DesktopSnjsExports'
import { HomeServerInterface } from '@standardnotes/home-server'
import { HomeServer, HomeServerInterface } from '@standardnotes/home-server'

import { WebContents } from 'electron'
import { MessageToWebApp } from '../../Shared/IpcMessages'
import { FilesManagerInterface } from '../File/FilesManagerInterface'
import { HomeServerConfigurationFile } from './HomeServerConfigurationFile'
import { isWindows } from '../Types/Platforms'

const os = require('os')

Expand Down Expand Up @@ -126,6 +127,8 @@ export class HomeServerManager implements HomeServerManagerInterface {
}

async startHomeServer(): Promise<string | undefined> {
this.doNotInstantiateHomeServerOnWindowsUntilItIsSupported()

if (!this.homeServer) {
return
}
Expand Down Expand Up @@ -261,4 +264,10 @@ export class HomeServerManager implements HomeServerManagerInterface {

return configuration
}

private doNotInstantiateHomeServerOnWindowsUntilItIsSupported(): void {
if (!isWindows() && !this.homeServer) {
this.homeServer = new HomeServer()
}
}
}
@@ -1,4 +1,3 @@
export enum InternalFeature {
Vaults = 'vaults',
HomeServer = 'home-server',
}
@@ -1,10 +1,38 @@
import { Subtitle, Text, Title } from '@/Components/Preferences/PreferencesComponents/Content'
import { isWindowsPlatform } from '@standardnotes/ui-services'

import { useApplication } from '@/Components/ApplicationProvider'
import { Pill, Subtitle, Text, Title } from '@/Components/Preferences/PreferencesComponents/Content'

import PreferencesPane from '../../PreferencesComponents/PreferencesPane'
import PreferencesGroup from '../../PreferencesComponents/PreferencesGroup'
import PreferencesSegment from '../../PreferencesComponents/PreferencesSegment'
import HomeServerSettings from './HomeServerSettings'

const HomeServer = () => {
const application = useApplication()

if (isWindowsPlatform(application.platform)) {
return (
<PreferencesPane>
<PreferencesGroup>
<PreferencesSegment>
<div className="flex items-center justify-between">
<div className="flex items-start">
<Title>Home Server</Title>
<Pill style={'success'}>Labs</Pill>
</div>
</div>
<div className="flex items-center justify-between">
<div className="mr-10 flex flex-col">
<Subtitle>Windows support for home server is coming soon.</Subtitle>
</div>
</div>
</PreferencesSegment>
</PreferencesGroup>
</PreferencesPane>
)
}

return (
<PreferencesPane>
<PreferencesGroup>
Expand Down
Expand Up @@ -5,7 +5,7 @@ import { PackageProvider } from './Panes/General/Advanced/Packages/Provider/Pack
import { securityPrefsHasBubble } from './Panes/Security/securityPrefsHasBubble'
import { PreferenceId } from '@standardnotes/ui-services'
import { isDesktopApplication } from '@/Utils'
import { featureTrunkHomeServerEnabled, featureTrunkVaultsEnabled } from '@/FeatureTrunk'
import { featureTrunkVaultsEnabled } from '@/FeatureTrunk'

interface PreferencesMenuItem {
readonly id: PreferenceId
Expand Down Expand Up @@ -47,7 +47,9 @@ const READY_PREFERENCES_MENU_ITEMS: PreferencesMenuItem[] = [
{ 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 {
private _selectedPane: PreferenceId = 'account'
Expand All @@ -60,10 +62,6 @@ export class PreferencesMenu {
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

if (isDesktopApplication()) {
Expand All @@ -72,8 +70,6 @@ export class PreferencesMenu {

this._menu = menuItems.sort((a, b) => a.order - b.order)

this._menu = this._enableUnfinishedFeatures ? PREFERENCES_MENU_ITEMS : READY_PREFERENCES_MENU_ITEMS

this.loadLatestVersions()

makeAutoObservable<
Expand Down
4 changes: 0 additions & 4 deletions packages/web/src/javascripts/FeatureTrunk.ts
Expand Up @@ -11,7 +11,3 @@ export function featureTrunkEnabled(trunk: FeatureTrunkName): boolean {
export function featureTrunkVaultsEnabled(): boolean {
return InternalFeatureService.get().isFeatureEnabled(InternalFeature.Vaults)
}

export function featureTrunkHomeServerEnabled(): boolean {
return InternalFeatureService.get().isFeatureEnabled(InternalFeature.HomeServer)
}