-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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: deprecate invokers - auto proxying apis - strict types #924
Conversation
861eb67
to
958b272
Compare
492ecab
to
dd2e0f0
Compare
There is no longer a need to handle the
exists: (path: string) => ipcRenderer.invoke('exists', path) // So manual, typo risk
or
exists: (arg1: string, arg2) => ipcRenderer.invoke('exists', arg1, arg2) // So manual, typo risk
ipcMain.handle('exists', async (_event, path: string) => { }) // typo risk
global.core.api?.exists(path) // typo risk, no compile-time check for the `exists` route declaration, e.g., global.core.api?.exist(path) -> app crashes on runtime if someone change the route name in handler / preload / request Now, simply add new routes to export enum FileSystemRoute {
deleteFile = 'deleteFile',
isDirectory = 'isDirectory',
getUserSpace = 'getUserSpace',
// ...new routes go here
// easier to maintain
} Provide handlers for new routes : handler.handle(FileSystemRoute.exists, async (_event, path: string) => { } // no typo risk Make requests from the web app (strict type guard). global.core?.api?.exists(path) // compile error if the route does not exist, no typo risk |
…unctions from the web
3b4aa2f
to
bdd6418
Compare
bdd6418
to
8ed44fa
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
Problem
Maintaining IPC APIs is currently challenging. Every time we need to expose a new API, we find ourselves having to perform the following steps:
preload.ts
with route string names, which involves managing numerous invokers.main.ts
with poorly formatted strings.This situation poses several problems:
preload.ts
should be generated or proxied automatically to reduce code duplication.This PR is to address the concern of @dan-jan about how we can autogenerate
preload.ts
code.To Discuss:
Although this approach would facilitate future updates by eliminating raw string routes and consolidating them in one place (core), there is a risk of overlooking the implementation of newly added routes (handlers). Is there a way to define the Handler/Route as an abstract class so that any implemented class would trigger an error immediately in case of a missing handler implementation?
After refactored the handler logics to /common, could it be proxied automatically instead of adding handler one by one?