From 6778a113f8ee632b5a5353e97759d2264d6409fc Mon Sep 17 00:00:00 2001 From: filip mertens Date: Thu, 1 Jun 2023 10:47:55 +0200 Subject: [PATCH] refactor --- apps/1test/src/electron/fsPlugin.ts | 7 ++++--- apps/1test/src/electron/gitPlugin.ts | 2 +- apps/1test/src/electron/lib/electronPluginClient.ts | 13 ++++++------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/apps/1test/src/electron/fsPlugin.ts b/apps/1test/src/electron/fsPlugin.ts index f04db0a904..5355a1479a 100644 --- a/apps/1test/src/electron/fsPlugin.ts +++ b/apps/1test/src/electron/fsPlugin.ts @@ -3,8 +3,9 @@ import { createClient } from "./lib/electronPluginClient" import { Plugin } from '@remixproject/engine'; import fs from 'fs/promises' import { Stats } from "fs"; +import { Profile } from "@remixproject/plugin-utils"; -const profile = { +const profile: Profile = { displayName: 'fs', name: 'fs', description: 'fs', @@ -26,7 +27,7 @@ class FSPluginClient extends PluginClient { constructor(){ super() this.methods = ['readdir', 'readFile', 'writeFile', 'mkdir', 'rmdir', 'unlink', 'rename', 'stat', 'exists'] - createClient(this, 'fs') + createClient(this, profile) this.onload(() => { console.log('fsPluginClient onload') }) @@ -68,7 +69,7 @@ class FSPluginClient extends PluginClient { async exists(path: string): Promise { return fs.access(path).then(() => true).catch(() => false) } - + } \ No newline at end of file diff --git a/apps/1test/src/electron/gitPlugin.ts b/apps/1test/src/electron/gitPlugin.ts index ea4ab2510a..5cc8ed3fd5 100644 --- a/apps/1test/src/electron/gitPlugin.ts +++ b/apps/1test/src/electron/gitPlugin.ts @@ -26,7 +26,7 @@ class GitPluginClient extends PluginClient { constructor() { super() this.methods = ['log', 'status', 'add', 'commit', 'push', 'pull', 'clone', 'checkout', 'branch', 'merge', 'reset', 'revert', 'diff', 'stash', 'apply', 'cherryPick', 'rebase', 'tag', 'fetch', 'remote', 'config', 'show', 'init', 'help', 'version'] - createClient(this, 'git') + createClient(this, profile) this.onload(() => { console.log('GitPluginClient onload') }) diff --git a/apps/1test/src/electron/lib/electronPluginClient.ts b/apps/1test/src/electron/lib/electronPluginClient.ts index 1df3c35c53..ef0670878e 100644 --- a/apps/1test/src/electron/lib/electronPluginClient.ts +++ b/apps/1test/src/electron/lib/electronPluginClient.ts @@ -1,23 +1,22 @@ import { ClientConnector, connectClient, applyApi, Client, PluginClient } from '@remixproject/plugin' -import type { Message, Api, ApiMap } from '@remixproject/plugin-utils' +import type { Message, Api, ApiMap, Profile } from '@remixproject/plugin-utils' import { IRemixApi } from '@remixproject/plugin-api' import { ipcMain } from 'electron' import { mainWindow } from '../..' export class ElectronPluginClientConnector implements ClientConnector { - constructor(public IPCName: string) { + constructor(public profile: Profile) { } - /** Send a message to the engine */ send(message: Partial) { - mainWindow.webContents.send(this.IPCName + ':send', message) + mainWindow.webContents.send(this.profile.name + ':send', message) } /** Listen to message from the engine */ on(cb: (message: Partial) => void) { - ipcMain.on(this.IPCName + ':on', (event, message) => { + ipcMain.on(this.profile.name + ':on', (event, message) => { cb(message) }) } @@ -26,9 +25,9 @@ export class ElectronPluginClientConnector implements ClientConnector { export const createClient = < P extends Api, App extends ApiMap = Readonly ->(client: PluginClient = new PluginClient(), IPCName: string): Client => { +>(client: PluginClient = new PluginClient(), profile: Profile): Client => { const c = client as any - connectClient(new ElectronPluginClientConnector(IPCName), c) + connectClient(new ElectronPluginClientConnector(profile), c) applyApi(c) return c } \ No newline at end of file