diff options
author | Kristóf Marussy <kristof@marussy.com> | 2021-12-23 00:43:55 +0100 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2021-12-23 01:17:18 +0100 |
commit | cf23e60c17763123caa77f1194e6efd913692ea1 (patch) | |
tree | 42266377ac1a65a9b225737c8cbef02c6b1871cd /packages/main | |
parent | feat: Add mui (diff) | |
download | sophie-cf23e60c17763123caa77f1194e6efd913692ea1.tar.gz sophie-cf23e60c17763123caa77f1194e6efd913692ea1.tar.zst sophie-cf23e60c17763123caa77f1194e6efd913692ea1.zip |
feat: Add shared package for electron ipc
Diffstat (limited to 'packages/main')
-rw-r--r-- | packages/main/package.json | 3 | ||||
-rw-r--r-- | packages/main/src/index.ts | 15 | ||||
-rw-r--r-- | packages/main/tsconfig.json | 6 |
3 files changed, 22 insertions, 2 deletions
diff --git a/packages/main/package.json b/packages/main/package.json index 11a6270..63da432 100644 --- a/packages/main/package.json +++ b/packages/main/package.json | |||
@@ -5,9 +5,10 @@ | |||
5 | "main": "dist/index.cjs", | 5 | "main": "dist/index.cjs", |
6 | "scripts": { | 6 | "scripts": { |
7 | "build": "vite build", | 7 | "build": "vite build", |
8 | "typecheck": "tsc --noEmit" | 8 | "typecheck": "tsc" |
9 | }, | 9 | }, |
10 | "dependencies": { | 10 | "dependencies": { |
11 | "@sophie/shared": "workspace:*", | ||
11 | "electron": "^16.0.5" | 12 | "electron": "^16.0.5" |
12 | }, | 13 | }, |
13 | "devDependencies": { | 14 | "devDependencies": { |
diff --git a/packages/main/src/index.ts b/packages/main/src/index.ts index ef954e1..cd04276 100644 --- a/packages/main/src/index.ts +++ b/packages/main/src/index.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import { app, BrowserWindow } from 'electron'; | 1 | import { app, BrowserWindow } from 'electron'; |
2 | import { join } from 'path'; | 2 | import { join } from 'path'; |
3 | import { RendererIpcMessage } from '@sophie/shared'; | ||
3 | import { URL } from 'url'; | 4 | import { URL } from 'url'; |
4 | 5 | ||
5 | const isSingleInstance = app.requestSingleInstanceLock(); | 6 | const isSingleInstance = app.requestSingleInstanceLock(); |
@@ -49,9 +50,10 @@ function createWindow(): Promise<void> { | |||
49 | } | 50 | } |
50 | }); | 51 | }); |
51 | 52 | ||
53 | const { webContents } = mainWindow; | ||
54 | |||
52 | // See https://github.com/MarshallOfSound/electron-devtools-installer/issues/195#issuecomment-998872878 | 55 | // See https://github.com/MarshallOfSound/electron-devtools-installer/issues/195#issuecomment-998872878 |
53 | if (isDevelopment) { | 56 | if (isDevelopment) { |
54 | const { webContents } = mainWindow; | ||
55 | webContents.once('dom-ready', () => { | 57 | webContents.once('dom-ready', () => { |
56 | webContents.once('devtools-opened', () => { | 58 | webContents.once('devtools-opened', () => { |
57 | mainWindow?.focus(); | 59 | mainWindow?.focus(); |
@@ -64,6 +66,17 @@ function createWindow(): Promise<void> { | |||
64 | mainWindow?.show(); | 66 | mainWindow?.show(); |
65 | }); | 67 | }); |
66 | 68 | ||
69 | webContents.on('ipc-message', (_event, channel, ...args) => { | ||
70 | switch (channel) { | ||
71 | case RendererIpcMessage.ButtonClicked: | ||
72 | console.log('Button clicked'); | ||
73 | break; | ||
74 | default: | ||
75 | console.warn('Unknown IPC message:', channel, args); | ||
76 | break; | ||
77 | } | ||
78 | }); | ||
79 | |||
67 | const pageUrl = (isDevelopment && import.meta.env.VITE_DEV_SERVER_URL !== undefined) | 80 | const pageUrl = (isDevelopment && import.meta.env.VITE_DEV_SERVER_URL !== undefined) |
68 | ? import.meta.env.VITE_DEV_SERVER_URL | 81 | ? import.meta.env.VITE_DEV_SERVER_URL |
69 | : new URL('../renderer/dist/index.html', `file://${__dirname}`).toString(); | 82 | : new URL('../renderer/dist/index.html', `file://${__dirname}`).toString(); |
diff --git a/packages/main/tsconfig.json b/packages/main/tsconfig.json index 1a569d2..970215c 100644 --- a/packages/main/tsconfig.json +++ b/packages/main/tsconfig.json | |||
@@ -1,11 +1,17 @@ | |||
1 | { | 1 | { |
2 | "extends": "../../tsconfig.json", | 2 | "extends": "../../tsconfig.json", |
3 | "compilerOptions": { | 3 | "compilerOptions": { |
4 | "noEmit": true, | ||
4 | "types": [ | 5 | "types": [ |
5 | "node", | 6 | "node", |
6 | "vite/client" | 7 | "vite/client" |
7 | ] | 8 | ] |
8 | }, | 9 | }, |
10 | "references": [ | ||
11 | { | ||
12 | "path": "../shared" | ||
13 | } | ||
14 | ], | ||
9 | "include": [ | 15 | "include": [ |
10 | "src/**/*.ts", | 16 | "src/**/*.ts", |
11 | "types/**/*.d.ts" | 17 | "types/**/*.d.ts" |