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

refactor: import ipc objects from main & preload #33

Merged
merged 4 commits into from
Nov 6, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions apps/example-reducers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@
"dependencies": {
"react": "^18.3.1",
"react-dom": "^18.3.1",
"zustand": "^5.0.0",
"zustand": "^5.0.1",
"zutron": "workspace:*"
},
"devDependencies": {
"@types/node": "^22.7.5",
"@types/react": "^18.3.11",
"@types/node": "^22.9.0",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@vitejs/plugin-react": "^4.3.2",
"electron": "^32.1.2",
"@vitejs/plugin-react": "^4.3.3",
"electron": "^33.1.0",
"electron-builder": "^25.1.8",
"electron-vite": "^2.3.0",
"typescript": "^5.6.3",
"vite": "^5.4.9",
"wdio-electron-service": "^7.1.0"
"vite": "^5.4.10",
"wdio-electron-service": "^7.2.0"
}
}
4 changes: 2 additions & 2 deletions apps/example-reducers/src/main/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'node:path';
import { BrowserWindow, type BrowserWindowConstructorOptions, app, ipcMain } from 'electron';
import { BrowserWindow, type BrowserWindowConstructorOptions, app } from 'electron';

import { mainZustandBridge } from 'zutron/main';
import 'wdio-electron-service/main';
Expand Down Expand Up @@ -72,7 +72,7 @@ app
// Set the badge count to the current counter value
store.subscribe((state) => app.setBadgeCount(state.counter ?? 0));

