From 1af7a21620c32745c1e2bd230b1c75fc9474f9ca Mon Sep 17 00:00:00 2001 From: luhc228 Date: Tue, 6 Jul 2021 11:03:23 +0800 Subject: [PATCH 1/3] fix: electron module not found in prod env --- main/data/data.json | 2 +- main/index.ts | 8 ++---- main/ipc/installBasePackages.ts | 5 ++-- .../packageInstaller/IDEExtensionInstaller.ts | 13 ++++++---- main/packageInstaller/index.ts | 26 +++++++++++++++---- main/types/index.ts | 6 +++++ package.json | 2 +- 7 files changed, 42 insertions(+), 20 deletions(-) diff --git a/main/data/data.json b/main/data/data.json index f0cbd53..7c1f853 100644 --- a/main/data/data.json +++ b/main/data/data.json @@ -136,7 +136,7 @@ "isInternal": false } ], - "IdeExtensions": [ + "IDEExtensions": [ { "title": "AppWorks Pack", "name": "iceworks-team.iceworks", diff --git a/main/index.ts b/main/index.ts index 3ba4ff9..aef0673 100644 --- a/main/index.ts +++ b/main/index.ts @@ -7,7 +7,6 @@ import getPackagesData from './utils/getPackagesData'; import { autoDownloadPackages } from './autoDownloader'; import store, { packagesDataKey } from './store'; import { recordDAU } from './recorder'; -import log from './utils/log'; process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = 'true'; @@ -27,13 +26,10 @@ app.whenReady() autoDownloadPackages(); + recordDAU(); + app.on('activate', () => { if (BrowserWindow.getAllWindows().length === 0) createWindow(); - - recordDAU() - .catch((err) => { - log.error(err); - }); }); }); diff --git a/main/ipc/installBasePackages.ts b/main/ipc/installBasePackages.ts index 93a7ddb..16667f5 100644 --- a/main/ipc/installBasePackages.ts +++ b/main/ipc/installBasePackages.ts @@ -7,6 +7,7 @@ import { send as sendMainWindow } from '../window'; import killChannelChildProcess from '../utils/killChannelChildProcess'; import log from '../utils/log'; import nodeCache from '../utils/nodeCache'; +import store, { packagesDataKey } from '../store'; const childProcessMap = new Map(); @@ -23,8 +24,8 @@ export default () => { // fork a child process to install package childProcess = child_process.fork(path.join(__dirname, '..', 'packageInstaller/index')); childProcessMap.set(installChannel, childProcess); - - childProcess.send({ packagesList, installChannel, processChannel }); + const packagesData = store.get(packagesDataKey); + childProcess.send({ packagesList, packagesData, installChannel, processChannel }); childProcess.on('message', ({ channel, data }: any) => { if (channel === processChannel) { diff --git a/main/packageInstaller/IDEExtensionInstaller.ts b/main/packageInstaller/IDEExtensionInstaller.ts index 9b1ae1f..26df6a9 100644 --- a/main/packageInstaller/IDEExtensionInstaller.ts +++ b/main/packageInstaller/IDEExtensionInstaller.ts @@ -1,21 +1,24 @@ import * as path from 'path'; import * as execa from 'execa'; import isCommandInstalled from '../utils/isCommandInstalled'; -import { IPackageInfo, IPackageInstaller } from '../types'; +import { IPackageInfo, IPackageInstaller, IPackagesData, Platform } from '../types'; import { INSTALL_COMMAND_PACKAGES, VSCODE_COMMAND_NAME, VSCODE_NAME } from '../constants'; import writeLog from '../utils/writeLog'; -import store, { packagesDataKey } from '../store'; import getLocalDmgInfo from '../packageInfo/dmg'; import installCommandToPath from '../utils/installCommandToPath'; class IDEExtensionInstaller implements IPackageInstaller { channel: string; + packagesData: IPackagesData; + IDETypeProcessor: { [k: string]: Function }; - constructor(channel: string) { + constructor(channel: string, packagesData: any) { this.channel = channel; + this.packagesData = packagesData; + this.IDETypeProcessor = { VSCode: this.installVSCodeExtension, }; @@ -64,9 +67,9 @@ class IDEExtensionInstaller implements IPackageInstaller { // try to install code command to the path writeLog(this.channel, 'Try to install code command to path.', true, 'info'); - const { apps = [] } = store.get(packagesDataKey); + const { apps = [] } = this.packagesData; - const vscodeInfo = apps.find((app) => app.name === VSCODE_NAME && app.platforms.includes(process.platform)); + const vscodeInfo = apps.find((app) => app.name === VSCODE_NAME && app.platforms.includes(process.platform as Platform)); if (!vscodeInfo) { throw new Error(`${VSCODE_NAME} info was not found.`); } diff --git a/main/packageInstaller/index.ts b/main/packageInstaller/index.ts index 706e922..1603b0d 100644 --- a/main/packageInstaller/index.ts +++ b/main/packageInstaller/index.ts @@ -1,7 +1,7 @@ import * as path from 'path'; import * as fse from 'fs-extra'; import downloadFile from '../utils/downloadFile'; -import { IInstallResult, IPackageInfo } from '../types'; +import { IInstallResult, IPackageInfo, IPackagesData } from '../types'; import log from '../utils/log'; import writeLog from '../utils/writeLog'; import { INSTALL_COMMAND_PACKAGES, TOOLKIT_PACKAGES_DIR } from '../constants'; @@ -28,22 +28,26 @@ process.on('message', processListener); function processListener({ packagesList, + packagesData, installChannel, processChannel, }: { packagesList: IPackageInfo[]; + packagesData: IPackagesData; installChannel: string; processChannel: string; }) { - installPackages({ packagesList, installChannel, processChannel }); + installPackages({ packagesList, packagesData, installChannel, processChannel }); } async function installPackages({ packagesList, + packagesData, installChannel, processChannel, }: { packagesList: IPackageInfo[]; + packagesData: IPackagesData; installChannel: string; processChannel: string; }) { @@ -79,7 +83,7 @@ async function installPackages({ throw new Error('No package was found.'); } // install package - const { localPath } = await install({ packagePath, packageInfo, channel: installChannel }); + const { localPath } = await install({ packagePath, packageInfo, channel: installChannel, packagesData }); // install package command // e.g: VS Code cli command 'code' await installPkgCommandToPath(name, localPath); @@ -107,7 +111,19 @@ async function installPackages({ process.send({ channel: processChannel, data: { status: 'done', result } }); } -async function install({ channel, packagePath, packageInfo }: { channel: string; packagePath: string; packageInfo: IPackageInfo }) { +async function install( + { + channel, + packagePath, + packageInfo, + packagesData, + }: { + channel: string; + packagePath: string; + packageInfo: IPackageInfo; + packagesData: IPackagesData; + }, +) { let processorKey; if (packagePath) { processorKey = path.extname(packagePath).replace('.', ''); @@ -116,7 +132,7 @@ async function install({ channel, packagePath, packageInfo }: { channel: string; } const Installer = packageProcessor[processorKey]; if (Installer) { - const installer = new Installer(channel); + const installer = new Installer(channel, packagesData); return await installer.install(packageInfo, packagePath); } } diff --git a/main/types/index.ts b/main/types/index.ts index 50ca75e..83875e0 100644 --- a/main/types/index.ts +++ b/main/types/index.ts @@ -55,3 +55,9 @@ export interface INodeVersions { versions: string[]; majors: Array<{ version: string; title: string }>; } + +export interface IPackagesData { + bases: IBasePackageInfo[]; + + apps: IBasePackageInfo[]; +} diff --git a/package.json b/package.json index 170e202..1842858 100644 --- a/package.json +++ b/package.json @@ -105,7 +105,7 @@ "@types/shelljs": "^0.8.8", "ali-oss": "^6.15.2", "concurrently": "^5.1.0", - "electron": "12.0.9", + "electron": "^12.0.0", "electron-builder": "^22.10.5", "electron-notarize": "^1.0.0", "eslint": "^6.8.0", From d232cc0a151a402c3b77e1607ecb413675f414e6 Mon Sep 17 00:00:00 2001 From: luhc228 Date: Tue, 6 Jul 2021 11:04:44 +0800 Subject: [PATCH 2/3] chore: data --- main/data/data.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/data/data.json b/main/data/data.json index 7c1f853..f0cbd53 100644 --- a/main/data/data.json +++ b/main/data/data.json @@ -136,7 +136,7 @@ "isInternal": false } ], - "IDEExtensions": [ + "IdeExtensions": [ { "title": "AppWorks Pack", "name": "iceworks-team.iceworks", From d584058f274e341dcd41ce23deb1ffcd5765d2c5 Mon Sep 17 00:00:00 2001 From: luhc228 Date: Tue, 6 Jul 2021 14:29:32 +0800 Subject: [PATCH 3/3] chore: add comment --- main/ipc/installBasePackages.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/main/ipc/installBasePackages.ts b/main/ipc/installBasePackages.ts index 16667f5..60b180e 100644 --- a/main/ipc/installBasePackages.ts +++ b/main/ipc/installBasePackages.ts @@ -24,6 +24,8 @@ export default () => { // fork a child process to install package childProcess = child_process.fork(path.join(__dirname, '..', 'packageInstaller/index')); childProcessMap.set(installChannel, childProcess); + // After packing the Electron app, the electron module which the electron-store require, couldn't be found in childProcess. + // For more detail, see this PR: https://github.com/appworks-lab/toolkit/pull/41 const packagesData = store.get(packagesDataKey); childProcess.send({ packagesList, packagesData, installChannel, processChannel });