Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "remix-plugin",
"version": "0.3.37",
"version": "0.3.43",
"license": "MIT",
"scripts": {
"nx": "nx",
Expand Down
2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@remixproject/plugin-api",
"version": "0.3.37",
"version": "0.3.43",
"homepage": "https://github.com/ethereum/remix-plugin/tree/master/packages/api#readme",
"repository": {
"type": "git",
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/lib/dgit/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface IDgitSystem {
commit(cmd: any): string;
status(cmd: any): any[];
rm(cmd: any): string;
reset(cmd: any): string;
log(cmd: any): any[];
lsfiles(cmd: any): any[];
readblob(cmd: any): { oid: string, blob: Uint8Array }
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/lib/dgit/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import { LibraryProfile } from '@remixproject/plugin-utils'

export const dGitProfile: LibraryProfile<IDgitSystem> = {
name: 'dGitProvider',
methods: ['clone', 'addremote', 'delremote', 'remotes', 'init', 'status', 'log', 'commit', 'add', 'rm', 'lsfiles', 'readblob', 'resolveref', 'branch', 'branches','checkout','currentbranch', 'zip', 'push', 'pull', 'setIpfsConfig','getItem','setItem', 'localStorageUsed']
methods: ['clone', 'addremote', 'delremote', 'remotes', 'init', 'status', 'log', 'commit', 'add', 'reset', 'rm', 'lsfiles', 'readblob', 'resolveref', 'branch', 'branches','checkout','currentbranch', 'zip', 'push', 'pull', 'setIpfsConfig','getItem','setItem', 'localStorageUsed']
}
2 changes: 1 addition & 1 deletion packages/engine/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@remixproject/engine",
"version": "0.3.37",
"version": "0.3.43",
"homepage": "https://github.com/ethereum/remix-plugin/tree/master/packages/engine/core#readme",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/engine/electron/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@remixproject/engine-electron",
"version": "0.3.37",
"version": "0.3.43",
"homepage": "https://github.com/ethereum/remix-plugin/tree/master/packages/engine/node#readme",
"repository": {
"type": "git",
Expand Down
187 changes: 110 additions & 77 deletions packages/engine/electron/src/lib/electronPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,175 +1,208 @@
import type { Profile, Message } from '@remixproject/plugin-utils'
import type { Profile, Message } from '@remixproject/plugin-utils';
import { Plugin } from '@remixproject/engine';
import { EventEmitter } from 'events';

export abstract class ElectronPlugin extends Plugin {
protected loaded: boolean
protected id = 0
protected pendingRequest: Record<number, (result: any, error: Error | string) => void> = {}
protected loaded: boolean;
protected connected: boolean;
public events = new EventEmitter();
protected id = 0;
protected pendingRequest: Record<
number,
(result: any, error: Error | string) => void
> = {};
protected api: {
send: (message: Partial<Message>) => void
on: (cb: (event: any, message: any) => void) => void
}
send: (message: Partial<Message>) => void;
on: (cb: (event: any, message: any) => void) => void;
};

profile: Profile
profile: Profile;
constructor(profile: Profile) {
super(profile)
this.loaded = false
super(profile);
this.loaded = false;
this.connected = false;

if(!window.electronAPI) throw new Error('ElectronPluginConnector requires window.api')
if(!window.electronAPI.plugins) throw new Error('ElectronPluginConnector requires window.api.plugins')
if (!window.electronAPI)
throw new Error('ElectronPluginConnector requires window.api');
if (!window.electronAPI.plugins)
throw new Error('ElectronPluginConnector requires window.api.plugins');

window.electronAPI.plugins.find((plugin: any) => {
if(plugin.name === profile.name){
this.api = plugin
return true
if (plugin.name === profile.name) {
this.api = plugin;
return true;
}
})
});

if(!this.api) throw new Error(`ElectronPluginConnector requires window.api.plugins.${profile.name} to be defined in preload.ts`)
if (!this.api)
throw new Error(
`ElectronPluginConnector requires window.api.plugins.${profile.name} to be defined in preload.ts`
);

this.api.on((event: any, message: any) => {
this.getMessage(message)
})


this.getMessage(message);
});
}

/**
* Send a message to the external plugin
* @param message the message passed to the plugin
*/
protected send(message: Partial<Message>): void {
if(this.loaded)
this.api.send(message)
if (this.loaded) this.api.send(message);
}
/**
* Open connection with the plugin
* @param name The name of the plugin should connect to
*/
protected async connect(name: string) {
const connected = await window.electronAPI.activatePlugin(name)
if(connected && !this.loaded){
this.handshake()
const connected = await window.electronAPI.activatePlugin(name);
if (connected && !this.loaded) {
this.handshake();
}

}
/** Close connection with the plugin */
protected disconnect(): any | Promise<any> {
// TODO: Disconnect from the plugin
}

async activate() {
await this.connect(this.profile.name)
return super.activate()
await this.connect(this.profile.name);
return super.activate();
}

async deactivate() {
this.loaded = false
await this.disconnect()
return super.deactivate()
this.loaded = false;
await this.disconnect();
return super.deactivate();
}

/** Call a method from this plugin */
protected callPluginMethod(key: string, payload: any[] = []): Promise<any> {
const action = 'request'
const id = this.id++
const requestInfo = this.currentRequest
const name = this.name
const action = 'request';
const id = this.id++;
const requestInfo = this.currentRequest;
const name = this.name;
const promise = new Promise((res, rej) => {
this.pendingRequest[id] = (result: any[], error: Error | string) => error ? rej (error) : res(result)
})
this.send({ id, action, key, payload, requestInfo, name })
return promise
this.pendingRequest[id] = (result: any[], error: Error | string) =>
error ? rej(error) : res(result);
});
this.send({ id, action, key, payload, requestInfo, name });
return promise;
}

