diff --git a/package.json b/package.json index e5d82ea0..971c7ef1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "remix-plugin", - "version": "0.3.37", + "version": "0.3.43", "license": "MIT", "scripts": { "nx": "nx", diff --git a/packages/api/package.json b/packages/api/package.json index 224edc7e..185bba15 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -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", diff --git a/packages/api/src/lib/dgit/api.ts b/packages/api/src/lib/dgit/api.ts index 5e4e4c1f..24acf29a 100644 --- a/packages/api/src/lib/dgit/api.ts +++ b/packages/api/src/lib/dgit/api.ts @@ -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 } diff --git a/packages/api/src/lib/dgit/profile.ts b/packages/api/src/lib/dgit/profile.ts index 477692f9..d463eda3 100644 --- a/packages/api/src/lib/dgit/profile.ts +++ b/packages/api/src/lib/dgit/profile.ts @@ -3,5 +3,5 @@ import { LibraryProfile } from '@remixproject/plugin-utils' export const dGitProfile: LibraryProfile = { 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'] } diff --git a/packages/engine/core/package.json b/packages/engine/core/package.json index 7078f545..4b991849 100644 --- a/packages/engine/core/package.json +++ b/packages/engine/core/package.json @@ -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", diff --git a/packages/engine/electron/package.json b/packages/engine/electron/package.json index 7cc4864f..069da5c8 100644 --- a/packages/engine/electron/package.json +++ b/packages/engine/electron/package.json @@ -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", diff --git a/packages/engine/electron/src/lib/electronPlugin.ts b/packages/engine/electron/src/lib/electronPlugin.ts index 2bdfa065..0441e4f0 100644 --- a/packages/engine/electron/src/lib/electronPlugin.ts +++ b/packages/engine/electron/src/lib/electronPlugin.ts @@ -1,37 +1,47 @@ -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 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) => void - on: (cb: (event: any, message: any) => void) => void - } + send: (message: Partial) => 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); + }); } /** @@ -39,19 +49,17 @@ export abstract class ElectronPlugin extends Plugin { * @param message the message passed to the plugin */ protected send(message: Partial): 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 { @@ -59,51 +67,66 @@ export abstract class ElectronPlugin extends 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 { - 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 { + 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 @@ -111,65 +134,75 @@ export abstract class ElectronPlugin extends Plugin { 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' + ); } } } -} \ No newline at end of file +} diff --git a/packages/engine/node/package.json b/packages/engine/node/package.json index 682a260d..db8a4615 100644 --- a/packages/engine/node/package.json +++ b/packages/engine/node/package.json @@ -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", diff --git a/packages/engine/theia/package.json b/packages/engine/theia/package.json index e557461a..f35c92ac 100644 --- a/packages/engine/theia/package.json +++ b/packages/engine/theia/package.json @@ -1,4 +1,4 @@ { "name": "@remixproject/engine-theia", - "version": "0.3.37" + "version": "0.3.43" } diff --git a/packages/engine/vscode/package.json b/packages/engine/vscode/package.json index 6099be1c..783f30fe 100644 --- a/packages/engine/vscode/package.json +++ b/packages/engine/vscode/package.json @@ -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", diff --git a/packages/engine/web/package.json b/packages/engine/web/package.json index 8ebb4e6e..cac3ae08 100644 --- a/packages/engine/web/package.json +++ b/packages/engine/web/package.json @@ -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", diff --git a/packages/plugin/child-process/package.json b/packages/plugin/child-process/package.json index ad26c405..1ae98f9f 100644 --- a/packages/plugin/child-process/package.json +++ b/packages/plugin/child-process/package.json @@ -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", diff --git a/packages/plugin/core/package.json b/packages/plugin/core/package.json index d9e01dca..d9f4cae6 100644 --- a/packages/plugin/core/package.json +++ b/packages/plugin/core/package.json @@ -1,6 +1,6 @@ { "name": "@remixproject/plugin", - "version": "0.3.37", + "version": "0.3.43", "dependencies": { "events": "3.2.0" }, diff --git a/packages/plugin/electron/package.json b/packages/plugin/electron/package.json index c21eeeb7..777e51f4 100644 --- a/packages/plugin/electron/package.json +++ b/packages/plugin/electron/package.json @@ -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", diff --git a/packages/plugin/electron/src/lib/electronPluginClient.ts b/packages/plugin/electron/src/lib/electronPluginClient.ts index f50ff0e8..a51274fd 100644 --- a/packages/plugin/electron/src/lib/electronPluginClient.ts +++ b/packages/plugin/electron/src/lib/electronPluginClient.ts @@ -10,7 +10,12 @@ export class ElectronPluginClientConnector implements ClientConnector { /** Send a message to the engine */ send(message: Partial) { - this.browserWindow.webContents.send(this.profile.name + ':send', message) + try{ + this.browserWindow.webContents.send(this.profile.name + ':send', message) + }catch(e){ + console.log(`Error sending message to ${this.profile.name} plugin: ${e}`) + console.log(`Message: ${message}`) + } } /** Listen to message from the engine */ diff --git a/packages/plugin/iframe/package.json b/packages/plugin/iframe/package.json index 47ec5dae..79ce50ee 100644 --- a/packages/plugin/iframe/package.json +++ b/packages/plugin/iframe/package.json @@ -1,6 +1,6 @@ { "name": "@remixproject/plugin-iframe", - "version": "0.3.37", + "version": "0.3.43", "homepage": "https://github.com/ethereum/remix-plugin/tree/master/packages/plugin/iframe#readme", "repository": { "type": "git", diff --git a/packages/plugin/theia/package.json b/packages/plugin/theia/package.json index a30d63f7..7cf4d9b1 100644 --- a/packages/plugin/theia/package.json +++ b/packages/plugin/theia/package.json @@ -1,4 +1,4 @@ { "name": "@remixproject/engine-plugin", - "version": "0.3.37" + "version": "0.3.43" } diff --git a/packages/plugin/vscode/package.json b/packages/plugin/vscode/package.json index dafe535b..122b79f8 100644 --- a/packages/plugin/vscode/package.json +++ b/packages/plugin/vscode/package.json @@ -1,6 +1,6 @@ { "name": "@remixproject/plugin-vscode", - "version": "0.3.37", + "version": "0.3.43", "homepage": "https://github.com/ethereum/remix-plugin/tree/master/packages/plugin/vscode#readme", "repository": { "type": "git", diff --git a/packages/plugin/webview/package.json b/packages/plugin/webview/package.json index 9a70d530..dee01d5b 100644 --- a/packages/plugin/webview/package.json +++ b/packages/plugin/webview/package.json @@ -1,6 +1,6 @@ { "name": "@remixproject/plugin-webview", - "version": "0.3.37", + "version": "0.3.43", "homepage": "https://github.com/ethereum/remix-plugin/tree/master/packages/plugin/webview#readme", "repository": { "type": "git", diff --git a/packages/plugin/webworker/package.json b/packages/plugin/webworker/package.json index 578a336c..1c713bfd 100644 --- a/packages/plugin/webworker/package.json +++ b/packages/plugin/webworker/package.json @@ -1,6 +1,6 @@ { "name": "@remixproject/plugin-webworker", - "version": "0.3.37", + "version": "0.3.43", "homepage": "https://github.com/ethereum/remix-plugin/tree/master/packages/plugin/webworker#readme", "repository": { "type": "git", diff --git a/packages/plugin/ws/package.json b/packages/plugin/ws/package.json index 13f52b1f..8b2f5d0a 100644 --- a/packages/plugin/ws/package.json +++ b/packages/plugin/ws/package.json @@ -1,6 +1,6 @@ { "name": "@remixproject/plugin-ws", - "version": "0.3.37", + "version": "0.3.43", "peerDependencies": { "ws": "^7.3.1" }, diff --git a/packages/utils/package.json b/packages/utils/package.json index 4fa206c9..bdd8aa9e 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -1,6 +1,6 @@ { "name": "@remixproject/plugin-utils", - "version": "0.3.37", + "version": "0.3.43", "dependencies": { "tslib": "2.0.1" },