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:
Cats Juice
2023-12-19 07:17:54 +00:00
parent e0d328676d
commit 15dd20ef48
32 changed files with 470 additions and 29 deletions

View File

@@ -5,7 +5,7 @@ import path, { resolve } from 'node:path';
import process from 'node:process';
import type { Workspace } from '@blocksuite/store';
import { test as baseTest } from '@playwright/test';
import { type BrowserContext, test as baseTest } from '@playwright/test';
export const rootDir = resolve(__dirname, '..', '..');
// assert that the rootDir is the root of the project
@@ -32,6 +32,12 @@ type CurrentWorkspace = {
blockSuiteWorkspace: Workspace;
};
export const skipOnboarding = async (context: BrowserContext) => {
await context.addInitScript(() => {
window.localStorage.setItem('app_config', '{"onBoarding":false}');
});
};
export const test = baseTest.extend<{
workspace: {
current: () => Promise<CurrentWorkspace>;
@@ -59,6 +65,9 @@ export const test = baseTest.extend<{
});
},
context: async ({ context }, use) => {
// workaround for skipping onboarding redirect on the web
await skipOnboarding(context);
if (enableCoverage) {
await context.addInitScript(() =>
window.addEventListener('beforeunload', () =>