/** Perform handshake with the client if not loaded yet */
protected async handshake() {
if (!this.loaded) {
this.loaded = true
this.loaded = true;
let methods: string[];
try {
methods = await this.callPluginMethod('handshake', [this.profile.name])
methods = await this.callPluginMethod('handshake', [this.profile.name]);
} catch (err) {
this.loaded = false
this.loaded = false;
throw err;
}
this.emit('loaded', this.name)

if (methods) {
this.profile.methods = methods
this.call('manager', 'updateProfile', this.profile)
this.profile.methods = methods;
await this.call('manager', 'updateProfile', this.profile);
}
this.connected = true;
this.events.emit('connected');
this.emit('loaded', this.name);
} else {
// If there is a broken connection we want send back the handshake to the plugin client
return this.callPluginMethod('handshake', [this.profile.name])
return this.callPluginMethod('handshake', [this.profile.name]);
}
}

// Wait until this connection is settled
public onConnect(cb?: () => void): Promise<void> {
return new Promise((res, rej) => {
const loadFn = () => {
res();
if (cb) cb();
};
this.connected ? loadFn() : this.events.once('connected', () => loadFn());
});
}

/**
* React when a message comes from client
* @param message The message sent by the client
*/
protected async getMessage(message: Message) {
// Check for handshake request from the client
if (message.action === 'request' && message.key === 'handshake') {
return this.handshake()
return this.handshake();
}

switch (message.action) {
// Start listening on an event
case 'on':
case 'listen': {
const { name, key } = message
const action = 'notification'
this.on(name, key, (...payload: any[]) => this.send({ action, name, key, payload }))
break
const { name, key } = message;
const action = 'notification';
this.on(name, key, (...payload: any[]) =>
this.send({ action, name, key, payload })
);
break;
}
case 'off': {
const { name, key } = message
this.off(name, key)
break
const { name, key } = message;
this.off(name, key);
break;
}
case 'once': {
const { name, key } = message
const action = 'notification'
this.once(name, key, (...payload: any) => this.send({ action, name, key, payload }))
break
const { name, key } = message;
const action = 'notification';
this.once(name, key, (...payload: any) =>
this.send({ action, name, key, payload })
);
break;
}
// Emit an event
case 'emit':
case 'notification': {
if (!message.payload) break
this.emit(message.key, ...message.payload)
break
if (!message.payload) break;
this.emit(message.key, ...message.payload);
break;
}
// Call a method
case 'call':
case 'request': {
const action = 'response'
const action = 'response';
try {
const payload = await this.call(message.name, message.key, ...message.payload)
const error: any = undefined
this.send({ ...message, action, payload, error })
const payload = await this.call(
message.name,
message.key,
...message.payload
);
const error: any = undefined;
this.send({ ...message, action, payload, error });
} catch (err) {
const payload: any = undefined
const error = err.message || err
this.send({ ...message, action, payload, error })
const payload: any = undefined;
const error = err.message || err;
this.send({ ...message, action, payload, error });
}
break
break;
}
case 'cancel': {
const payload = this.cancel(message.name, message.key)
const payload = this.cancel(message.name, message.key);
break;
}
// Return result from exposed method
case 'response': {
const { id, payload, error } = message
this.pendingRequest[id](payload, error)
delete this.pendingRequest[id]
break
const { id, payload, error } = message;
this.pendingRequest[id](payload, error);
delete this.pendingRequest[id];
break;
}
default: {
throw new Error('Message should be a notification, request or response')
throw new Error(
'Message should be a notification, request or response'
);
}
}
}
}
}
2 changes: 1 addition & 1 deletion packages/engine/node/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@remixproject/engine-node",
"version": "0.3.37",
"version": "0.3.43",
"homepage": "https://github.com/ethereum/remix-plugin/tree/master/packages/engine/node#readme",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/engine/theia/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "@remixproject/engine-theia",
"version": "0.3.37"
"version": "0.3.43"
}
2 changes: 1 addition & 1 deletion packages/engine/vscode/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@remixproject/engine-vscode",
"version": "0.3.37",
"version": "0.3.43",
"homepage": "https://github.com/ethereum/remix-plugin/tree/master/packages/engine/vscode#readme",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/engine/web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@remixproject/engine-web",
"version": "0.3.37",
"version": "0.3.43",
"homepage": "https://github.com/ethereum/remix-plugin/tree/master/packages/engine/web#readme",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin/child-process/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@remixproject/plugin-child-process",
"version": "0.3.37",
"version": "0.3.43",
"homepage": "https://github.com/ethereum/remix-plugin/tree/master/packages/plugin/child_process#readme",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@remixproject/plugin",
"version": "0.3.37",
"version": "0.3.43",
"dependencies": {
"events": "3.2.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin/electron/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@remixproject/plugin-electron",
"version": "0.3.37",
"version": "0.3.43",
"homepage": "https://github.com/ethereum/remix-plugin/tree/master/packages/plugin/iframe#readme",
"repository": {
"type": "git",
Expand Down
Loading