Skip to content

Commit f6bb77e

Browse files
authored
Merge pull request #72 from appworks-lab/release-next
Release 0.4.0
2 parents efe67cc + 0d569ed commit f6bb77e

File tree

110 files changed

+1858
-750
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+1858
-750
lines changed

CHANGELOG.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
# CHANGELOG
22

3+
## 0.4.0
4+
5+
- Feat: add base packages info cache
6+
- Feat: support view app or tool details
7+
- Feat: enhance app updates and show the changelog
8+
- Feat: support build an asar package
9+
310
## 0.3.0
411

512
- Feat: support install tnpm or cnpm
613
- Feat: support install mac app
714
- Feat: support install chrome extension
815
- Feat: smaller window size
9-
- chore: update readme
16+
- Chore: update readme
1017

1118
## 0.2.1
1219

1320
- Fix: fail to get internal npm package info
14-
- Feat: use default shell to excute sh file
21+
- Feat: use default shell to execute sh file
1522
- Feat: add global dependencies prefix path
1623
- Feat: add recommend icon to registry
1724
- Feat: update log to sls
@@ -34,4 +41,4 @@
3441
## 0.1.0
3542

3643
- Feat: fast install packages, including VS Code/Git/Node.js/AppWorks/Chrome
37-
- Feat: node version manager
44+
- Feat: node version manager

main/utils/autoUpdater.ts renamed to main/autoUpdater/index.ts

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { NsisUpdater, MacUpdater, AppImageUpdater } from 'electron-updater';
2-
import * as isDev from 'electron-is-dev';
3-
import log from './log';
2+
import { app } from 'electron';
3+
import fetch from 'node-fetch';
4+
import log from '../utils/log';
5+
import { createUpdaterWindow, sendToUpdaterWindow } from '../window';
6+
7+
const { version: currentVersion } = require('../../package.json');
48

