Skip to content

Commit ae1abe2

Browse files
committed
feat: add shared api
1 parent 439d14c commit ae1abe2

File tree

5 files changed

+18
-11
lines changed

5 files changed

+18
-11
lines changed

src/app/ipc-main.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { exec } from 'child_process';
22
import { ipcMain } from 'electron';
33
import { promisify } from 'util';
4+
import * as events from '../shared/events';
45
import createLogger from './logger';
56

67
const logger = createLogger('app');
@@ -27,5 +28,5 @@ async function getRequirements(): Promise<
2728
export const registerIPCMainHandlers = (): void => {
2829
logger.info('registerIPCMainHandlers');
2930

30-
ipcMain.handle('get-requirements', getRequirements);
31+
ipcMain.handle(events.TIP_GET_REQUIREMENTS, getRequirements);
3132
};

src/app/preload.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { contextBridge, ipcRenderer } from 'electron';
2+
import { TipManagerAPI } from '../shared/api';
3+
import * as events from '../shared/events';
24

3-
contextBridge.exposeInMainWorld('electronAPI', {
4-
getRequirements: () => ipcRenderer.invoke('get-requirements'),
5-
});
5+
const tipManagerAPI: TipManagerAPI = {
6+
getRequirements: () => ipcRenderer.invoke(events.TIP_GET_REQUIREMENTS),
7+
};
8+
9+
contextBridge.exposeInMainWorld('tipmanager', tipManagerAPI);

src/shared/api.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export interface TipManagerAPI {
2+
getRequirements(): Promise<{ stdout: string; stderr: string }[]>;
3+
}

src/shared/events.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const TIP_GET_REQUIREMENTS = 'TIP_GET_REQUIREMENTS';

src/ui/electron-api/base.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1+
import { TipManagerAPI } from '../../shared/api';
2+
13
declare global {
24
interface Window {
3-
electronAPI: ElectronAPI;
5+
tipmanager: TipManagerAPI;
46
}
57
}
68

7-
export interface ElectronAPI {
8-
getRequirements: () => Promise<{ stdout: string; stderr: string }[]>;
9-
}
10-
119
export class BaseAPI {
12-
private _base: ElectronAPI;
10+
private _base: TipManagerAPI;
1311

1412
get base() {
1513
return this._base;
1614
}
1715

1816
constructor() {
19-
this._base = window.electronAPI;
17+
this._base = window.tipmanager;
2018
}
2119
}

0 commit comments

Comments
 (0)