rdesktop
filip mertens 1 year ago
parent 87f65eeba7
commit 6778a113f8
  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 { Plugin } from '@remixproject/engine';
import fs from 'fs/promises' import fs from 'fs/promises'
import { Stats } from "fs"; import { Stats } from "fs";
import { Profile } from "@remixproject/plugin-utils";
const profile = { const profile: Profile = {
displayName: 'fs', displayName: 'fs',
name: 'fs', name: 'fs',
description: 'fs', description: 'fs',
@ -26,7 +27,7 @@ class FSPluginClient extends PluginClient {
constructor(){ constructor(){
super() super()
this.methods = ['readdir', 'readFile', 'writeFile', 'mkdir', 'rmdir', 'unlink', 'rename', 'stat', 'exists'] this.methods = ['readdir', 'readFile', 'writeFile', 'mkdir', 'rmdir', 'unlink', 'rename', 'stat', 'exists']
createClient(this, 'fs') createClient(this, profile)
this.onload(() => { this.onload(() => {
console.log('fsPluginClient onload') console.log('fsPluginClient onload')
}) })

@ -26,7 +26,7 @@ class GitPluginClient extends PluginClient {
constructor() { constructor() {
super() 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'] 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(() => { this.onload(() => {
console.log('GitPluginClient onload') console.log('GitPluginClient onload')
}) })

@ -1,23 +1,22 @@
import { ClientConnector, connectClient, applyApi, Client, PluginClient } from '@remixproject/plugin' 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 { IRemixApi } from '@remixproject/plugin-api'
import { ipcMain } from 'electron' import { ipcMain } from 'electron'
import { mainWindow } from '../..' import { mainWindow } from '../..'
export class ElectronPluginClientConnector implements ClientConnector { export class ElectronPluginClientConnector implements ClientConnector {
constructor(public IPCName: string) { constructor(public profile: Profile) {
} }
/** Send a message to the engine */ /** Send a message to the engine */
send(message: Partial<Message>) { 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 */ /** Listen to message from the engine */
on(cb: (message: Partial<Message>) => void) { on(cb: (message: Partial<Message>) => void) {
ipcMain.on(this.IPCName + ':on', (event, message) => { ipcMain.on(this.profile.name + ':on', (event, message) => {
cb(message) cb(message)
}) })
} }
@ -26,9 +25,9 @@ export class ElectronPluginClientConnector implements ClientConnector {
export const createClient = < export const createClient = <
P extends Api, P extends Api,
App extends ApiMap = Readonly<IRemixApi> 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 const c = client as any
connectClient(new ElectronPluginClientConnector(IPCName), c) connectClient(new ElectronPluginClientConnector(profile), c)
applyApi(c) applyApi(c)
return c return c
} }
Loading…
Cancel
Save