mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-03 07:10:46 +08:00
feat(electron): onboarding at first launch logic for client and web (#5183)
- Added a simple abstraction of persistent storage class.
- Different persistence solutions are provided for web and client.
- web: stored in localStorage
- client: stored in the application directory as `.json` file
- Define persistent app-config schema
- Add a new hook that can interactive with persistent-app-config reactively
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import { initMainWindow } from '../main-window';
|
||||
import {
|
||||
getOnboardingWindow,
|
||||
getOrCreateOnboardingWindow,
|
||||
} from '../onboarding';
|
||||
import { launchStage } from './stage';
|
||||
|
||||
/**
|
||||
* Launch app depending on launch stage
|
||||
*/
|
||||
export function launch() {
|
||||
const stage = launchStage.value;
|
||||
if (stage === 'main') {
|
||||
initMainWindow().catch(e => {
|
||||
console.error('Failed to restore or create window:', e);
|
||||
});
|
||||
|
||||
getOnboardingWindow()
|
||||
.then(w => w?.destroy())
|
||||
.catch(e => console.error('Failed to destroy onboarding window:', e));
|
||||
}
|
||||
if (stage === 'onboarding')
|
||||
getOrCreateOnboardingWindow().catch(e => {
|
||||
console.error('Failed to restore or create onboarding window:', e);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { persistentConfig } from '../config-storage/persist';
|
||||
import type { LaunchStage } from './types';
|
||||
|
||||
export const launchStage: { value: LaunchStage } = {
|
||||
value: persistentConfig.get('onBoarding') ? 'onboarding' : 'main',
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
export type LaunchStage = 'main' | 'onboarding';
|
||||
@@ -0,0 +1,9 @@
|
||||
import type { BrowserWindow } from 'electron';
|
||||
|
||||
import type { LaunchStage } from './types';
|
||||
|
||||
export const windows$: Record<LaunchStage, Promise<BrowserWindow> | undefined> =
|
||||
{
|
||||
main: undefined,
|
||||
onboarding: undefined,
|
||||
};
|
||||
Reference in New Issue
Block a user