refactor(electron): create electron api package (#5334)

This commit is contained in:
EYHN
2023-12-27 06:38:37 +00:00
parent ce17daba42
commit 4e861d8118
53 changed files with 307 additions and 690 deletions

View File

@@ -3,6 +3,7 @@ import {
resolveGlobalLoadingEventAtom,
} from '@affine/component/global-loading';
import { pushNotificationAtom } from '@affine/component/notification-center';
import { apis } from '@affine/electron-api';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import {
HtmlTransformer,
@@ -49,7 +50,7 @@ async function exportHandler({ page, type }: ExportHandlerOptions) {
break;
case 'pdf':
if (environment.isDesktop && page.meta.mode === 'page') {
await window.apis?.export.savePDFFileAs(
await apis?.export.savePDFFileAs(
(page.root as PageBlockModel).title.toString()
);
} else {

View File

@@ -1,3 +1,5 @@
import { apis } from '@affine/electron-api';
import { assertExists } from '@blocksuite/global/utils';
import {
type AppConfigSchema,
AppConfigStorage,
@@ -13,11 +15,13 @@ class AppConfigProxy {
value: AppConfigSchema = defaultAppConfig;
async getSync(): Promise<AppConfigSchema> {
return (this.value = await window.apis.configStorage.get());
assertExists(apis);
return (this.value = await apis.configStorage.get());
}
async setSync(): Promise<void> {
await window.apis.configStorage.set(this.value);
assertExists(apis);
await apis.configStorage.set(this.value);
}
get(): AppConfigSchema {