Skip to content
Merged
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
8 changes: 2 additions & 6 deletions main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -27,13 +26,10 @@ app.whenReady()

autoDownloadPackages();

recordDAU();

app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) createWindow();

recordDAU()
.catch((err) => {
log.error(err);
});
});
});

Expand Down
7 changes: 5 additions & 2 deletions main/ipc/installBasePackages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -23,8 +24,10 @@ 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 });
// 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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

最好 注释下 这个问题

childProcess.send({ packagesList, packagesData, installChannel, processChannel });

childProcess.on('message', ({ channel, data }: any) => {
if (channel === processChannel) {
Expand Down
13 changes: 8 additions & 5 deletions main/packageInstaller/IDEExtensionInstaller.ts
Original file line number Diff line number Diff line change
@@ -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,
};
Expand Down Expand Up @@ -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.`);
}
Expand Down
26 changes: 21 additions & 5 deletions main/packageInstaller/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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;
}) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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('.', '');
Expand All @@ -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);
}
}
Expand Down
6 changes: 6 additions & 0 deletions main/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,9 @@ export interface INodeVersions {
versions: string[];
majors: Array<{ version: string; title: string }>;
}

export interface IPackagesData {
bases: IBasePackageInfo[];

apps: IBasePackageInfo[];
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down