From 9c53587e20f4e45ff82148004812edfa40857a47 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Sat, 27 Jan 2024 09:39:45 +0100 Subject: [PATCH] updater plugin --- .../ci/update_desktop_release_assets.ts | 2 +- apps/remix-ide/src/app.js | 7 ++- .../app/plugins/electron/appUpdaterPlugin.ts | 14 +++++ apps/remixdesktop/src/engine.ts | 3 + apps/remixdesktop/src/plugins/appUpdater.ts | 63 ++++++++++++++++--- .../src/plugins/compilerLoader.ts | 2 - apps/remixdesktop/src/preload.ts | 2 +- 7 files changed, 80 insertions(+), 13 deletions(-) create mode 100644 apps/remix-ide/src/app/plugins/electron/appUpdaterPlugin.ts diff --git a/apps/remix-ide/ci/update_desktop_release_assets.ts b/apps/remix-ide/ci/update_desktop_release_assets.ts index bddd7f8aaf..265f66bd6f 100644 --- a/apps/remix-ide/ci/update_desktop_release_assets.ts +++ b/apps/remix-ide/ci/update_desktop_release_assets.ts @@ -23,7 +23,7 @@ async function getAllReleases() { async function uploadReleaseAsset(release, name, file) { const upload_url = release.upload_url - console.log(upload_url) + console.log(`Uploading ${name} to ${upload_url}`) octokit.request({ method: "POST", url: upload_url, diff --git a/apps/remix-ide/src/app.js b/apps/remix-ide/src/app.js index 6f01181fa5..475825904d 100644 --- a/apps/remix-ide/src/app.js +++ b/apps/remix-ide/src/app.js @@ -57,7 +57,8 @@ import { electronTemplates } from './app/plugins/electron/templatesPlugin' import { xtermPlugin } from './app/plugins/electron/xtermPlugin' import { ripgrepPlugin } from './app/plugins/electron/ripgrepPlugin' import { compilerLoaderPlugin, compilerLoaderPluginDesktop } from './app/plugins/electron/compilerLoaderPlugin' - +import { appUpdaterPlugin } from './app/plugins/electron/appUpdaterPlugin' + import {OpenAIGpt} from './app/plugins/openaigpt' const isElectron = require('is-electron') @@ -377,6 +378,8 @@ class AppComponent { this.engine.register([xterm]) const ripgrep = new ripgrepPlugin() this.engine.register([ripgrep]) + const appUpdater = new appUpdaterPlugin() + this.engine.register([appUpdater]) } const compilerloader = isElectron()? new compilerLoaderPluginDesktop(): new compilerLoaderPlugin() @@ -500,7 +503,7 @@ class AppComponent { await this.appManager.activatePlugin(['solidity-script', 'remix-templates']) if (isElectron()){ - await this.appManager.activatePlugin(['isogit', 'electronconfig', 'electronTemplates', 'xterm', 'ripgrep']) + await this.appManager.activatePlugin(['isogit', 'electronconfig', 'electronTemplates', 'xterm', 'ripgrep', 'appUpdater']) } this.appManager.on( diff --git a/apps/remix-ide/src/app/plugins/electron/appUpdaterPlugin.ts b/apps/remix-ide/src/app/plugins/electron/appUpdaterPlugin.ts new file mode 100644 index 0000000000..8718b150db --- /dev/null +++ b/apps/remix-ide/src/app/plugins/electron/appUpdaterPlugin.ts @@ -0,0 +1,14 @@ +import { ElectronPlugin } from '@remixproject/engine-electron' + +const profile = { + displayName: 'appUpdater', + name: 'appUpdater', + description: 'appUpdater', +} + +export class appUpdaterPlugin extends ElectronPlugin { + constructor() { + console.log('appUpdaterPlugin') + super(profile) + } +} \ No newline at end of file diff --git a/apps/remixdesktop/src/engine.ts b/apps/remixdesktop/src/engine.ts index 004f2d13e1..0908425947 100644 --- a/apps/remixdesktop/src/engine.ts +++ b/apps/remixdesktop/src/engine.ts @@ -9,6 +9,7 @@ import { ConfigPlugin } from './plugins/configPlugin'; import { TemplatesPlugin } from './plugins/templates'; import { RipgrepPlugin } from './plugins/ripgrepPlugin'; import { CompilerLoaderPlugin } from './plugins/compilerLoader'; +import { AppUpdaterPlugin } from './plugins/appUpdater'; const engine = new Engine() const appManager = new PluginManager() @@ -19,6 +20,7 @@ const configPlugin = new ConfigPlugin() const templatesPlugin = new TemplatesPlugin() const ripgrepPlugin = new RipgrepPlugin() const compilerLoaderPlugin = new CompilerLoaderPlugin() +const appUpdaterPlugin = new AppUpdaterPlugin() engine.register(appManager) engine.register(fsPlugin) @@ -28,6 +30,7 @@ engine.register(configPlugin) engine.register(templatesPlugin) engine.register(ripgrepPlugin) engine.register(compilerLoaderPlugin) +engine.register(appUpdaterPlugin) appManager.activatePlugin('electronconfig') appManager.activatePlugin('fs') diff --git a/apps/remixdesktop/src/plugins/appUpdater.ts b/apps/remixdesktop/src/plugins/appUpdater.ts index 0143bbe8f5..bb32497061 100644 --- a/apps/remixdesktop/src/plugins/appUpdater.ts +++ b/apps/remixdesktop/src/plugins/appUpdater.ts @@ -1,11 +1,17 @@ import { ElectronBasePlugin, ElectronBasePluginClient } from "@remixproject/plugin-electron" import { Profile } from "@remixproject/plugin-utils" import { autoUpdater } from "electron" -import { profile } from "node:console" -export class appUpdaterPlugin extends ElectronBasePlugin { +const profile = { + displayName: 'appUpdater', + name: 'appUpdater', + description: 'appUpdater', +} + +export class AppUpdaterPlugin extends ElectronBasePlugin { constructor() { - super(profile, clientProfile, appUpdaterPluginClient) + console.log('AppUpdaterPlugin') + super(profile, clientProfile, AppUpdaterPluginClient) this.methods = [...super.methods] } } @@ -17,23 +23,66 @@ const clientProfile: Profile = { methods: ['checkForUpdates'], } -class appUpdaterPluginClient extends ElectronBasePluginClient { +class AppUpdaterPluginClient extends ElectronBasePluginClient { constructor(webContentsId: number, profile: Profile) { + console.log('AppUpdaterPluginClient') super(webContentsId, profile) } async onActivation(): Promise { console.log('onActivation', 'appUpdaterPluginClient') - this.onload(() => { + this.onload(async () => { console.log('onload', 'appUpdaterPluginClient') this.emit('loaded') + + autoUpdater.on('checking-for-update', () => { + console.log('Checking for update...'); + this.call('terminal', 'log', { + type: 'log', + value: 'Checking for update...', + }) + }) + autoUpdater.on('update-available', (info: any) => { + console.log('Update available.', info); + this.call('terminal', 'log', { + type: 'log', + value: 'Update available.', + }) + }) + autoUpdater.on('update-not-available', () => { + console.log('Update not available.'); + this.call('terminal', 'log', { + type: 'log', + value: 'Update not available.', + }) + }) + autoUpdater.on('error', (err) => { + console.log('Error in auto-updater. ' + err); + this.call('terminal', 'log', { + type: 'log', + value: 'Error in auto-updater. ' + err, + }) + }) + autoUpdater.on('update-downloaded', (info) => { + console.log('Update downloaded'); + this.call('terminal', 'log', { + type: 'log', + value: 'Update downloaded', + }) + autoUpdater.quitAndInstall(); + }) + await this.checkForUpdates() }) - } + } + async checkForUpdates(): Promise { console.log('checkForUpdates') + this.call('terminal', 'log', { + type: 'log', + value: 'Checking for updates...', + }) autoUpdater.checkForUpdates() } } -export default appUpdaterPlugin diff --git a/apps/remixdesktop/src/plugins/compilerLoader.ts b/apps/remixdesktop/src/plugins/compilerLoader.ts index e44653135c..7e60b38043 100644 --- a/apps/remixdesktop/src/plugins/compilerLoader.ts +++ b/apps/remixdesktop/src/plugins/compilerLoader.ts @@ -66,9 +66,7 @@ class CompilerLoaderPluginClient extends ElectronBasePluginClient { } async onActivation(): Promise { - console.log('onActivation', 'CompilerLoaderPluginClient') this.onload(() => { - console.log('onload', 'CompilerLoaderPluginClient') this.emit('loaded') }) } diff --git a/apps/remixdesktop/src/preload.ts b/apps/remixdesktop/src/preload.ts index 007fe098e9..c5c8e5a65d 100644 --- a/apps/remixdesktop/src/preload.ts +++ b/apps/remixdesktop/src/preload.ts @@ -6,7 +6,7 @@ console.log('preload.ts', new Date().toLocaleTimeString()) /* preload script needs statically defined API for each plugin */ -const exposedPLugins = ['fs', 'git', 'xterm', 'isogit', 'electronconfig', 'electronTemplates', 'ripgrep', 'compilerloader'] +const exposedPLugins = ['fs', 'git', 'xterm', 'isogit', 'electronconfig', 'electronTemplates', 'ripgrep', 'compilerloader', 'appUpdater'] let webContentsId: number | undefined