const { unsubscribe } = mainZustandBridge(ipcMain, store, [mainWindow], {
const { unsubscribe } = mainZustandBridge(store, [mainWindow], {
reducer: rootReducer,
});

Expand Down
4 changes: 2 additions & 2 deletions apps/example-reducers/src/preload/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { contextBridge, ipcRenderer } from 'electron';
import { contextBridge } from 'electron';

import { preloadZustandBridge } from 'zutron/preload';
import 'wdio-electron-service/preload';
import type { Handlers } from 'zutron';

import type { State } from '../features/index.js';

export const { handlers } = preloadZustandBridge<State>(ipcRenderer);
export const { handlers } = preloadZustandBridge<State>();

contextBridge.exposeInMainWorld('zutron', handlers);

Expand Down
14 changes: 7 additions & 7 deletions apps/example-separate-handlers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@
"dependencies": {
"react": "^18.3.1",
"react-dom": "^18.3.1",
"zustand": "^5.0.0",
"zustand": "^5.0.1",
"zutron": "workspace:*"
},
"devDependencies": {
"@types/node": "^22.7.5",
"@types/react": "^18.3.11",
"@types/node": "^22.9.0",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@vitejs/plugin-react": "^4.3.2",
"electron": "^32.1.2",
"@vitejs/plugin-react": "^4.3.3",
"electron": "^33.1.0",
"electron-builder": "^25.1.8",
"electron-vite": "^2.3.0",
"typescript": "^5.6.3",
"vite": "^5.4.9",
"wdio-electron-service": "^7.1.0"
"vite": "^5.4.10",
"wdio-electron-service": "^7.2.0"
}
}
4 changes: 2 additions & 2 deletions apps/example-separate-handlers/src/main/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'node:path';

import { BrowserWindow, type BrowserWindowConstructorOptions, app, ipcMain } from 'electron';
import { BrowserWindow, type BrowserWindowConstructorOptions, app } from 'electron';
import { mainZustandBridge } from 'zutron/main';
import 'wdio-electron-service/main';

Expand Down Expand Up @@ -73,7 +73,7 @@ app
// Set the badge count to the current counter value
store.subscribe((state) => app.setBadgeCount(state.counter ?? 0));

const { unsubscribe } = mainZustandBridge(ipcMain, store, [mainWindow], {
const { unsubscribe } = mainZustandBridge(store, [mainWindow], {
handlers,
});

Expand Down
4 changes: 2 additions & 2 deletions apps/example-separate-handlers/src/preload/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { contextBridge, ipcRenderer } from 'electron';
import { contextBridge } from 'electron';
import { preloadZustandBridge } from 'zutron/preload';
import 'wdio-electron-service/preload';
import type { Handlers } from 'zutron';

import type { State } from '../features/index.js';

export const { handlers } = preloadZustandBridge<State>(ipcRenderer);
export const { handlers } = preloadZustandBridge<State>();

contextBridge.exposeInMainWorld('zutron', handlers);

Expand Down
14 changes: 7 additions & 7 deletions apps/example-store-handlers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@
"dependencies": {
"react": "^18.3.1",
"react-dom": "^18.3.1",
"zustand": "^5.0.0",
"zustand": "^5.0.1",
"zutron": "workspace:*"
},
"devDependencies": {
"@types/node": "^22.7.5",
"@types/react": "^18.3.11",
"@types/node": "^22.9.0",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@vitejs/plugin-react": "^4.3.2",
"electron": "^32.1.2",
"@vitejs/plugin-react": "^4.3.3",
"electron": "^33.1.0",
"electron-builder": "^25.1.8",
"electron-vite": "^2.3.0",
"typescript": "^5.6.3",
"vite": "^5.4.9",
"wdio-electron-service": "^7.1.0"
"vite": "^5.4.10",
"wdio-electron-service": "^7.2.0"
}
}
4 changes: 2 additions & 2 deletions apps/example-store-handlers/src/main/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'node:path';

import { BrowserWindow, type BrowserWindowConstructorOptions, app, ipcMain } from 'electron';
import { BrowserWindow, type BrowserWindowConstructorOptions, app } from 'electron';
import { mainZustandBridge } from 'zutron/main';
import 'wdio-electron-service/main';

Expand Down Expand Up @@ -71,7 +71,7 @@ app
// Set the badge count to the current counter value
store.subscribe((state) => app.setBadgeCount(state.counter ?? 0));

const { unsubscribe } = mainZustandBridge(ipcMain, store, [mainWindow]);
const { unsubscribe } = mainZustandBridge(store, [mainWindow]);

app.on('quit', () => {
tray.destroy();
Expand Down
4 changes: 2 additions & 2 deletions apps/example-store-handlers/src/preload/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { contextBridge, ipcRenderer } from 'electron';
import { contextBridge } from 'electron';
import { preloadZustandBridge } from 'zutron/preload';
import 'wdio-electron-service/preload';
import type { Handlers } from 'zutron';

import type { State } from '../features/index.js';

export const { handlers } = preloadZustandBridge<State>(ipcRenderer);
export const { handlers } = preloadZustandBridge<State>();

contextBridge.exposeInMainWorld('zutron', handlers);

Expand Down
20 changes: 10 additions & 10 deletions e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@
},
"dependencies": {
"@testing-library/webdriverio": "^3.2.1",
"@wdio/cli": "^9.2.1",
"@wdio/electron-utils": "^7.1.0",
"@wdio/globals": "^9.2.1",
"@wdio/local-runner": "^9.2.1",
"@wdio/mocha-framework": "^9.1.3",
"@wdio/cli": "^9.2.10",
"@wdio/electron-utils": "^7.2.0",
"@wdio/globals": "^9.2.8",
"@wdio/local-runner": "^9.2.8",
"@wdio/mocha-framework": "^9.2.8",
"cross-env": "^7.0.3",
"tsx": "^4.19.1",
"wdio-electron-service": "^7.1.0",
"webdriverio": "^9.2.1",
"tsx": "^4.19.2",
"wdio-electron-service": "^7.2.0",
"webdriverio": "^9.2.8",
"xvfb-maybe": "^0.2.1"
},
"devDependencies": {
"@types/mocha": "^10.0.9",
"@types/node": "^22.7.5",
"electron": "^32.1.2",
"@types/node": "^22.9.0",
"electron": "^33.1.0",
"read-package-up": "^11.0.0",
"typescript": "^5.6.3"
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"lint-staged": "^15.2.10",
"prettier": "^3.3.3",
"shelljs": "^0.8.5",
"tsx": "^4.19.1",
"turbo": "^2.1.3"
"tsx": "^4.19.2",
"turbo": "^2.2.3"
},
"lint-staged": {
"**/*.{yml,json,md,ts,tsx,js}": [
Expand Down
10 changes: 5 additions & 5 deletions packages/zutron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,17 @@
}
},
"devDependencies": {
"@testing-library/jest-dom": "^6.5.0",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.0.1",
"@types/shelljs": "^0.8.15",
"@vitest/coverage-v8": "^2.1.3",
"@vitest/coverage-v8": "^2.1.4",
"jsdom": "^25.0.1",
"react": "^18.3.1",
"rollup": "^4.24.0",
"rollup": "^4.24.4",
"shelljs": "^0.8.5",
"tsx": "^4.19.1",
"tsx": "^4.19.2",
"typescript": "^5.6.3",
"vitest": "^2.1.3"
"vitest": "^2.1.4"
},
"files": [
"dist/*",
Expand Down
5 changes: 2 additions & 3 deletions packages/zutron/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import type { BrowserWindow, IpcMain, IpcMainEvent } from 'electron';
import { type BrowserWindow, ipcMain, type IpcMainEvent } from 'electron';
import type { StoreApi } from 'zustand';

import type { Action, AnyState, Handler, MainZustandBridgeOpts, Thunk } from './index.js';

export type MainZustandBridge = <State extends AnyState, Store extends StoreApi<State>>(
ipcMain: IpcMain,
store: Store,
windows: BrowserWindow[],
options?: MainZustandBridgeOpts<State>,
Expand Down Expand Up @@ -52,7 +51,7 @@ export const createDispatch =
}
};

export const mainZustandBridge: MainZustandBridge = (ipcMain, store, windows, options) => {
export const mainZustandBridge: MainZustandBridge = (store, windows, options) => {
const dispatch = createDispatch(store, options);
ipcMain.on('subscribe', async (state: unknown) => {
for (const window of windows) {
Expand Down
4 changes: 2 additions & 2 deletions packages/zutron/src/preload.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { IpcRenderer } from 'electron';
import { ipcRenderer } from 'electron';

import type { AnyState, PreloadZustandBridgeReturn } from './index.js';

export const preloadZustandBridge = <S extends AnyState>(ipcRenderer: IpcRenderer): PreloadZustandBridgeReturn<S> => ({
export const preloadZustandBridge = <S extends AnyState>(): PreloadZustandBridgeReturn<S> => ({
handlers: {
dispatch: (...args) => ipcRenderer.send('dispatch', ...args),
getState: () => ipcRenderer.invoke('getState'),
Expand Down
Loading