59
let AutoUpdater;
610
if (process.platform === 'win32') {
@@ -19,28 +23,57 @@ autoUpdater.logger.transports.file.level = 'info';
1923
autoUpdater.on('checking-for-update', () => {
2024
log.info('checking-for-update');
2125
});
26+
2227
autoUpdater.on('update-available', (info) => {
2328
log.info('update-available', info);
2429
});
30+
2531
autoUpdater.on('update-not-available', (info) => {
2632
log.info('update-not-available', info);
2733
});
34+
2835
autoUpdater.on('error', (error) => {
2936
log.error('error', error);
3037
});
38+
3139
autoUpdater.on('download-progress', (meta) => {
3240
log.info('download-progress', meta);
3341
});
42+
3443
autoUpdater.on('update-downloaded', (info) => {
3544
log.info('update-downloaded', info);
45+
const { version: latestVersion } = info;
46+
app.whenReady()
47+
.then(() => {
48+
return createUpdaterWindow();
49+
})
50+
.then(() => {
51+
return fetchChangelog(latestVersion);
52+
})
53+
.then((changelog) => {
54+
sendToUpdaterWindow('update-info', {
55+
currentVersion,
56+
latestVersion,
57+
changelog,
58+
});
59+
})
60+
.catch((e) => {
61+
log.error(e);
62+
});
3663
});
3764

3865
export function checkForUpdates() {
39-
if (isDev) {
66+
if (process.env.NODE_ENV === 'development') {
4067
return;
4168
}
42-
autoUpdater.checkForUpdates();
69+
70+
return autoUpdater.checkForUpdates();
4371
}
4472

45-
export default autoUpdater;
73+
async function fetchChangelog(version: string) {
74+
const res = await fetch(`https://iceworks.oss-cn-hangzhou.aliyuncs.com/toolkit/changelog/${version}.json`);
75+
const content = await res.json();
76+
return content;
77+
}
4678

79+
export default autoUpdater;

main/data/data.json

Lines changed: 314 additions & 21 deletions
Large diffs are not rendered by default.

main/index.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { app, BrowserWindow } from 'electron';
22
import modifyProcessEnv from './utils/modifyProcessEnv';
3-
import { createWindow } from './window';
3+
import { createMainWindow } from './window';
44
import handleIPC from './ipc';
5-
import { checkForUpdates } from './utils/autoUpdater';
5+
import { checkForUpdates } from './autoUpdater';
66
import getPackagesData from './utils/getPackagesData';
77
import { autoDownloadPackages } from './autoDownloader';
88
import store, { packagesDataKey } from './store';
99
import { recordDAU } from './recorder';
10+
import setMenu from './menu';
1011

1112
process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = 'true';
1213

@@ -18,21 +19,26 @@ app.whenReady()
1819
.finally(() => {
1920
modifyProcessEnv();
2021

21-
createWindow();
22+
createMainWindow();
2223

2324
handleIPC();
2425

25-
checkForUpdates();
26-
27-
autoDownloadPackages();
28-
29-
recordDAU();
26+
setMenu();
3027

3128
app.on('activate', () => {
32-
if (BrowserWindow.getAllWindows().length === 0) createWindow();
29+
if (BrowserWindow.getAllWindows().length === 0) createMainWindow();
3330
});
3431
});
3532

33+
34+
app.on('will-finish-launching', () => {
35+
checkForUpdates();
36+
37+
autoDownloadPackages();
38+
39+
recordDAU();
40+
});
41+
3642
// Quit when all windows are closed.
3743
app.on('window-all-closed', () => {
3844
if (process.platform !== 'darwin') app.quit();

main/ipc/getBasePackagesInfo.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1-
import { ipcMain } from 'electron';
1+
import { ipcMain, IpcMainInvokeEvent } from 'electron';
22
import { BasePackageInfo, Platform } from '../types';
33
import { getPackageInfo } from '../packageInfo';
44
import checkIsAliInternal from '../utils/checkIsAliInternal';
55
import store, { packagesDataKey } from '../store';
6+
import nodeCache from '../utils/nodeCache';
7+
8+
const basePackagesInfoKey = 'basePackagesInfo';
69

710
export default () => {
8-
ipcMain.handle('get-base-packages-info', async () => {
11+
ipcMain.handle('get-base-packages-info', async (e: IpcMainInvokeEvent, force = false) => {
12+
const cache = nodeCache.get(basePackagesInfoKey);
13+
if (!force && cache) {
14+
return cache;
15+
}
916
const data = store.get(packagesDataKey);
1017
const { bases = [] }: { bases: BasePackageInfo[] } = data;
1118
const isAliInternal = await checkIsAliInternal();
@@ -22,6 +29,9 @@ export default () => {
2229
const packagesData = await Promise.all(basePackages.map((basePackageInfo: BasePackageInfo) => {
2330
return getPackageInfo(basePackageInfo);
2431
}));
32+
33+
nodeCache.set(basePackagesInfoKey, packagesData);
34+
2535
return packagesData;
2636
});
2737
};

main/ipc/handleApp.ts

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import checkIsAliInternal from '../utils/checkIsAliInternal';
99
import log from '../utils/log';
1010
import killChannelChildProcess from '../utils/killChannelChildProcess';
1111
import { record } from '../recorder';
12-
import { send as sendMainWindow } from '../window';
12+
import { sendToMainWindow } from '../window';
1313

1414
const childProcessMap = new Map();
1515

@@ -54,29 +54,32 @@ export default () => {
5454
log.info(`Channel ${childProcessName} has an existed child process.`);
5555
return;
5656
}
57-
// fork a child process to install package
5857
childProcess = child_process.fork(path.join(__dirname, '..', 'packageManager/index'));
5958
childProcessMap.set(childProcessName, childProcess);
6059
const packagesData = store.get(packagesDataKey);
6160
childProcess.send({ packagesList: [packageInfo], packagesData, uninstallChannel, processChannel, type: 'uninstall' });
6261

6362
childProcess.on('message', ({ channel, data }: any) => {
6463
if (channel === processChannel) {
65-
if (data.status === 'done') {
66-
record({
67-
module: 'app',
68-
action: 'uninstall',
69-
data: {
70-
name: packageInfo.title,
71-
},
72-
});
73-
}
74-
if (data.status === 'done' || data.status === 'error') {
75-
killChannelChildProcess(childProcessMap, childProcessName);
64+
switch (data.status) {
65+
case 'done':
66+
record({
67+
module: 'app',
68+
action: 'uninstall',
69+
data: {
70+
name: packageInfo.title,
71+
},
72+
});
73+
// eslint-disable-next-line no-fallthrough
74+
case 'error':
75+
killChannelChildProcess(childProcessMap, childProcessName);
76+
break;
77+
default:
78+
break;
7679
}
7780
}
7881

79-
sendMainWindow(channel, data);
82+
sendToMainWindow(channel, data);
8083
});
8184
});
8285

@@ -90,29 +93,36 @@ export default () => {
9093
log.info(`Channel ${childProcessName} has an existed child process.`);
9194
return;
9295
}
93-
// fork a child process to install package
96+
/**
97+
* we need to cancel the install process
98+
* so we create a childProcess and we can kill it later
99+
*/
94100
childProcess = child_process.fork(path.join(__dirname, '..', 'packageManager/index'));
95101
childProcessMap.set(childProcessName, childProcess);
96102
const packagesData = store.get(packagesDataKey);
97103
childProcess.send({ packagesList: [packageInfo], packagesData, installChannel, processChannel });
98104

99105
childProcess.on('message', ({ channel, data }: any) => {
100106
if (channel === processChannel) {
101-
if (data.status === 'done') {
102-
record({
103-
module: 'app',
104-
action: 'install',
105-
data: {
106-
name: packageInfo.title,
107-
},
108-
});
109-
}
110-
if (data.status === 'done' || data.status === 'error') {
111-
killChannelChildProcess(childProcessMap, childProcessName);
107+
switch (data.status) {
108+
case 'done':
109+
record({
110+
module: 'app',
111+
action: 'install',
112+
data: {
113+
name: packageInfo.title,
114+
},
115+
});
116+
// eslint-disable-next-line no-fallthrough
117+
case 'error':
118+
killChannelChildProcess(childProcessMap, childProcessName);
119+
break;
120+
default:
121+
break;
112122
}
113123
}
114124

115-
sendMainWindow(channel, data);
125+
sendToMainWindow(channel, data);
116126
});
117127
});
118128
};

main/ipc/handleBrowserExtension.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { getPackageInfo } from '../packageInfo';
99
import log from '../utils/log';
1010
import { record } from '../recorder';
1111
import killChannelChildProcess from '../utils/killChannelChildProcess';
12-
import { send as sendMainWindow } from '../window';
12+
import { sendToMainWindow } from '../window';
1313
import ping = require('ping');
1414

1515
const childProcessMap = new Map();
@@ -82,25 +82,29 @@ export default () => {
8282

8383
childProcess.on('message', ({ channel, data }: any) => {
8484
if (channel === processChannel) {
85-
if (data.status === 'done') {
86-
record({
87-
module: 'browserExtension',
88-
action: 'install',
89-
data: {
90-
name: packageInfo.title,
91-
},
92-
});
93-
}
94-
if (data.status === 'done' || data.status === 'error') {
95-
killChannelChildProcess(childProcessMap, childProcessName);
85+
switch (data.status) {
86+
case 'done':
87+
record({
88+
module: 'browserExtension',
89+
action: 'install',
90+
data: {
91+
name: packageInfo.title,
92+
},
93+
});
94+
// eslint-disable-next-line no-fallthrough
95+
case 'error':
96+
killChannelChildProcess(childProcessMap, childProcessName);
97+
break;
98+
default:
99+
break;
96100
}
97101
}
98102

99-
sendMainWindow(channel, data);
103+
sendToMainWindow(channel, data);
100104
});
101105
});
102106

103-
ipcMain.handle('check-webstore-host-alive', async (e: IpcMainInvokeEvent, browserType: string) => {
107+
ipcMain.handle('check-webstore-host-is-accessible', async (e: IpcMainInvokeEvent, browserType: string) => {
104108
const browserHosts = {
105109
Chrome: 'chrome.google.com',
106110
};

main/ipc/handleNpmDependency.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as child_process from 'child_process';
22
import * as path from 'path';
33
import { ipcMain, IpcMainInvokeEvent } from 'electron';
4-
import { send as sendMainWindow } from '../window';
4+
import { sendToMainWindow } from '../window';
55
import {
66
getGlobalDependencies,
77
uninstallGlobalDependency,
@@ -47,6 +47,10 @@ export default () => {
4747
});
4848

4949
ipcMain.handle('create-custom-global-dependencies-dir', async (e: IpcMainInvokeEvent, channel: string, currentGlobalDepsPath: string) => {
50+
/**
51+
* we need to cancel the process
52+
* so we create a childProcess and we can kill it later
53+
*/
5054
const childProcess = child_process.fork(path.join(__dirname, '..', 'npm/dependency/createCustomGlobalDepsDir'));
5155
childProcessMap.set(channel, childProcess);
5256

@@ -55,13 +59,20 @@ export default () => {
5559
childProcessMap.set(channel, childProcess);
5660

5761
childProcess.on('message', ({ data }: any) => {
58-
if (data.status === 'done') {
59-
record({
60-
module: 'node',
61-
action: 'createCustomGlobalDependenciesDir',
62-
});
62+
switch (data.status) {
63+
case 'done':
64+
record({
65+
module: 'node',
66+
action: 'createCustomGlobalDependenciesDir',
67+
});
68+
// eslint-disable-next-line no-fallthrough
69+
case 'error':
70+
killChannelChildProcess(childProcessMap, channel);
71+
break;
72+
default:
73+
break;
6374
}
64-
sendMainWindow(channel, data);
75+
sendToMainWindow(channel, data);
6576
});
6677
});
6778

0 commit comments

Comments
 (0)