rdesktop^2
filip mertens 1 year ago
parent eae0a0f696
commit 946135bde0
  1. 5
      apps/1test/src/electron/fsPlugin.ts
  2. 2
      apps/1test/src/electron/gitPlugin.ts
  3. 13
      apps/1test/src/electron/lib/electronPluginClient.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')
})

@ -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')
})

@ -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<Message>) {
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<Message>) => 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<IRemixApi>
>(client: PluginClient<P, App> = new PluginClient(), IPCName: string): Client<P, App> => {
>(client: PluginClient<P, App> = new PluginClient(), profile: Profile): Client<P, App> => {
const c = client as any
connectClient(new ElectronPluginClientConnector(IPCName), c)
connectClient(new ElectronPluginClientConnector(profile), c)
applyApi(c)
return c
}
Loading…
Cancel
Save