@ives_xxz/packages 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AddComponent/main.js +32 -0
- package/AddComponent/package.json +26 -0
- package/AddComponent/panel/index.js +233 -0
- package/AddComponent/readme.md +38 -0
- package/AddComponent/scene-accessor.js +109 -0
- package/AddComponent/template-auto-dock.js +73 -0
- package/BitmapFontTools/i18n/en.js +1 -0
- package/BitmapFontTools/i18n/zh.js +1 -0
- package/BitmapFontTools/main.js +1 -0
- package/BitmapFontTools/package-lock.json +83 -0
- package/BitmapFontTools/package.json +37 -0
- package/BitmapFontTools/panel/font.css +1 -0
- package/BitmapFontTools/panel/font.js +58 -0
- package/BitmapFontTools/panel/font_panel.js +1 -0
- package/BitmapFontTools/panel/ttf.css +1 -0
- package/BitmapFontTools/panel/ttf.js +68 -0
- package/BitmapFontTools/panel/ttf_panel.js +1 -0
- package/FWAssetsFinder/main.js +9 -0
- package/FWAssetsFinder/package.json +20 -0
- package/FWAssetsFinder/panel/index.css +2 -0
- package/FWAssetsFinder/panel/index.html +52 -0
- package/FWAssetsFinder/panel/index.js +265 -0
- package/FWAssetsFinder/panel/less.css +71 -0
- package/FWAssetsFinder/panel/scene.js +194 -0
- package/FWExcelGenerator/main.js +367 -0
- package/FWExcelGenerator/package-lock.json +109 -0
- package/FWExcelGenerator/package.json +23 -0
- package/FWExcelGenerator/panel/index.js +648 -0
- package/FWLayerGenerator/main.js +186 -0
- package/FWLayerGenerator/package.json +21 -0
- package/FWLayerGenerator/panel/index.css +36 -0
- package/FWLayerGenerator/panel/index.html +17 -0
- package/FWLayerGenerator/panel/index.js +29 -0
- package/FWMask/inspector.js +26 -0
- package/FWMask/main.js +16 -0
- package/FWMask/package.json +6 -0
- package/FWPolygonPoints/main.js +149 -0
- package/FWPolygonPoints/package.json +9 -0
- package/PNG Auto Compress/CHANGELOG.md +32 -0
- package/PNG Auto Compress/LICENSE +21 -0
- package/PNG Auto Compress/README.md +113 -0
- package/PNG Auto Compress/config-manager.js +72 -0
- package/PNG Auto Compress/i18n/en.js +14 -0
- package/PNG Auto Compress/i18n/zh.js +14 -0
- package/PNG Auto Compress/images/setting.png +0 -0
- package/PNG Auto Compress/jsconfig.json +1 -0
- package/PNG Auto Compress/main.js +377 -0
- package/PNG Auto Compress/package.json +41 -0
- package/PNG Auto Compress/panel.setting/index.css +13 -0
- package/PNG Auto Compress/panel.setting/index.html +51 -0
- package/PNG Auto Compress/panel.setting/index.js +124 -0
- package/PNG Auto Compress/pngquant/macos/COPYRIGHT +687 -0
- package/PNG Auto Compress/pngquant/macos/README.md +78 -0
- package/PNG Auto Compress/pngquant/macos/pngquant +0 -0
- package/PNG Auto Compress/pngquant/macos/pngquant-compat +0 -0
- package/PNG Auto Compress/pngquant/windows/COPYRIGHT +687 -0
- package/PNG Auto Compress/pngquant/windows/Drag PNG here to reduce palette automatically.bat +11 -0
- package/PNG Auto Compress/pngquant/windows/Drag PNG here to reduce palette to 256.bat +10 -0
- package/PNG Auto Compress/pngquant/windows/README.txt +78 -0
- package/PNG Auto Compress/pngquant/windows/pngquant.exe +0 -0
- package/PNG Auto Compress/typings/cocos/editor.d.ts +1053 -0
- package/PNG Auto Compress/utils/file-utils.js +67 -0
- package/Quick Finder/CHANGELOG.md +100 -0
- package/Quick Finder/LICENSE +21 -0
- package/Quick Finder/README.en.md +141 -0
- package/Quick Finder/README.md +149 -0
- package/Quick Finder/i18n/en.js +42 -0
- package/Quick Finder/i18n/zh.js +42 -0
- package/Quick Finder/images/assets/animation-clip.png +0 -0
- package/Quick Finder/images/assets/asset.png +0 -0
- package/Quick Finder/images/assets/atlas.png +0 -0
- package/Quick Finder/images/assets/audio-clip.png +0 -0
- package/Quick Finder/images/assets/auto-atlas.png +0 -0
- package/Quick Finder/images/assets/bitmap-font.png +0 -0
- package/Quick Finder/images/assets/buffer.png +0 -0
- package/Quick Finder/images/assets/coffeescript.png +0 -0
- package/Quick Finder/images/assets/component.png +0 -0
- package/Quick Finder/images/assets/css.png +0 -0
- package/Quick Finder/images/assets/dragonbones-atlas.png +0 -0
- package/Quick Finder/images/assets/folder.png +0 -0
- package/Quick Finder/images/assets/html.png +0 -0
- package/Quick Finder/images/assets/javascript.png +0 -0
- package/Quick Finder/images/assets/json.png +0 -0
- package/Quick Finder/images/assets/label-atlas.png +0 -0
- package/Quick Finder/images/assets/markdown.png +0 -0
- package/Quick Finder/images/assets/material.png +0 -0
- package/Quick Finder/images/assets/mesh.png +0 -0
- package/Quick Finder/images/assets/mount.png +0 -0
- package/Quick Finder/images/assets/node.png +0 -0
- package/Quick Finder/images/assets/particle.png +0 -0
- package/Quick Finder/images/assets/physics-material.png +0 -0
- package/Quick Finder/images/assets/prefab.png +0 -0
- package/Quick Finder/images/assets/raw-asset.png +0 -0
- package/Quick Finder/images/assets/scene.png +0 -0
- package/Quick Finder/images/assets/shader.png +0 -0
- package/Quick Finder/images/assets/skeleton.png +0 -0
- package/Quick Finder/images/assets/spine.png +0 -0
- package/Quick Finder/images/assets/sprite-animation.png +0 -0
- package/Quick Finder/images/assets/sprite-atlas.png +0 -0
- package/Quick Finder/images/assets/sprite-frame.png +0 -0
- package/Quick Finder/images/assets/text.png +0 -0
- package/Quick Finder/images/assets/tiled-map.png +0 -0
- package/Quick Finder/images/assets/ttf-font.png +0 -0
- package/Quick Finder/images/assets/typescript.png +0 -0
- package/Quick Finder/images/search.png +0 -0
- package/Quick Finder/images/settings.png +0 -0
- package/Quick Finder/images/update.png +0 -0
- package/Quick Finder/images/version.png +0 -0
- package/Quick Finder/jsconfig.json +17 -0
- package/Quick Finder/lib/node-fetch.js +1649 -0
- package/Quick Finder/lib/vue.global.prod.js +7 -0
- package/Quick Finder/package.json +45 -0
- package/Quick Finder/src/common/config-manager.js +122 -0
- package/Quick Finder/src/eazax/browser-util.js +61 -0
- package/Quick Finder/src/eazax/color-util.js +37 -0
- package/Quick Finder/src/eazax/css/cocos-class.css +202 -0
- package/Quick Finder/src/eazax/css/cocos-tag.css +197 -0
- package/Quick Finder/src/eazax/css/eazax-colors.css +18 -0
- package/Quick Finder/src/eazax/editor-main-kit.js +53 -0
- package/Quick Finder/src/eazax/editor-main-util.js +112 -0
- package/Quick Finder/src/eazax/editor-renderer-kit.js +26 -0
- package/Quick Finder/src/eazax/file-util.js +158 -0
- package/Quick Finder/src/eazax/i18n.js +36 -0
- package/Quick Finder/src/eazax/main-event.js +81 -0
- package/Quick Finder/src/eazax/package-util.js +47 -0
- package/Quick Finder/src/eazax/renderer-event.js +80 -0
- package/Quick Finder/src/eazax/updater.js +92 -0
- package/Quick Finder/src/eazax/version-util.js +61 -0
- package/Quick Finder/src/eazax/window-util.js +80 -0
- package/Quick Finder/src/main/finder.js +101 -0
- package/Quick Finder/src/main/index.js +155 -0
- package/Quick Finder/src/main/opener.js +95 -0
- package/Quick Finder/src/main/panel-manager.js +159 -0
- package/Quick Finder/src/renderer/search/index.css +222 -0
- package/Quick Finder/src/renderer/search/index.html +46 -0
- package/Quick Finder/src/renderer/search/index.js +348 -0
- package/Quick Finder/src/renderer/settings/index.css +101 -0
- package/Quick Finder/src/renderer/settings/index.html +86 -0
- package/Quick Finder/src/renderer/settings/index.js +219 -0
- package/Quick Finder/typings/cocos/editor.d.ts +1053 -0
- package/Quick Finder/typings/vue.d.ts +1 -0
- package/README.md +93 -0
- package/package.json +12 -0
- package/unpack plist/main.js +253 -0
- package/unpack plist/package.json +13 -0
- package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/CHANGELOG.md +30 -0
- package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/LICENSE +21 -0
- package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/README.en.md +111 -0
- package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/README.md +115 -0
- package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/i18n/en.js +55 -0
- package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/i18n/zh.js +55 -0
- package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/images/search.png +0 -0
- package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/images/settings.png +0 -0
- package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/images/update.png +0 -0
- package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/images/version.png +0 -0
- package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/jsconfig.json +17 -0
- package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/lib/node-fetch.js +1649 -0
- package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/lib/vue.global.prod.js +7 -0
- package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/package.json +44 -0
- package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/common/config-manager.js +104 -0
- package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/eazax/browser-util.js +61 -0
- package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/eazax/color-util.js +37 -0
- package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/eazax/css/cocos-class.css +201 -0
- package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/eazax/css/cocos-tag.css +197 -0
- package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/eazax/css/eazax-colors.css +18 -0
- package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/eazax/editor-main-kit.js +53 -0
- package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/eazax/editor-main-util.js +147 -0
- package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/eazax/editor-renderer-kit.js +26 -0
- package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/eazax/file-util.js +158 -0
- package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/eazax/i18n.js +36 -0
- package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/eazax/main-event.js +81 -0
- package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/eazax/package-util.js +47 -0
- package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/eazax/renderer-event.js +80 -0
- package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/eazax/updater.js +92 -0
- package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/eazax/version-util.js +61 -0
- package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/eazax/window-util.js +80 -0
- package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/main/editor-api.js +90 -0
- package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/main/finder.js +248 -0
- package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/main/index.js +155 -0
- package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/main/object-util.js +70 -0
- package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/main/panel-manager.js +86 -0
- package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/main/parser.js +161 -0
- package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/main/printer.js +108 -0
- package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/renderer/settings/index.css +61 -0
- package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/renderer/settings/index.html +90 -0
- package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/src/renderer/settings/index.js +191 -0
- package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/typings/cocos/editor.d.ts +1053 -0
- package//345/274/225/347/224/250/346/237/245/346/211/276/345/231/250/typings/vue.d.ts +1 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
const Fs = require('fs');
|
|
2
|
+
const Path = require('path');
|
|
3
|
+
const { promisify } = require('util');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 文件工具 (Promise 化)
|
|
7
|
+
* @author 陈皮皮 (ifaswind)
|
|
8
|
+
* @version 20210818
|
|
9
|
+
*/
|
|
10
|
+
const FileUtil = {
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 获取文件状态
|
|
14
|
+
* @param {Fs.PathLike} path 路径
|
|
15
|
+
* @returns {Promise<Fs.stats>}
|
|
16
|
+
*/
|
|
17
|
+
stat: promisify(Fs.stat),
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 创建文件夹
|
|
21
|
+
* @param {Fs.PathLike} path 路径
|
|
22
|
+
* @param {Fs.MakeDirectoryOptions?} options 选项
|
|
23
|
+
* @returns {Promise<void>}
|
|
24
|
+
*/
|
|
25
|
+
mkdir: promisify(Fs.mkdir),
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 读取文件夹
|
|
29
|
+
* @param {Fs.PathLike} path 路径
|
|
30
|
+
* @param {any} options 选项
|
|
31
|
+
* @returns {Promise<string[]>}
|
|
32
|
+
*/
|
|
33
|
+
readdir: promisify(Fs.readdir),
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 移除文件夹
|
|
37
|
+
* @param {Fs.PathLike} path 路径
|
|
38
|
+
* @param {Fs.RmDirOptions?} options 选项
|
|
39
|
+
* @returns {Promise<void>}
|
|
40
|
+
*/
|
|
41
|
+
rmdir: promisify(Fs.rmdir),
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* 读取文件
|
|
45
|
+
* @param {Fs.PathLike} path 路径
|
|
46
|
+
* @param {any} options 选项
|
|
47
|
+
* @returns {Promise<Buffer>}
|
|
48
|
+
*/
|
|
49
|
+
readFile: promisify(Fs.readFile),
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* 创建文件
|
|
53
|
+
* @param {Fs.PathLike} path 路径
|
|
54
|
+
* @param {string | NodeJS.ArrayBufferView} data 数据
|
|
55
|
+
* @param {Fs.WriteFileOptions?} options 选项
|
|
56
|
+
* @returns {Promise<void>}
|
|
57
|
+
*/
|
|
58
|
+
writeFile: promisify(Fs.writeFile),
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* 移除文件
|
|
62
|
+
* @param {Fs.PathLike} path 路径
|
|
63
|
+
* @returns {Promise<void>}
|
|
64
|
+
*/
|
|
65
|
+
unlink: promisify(Fs.unlink),
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 测试路径是否存在 (同步)
|
|
69
|
+
* @param {Fs.PathLike} path 路径
|
|
70
|
+
*/
|
|
71
|
+
existsSync: Fs.existsSync,
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* 复制文件/文件夹
|
|
75
|
+
* @param {Fs.PathLike} srcPath 源路径
|
|
76
|
+
* @param {Fs.PathLike} destPath 目标路径
|
|
77
|
+
* @returns {Promise<boolean>}
|
|
78
|
+
*/
|
|
79
|
+
async copy(srcPath, destPath) {
|
|
80
|
+
if (!FileUtil.existsSync(srcPath)) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
const stats = await FileUtil.stat(srcPath);
|
|
84
|
+
if (stats.isDirectory()) {
|
|
85
|
+
if (!FileUtil.existsSync(destPath)) {
|
|
86
|
+
await FileUtil.createDir(destPath);
|
|
87
|
+
}
|
|
88
|
+
const names = await FileUtil.readdir(srcPath);
|
|
89
|
+
for (const name of names) {
|
|
90
|
+
await FileUtil.copy(Path.join(srcPath, name), Path.join(destPath, name));
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
await FileUtil.writeFile(destPath, await FileUtil.readFile(srcPath));
|
|
94
|
+
}
|
|
95
|
+
return true;
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* 创建文件夹 (递归)
|
|
100
|
+
* @param {Fs.PathLike} path 路径
|
|
101
|
+
* @returns {Promise<boolean>}
|
|
102
|
+
*/
|
|
103
|
+
async createDir(path) {
|
|
104
|
+
if (FileUtil.existsSync(path)) {
|
|
105
|
+
return true;
|
|
106
|
+
} else {
|
|
107
|
+
const dir = Path.dirname(path);
|
|
108
|
+
if (await FileUtil.createDir(dir)) {
|
|
109
|
+
await FileUtil.mkdir(path);
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return false;
|
|
114
|
+
},
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* 移除文件/文件夹 (递归)
|
|
118
|
+
* @param {Fs.PathLike} path 路径
|
|
119
|
+
*/
|
|
120
|
+
async remove(path) {
|
|
121
|
+
if (!FileUtil.existsSync(path)) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const stats = await FileUtil.stat(path);
|
|
125
|
+
if (stats.isDirectory()) {
|
|
126
|
+
const names = await FileUtil.readdir(path);
|
|
127
|
+
for (const name of names) {
|
|
128
|
+
await FileUtil.remove(Path.join(path, name));
|
|
129
|
+
}
|
|
130
|
+
await FileUtil.rmdir(path);
|
|
131
|
+
} else {
|
|
132
|
+
await FileUtil.unlink(path);
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* 遍历文件/文件夹并执行函数
|
|
138
|
+
* @param {Fs.PathLike} path 路径
|
|
139
|
+
* @param {(filePath: Fs.PathLike, stat: Fs.Stats) => void | Promise<void>} handler 处理函数
|
|
140
|
+
*/
|
|
141
|
+
async map(path, handler) {
|
|
142
|
+
if (!FileUtil.existsSync(path)) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const stats = await FileUtil.stat(path);
|
|
146
|
+
if (stats.isDirectory()) {
|
|
147
|
+
const names = await FileUtil.readdir(path);
|
|
148
|
+
for (const name of names) {
|
|
149
|
+
await FileUtil.map(Path.join(path, name), handler);
|
|
150
|
+
}
|
|
151
|
+
} else {
|
|
152
|
+
await handler(path, stats);
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
module.exports = FileUtil;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const zh = require('../../i18n/zh');
|
|
2
|
+
const en = require('../../i18n/en');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 多语言
|
|
6
|
+
* @author 陈皮皮 (ifaswind)
|
|
7
|
+
* @version 20210713
|
|
8
|
+
*/
|
|
9
|
+
const I18n = {
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 中文
|
|
13
|
+
*/
|
|
14
|
+
zh,
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 英文
|
|
18
|
+
*/
|
|
19
|
+
en,
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 多语言文本
|
|
23
|
+
* @param {string} lang 语言
|
|
24
|
+
* @param {string} key 关键字
|
|
25
|
+
* @returns {string}
|
|
26
|
+
*/
|
|
27
|
+
translate(lang, key) {
|
|
28
|
+
if (I18n[lang] && I18n[lang][key]) {
|
|
29
|
+
return I18n[lang][key];
|
|
30
|
+
}
|
|
31
|
+
return key;
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
module.exports = I18n;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
const { ipcMain } = require('electron');
|
|
2
|
+
const PackageUtil = require('./package-util');
|
|
3
|
+
|
|
4
|
+
/** 包名 */
|
|
5
|
+
const PACKAGE_NAME = PackageUtil.name;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 主进程 IPC 事件
|
|
9
|
+
* @author 陈皮皮 (ifaswind)
|
|
10
|
+
* @version 20210818
|
|
11
|
+
*/
|
|
12
|
+
const MainEvent = {
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 监听事件(一次性)
|
|
16
|
+
* @param {string} channel 频道
|
|
17
|
+
* @param {Function} callback 回调
|
|
18
|
+
*/
|
|
19
|
+
once(channel, callback) {
|
|
20
|
+
return ipcMain.once(`${PACKAGE_NAME}:${channel}`, callback);
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 监听事件
|
|
25
|
+
* @param {string} channel 频道
|
|
26
|
+
* @param {Function} callback 回调
|
|
27
|
+
*/
|
|
28
|
+
on(channel, callback) {
|
|
29
|
+
return ipcMain.on(`${PACKAGE_NAME}:${channel}`, callback);
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 取消事件监听
|
|
34
|
+
* @param {string} channel 频道
|
|
35
|
+
* @param {Function} callback 回调
|
|
36
|
+
*/
|
|
37
|
+
removeListener(channel, callback) {
|
|
38
|
+
return ipcMain.removeListener(`${PACKAGE_NAME}:${channel}`, callback);
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 取消事件的所有监听
|
|
43
|
+
* @param {string} channel 频道
|
|
44
|
+
*/
|
|
45
|
+
removeAllListeners(channel) {
|
|
46
|
+
return ipcMain.removeAllListeners(`${PACKAGE_NAME}:${channel}`);
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 发送事件到指定渲染进程
|
|
51
|
+
* @param {Electron.WebContents} webContents 渲染进程事件对象
|
|
52
|
+
* @param {string} channel 频道
|
|
53
|
+
* @param {any[]?} args 参数
|
|
54
|
+
*/
|
|
55
|
+
send(webContents, channel) {
|
|
56
|
+
// return webContents.send(`${PACKAGE_NAME}:${channel}`, ...args);
|
|
57
|
+
const args = [`${PACKAGE_NAME}:${channel}`];
|
|
58
|
+
for (let i = 2, l = arguments.length; i < l; i++) {
|
|
59
|
+
args.push(arguments[i]);
|
|
60
|
+
}
|
|
61
|
+
return webContents.send.apply(webContents, args);
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* 回复事件给渲染进程
|
|
66
|
+
* @param {Electron.IpcMainEvent} ipcMainEvent 事件对象
|
|
67
|
+
* @param {string} channel 频道
|
|
68
|
+
* @param {any[]?} args 参数
|
|
69
|
+
*/
|
|
70
|
+
reply(ipcMainEvent, channel) {
|
|
71
|
+
// return ipcMainEvent.reply(`${PACKAGE_NAME}:${channel}`, ...args);
|
|
72
|
+
const args = [`${PACKAGE_NAME}:${channel}`];
|
|
73
|
+
for (let i = 2, l = arguments.length; i < l; i++) {
|
|
74
|
+
args.push(arguments[i]);
|
|
75
|
+
}
|
|
76
|
+
return ipcMainEvent.reply.apply(ipcMainEvent, args);
|
|
77
|
+
},
|
|
78
|
+
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
module.exports = MainEvent;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const { shell } = require('electron');
|
|
2
|
+
|
|
3
|
+
/** 包信息 */
|
|
4
|
+
const PACKAGE_JSON = require('../../package.json');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 包工具
|
|
8
|
+
* @author 陈皮皮 (ifaswind)
|
|
9
|
+
* @version 20210908
|
|
10
|
+
*/
|
|
11
|
+
const PackageUtil = {
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 包名
|
|
15
|
+
* @type {string}
|
|
16
|
+
*/
|
|
17
|
+
get name() {
|
|
18
|
+
return PACKAGE_JSON.name;
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 版本
|
|
23
|
+
* @type {string}
|
|
24
|
+
*/
|
|
25
|
+
get version() {
|
|
26
|
+
return PACKAGE_JSON.version;
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 仓库地址
|
|
31
|
+
* @type {string}
|
|
32
|
+
*/
|
|
33
|
+
get repository() {
|
|
34
|
+
return PACKAGE_JSON.repository;
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* 打开仓库页面
|
|
39
|
+
*/
|
|
40
|
+
openRepository() {
|
|
41
|
+
const url = PackageUtil.repository;
|
|
42
|
+
shell.openExternal(url);
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
module.exports = PackageUtil;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
const { ipcRenderer } = require('electron');
|
|
2
|
+
const PackageUtil = require('./package-util');
|
|
3
|
+
|
|
4
|
+
/** 包名 */
|
|
5
|
+
const PACKAGE_NAME = PackageUtil.name;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 渲染进程 IPC 事件
|
|
9
|
+
* @author 陈皮皮 (ifaswind)
|
|
10
|
+
* @version 20210818
|
|
11
|
+
*/
|
|
12
|
+
const RendererEvent = {
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 监听事件(一次性)
|
|
16
|
+
* @param {string} channel 频道
|
|
17
|
+
* @param {Function} callback 回调
|
|
18
|
+
*/
|
|
19
|
+
once(channel, callback) {
|
|
20
|
+
return ipcRenderer.once(`${PACKAGE_NAME}:${channel}`, callback);
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 监听事件
|
|
25
|
+
* @param {string} channel 频道
|
|
26
|
+
* @param {Function} callback 回调
|
|
27
|
+
*/
|
|
28
|
+
on(channel, callback) {
|
|
29
|
+
return ipcRenderer.on(`${PACKAGE_NAME}:${channel}`, callback);
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 取消事件监听
|
|
34
|
+
* @param {string} channel 频道
|
|
35
|
+
* @param {Function} callback 回调
|
|
36
|
+
*/
|
|
37
|
+
removeListener(channel, callback) {
|
|
38
|
+
return ipcRenderer.removeListener(`${PACKAGE_NAME}:${channel}`, callback);
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 取消事件的所有监听
|
|
43
|
+
* @param {string} channel 频道
|
|
44
|
+
*/
|
|
45
|
+
removeAllListeners(channel) {
|
|
46
|
+
return ipcRenderer.removeAllListeners(`${PACKAGE_NAME}:${channel}`);
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 发送事件到主进程
|
|
51
|
+
* @param {string} channel 频道
|
|
52
|
+
* @param {...any} args 参数
|
|
53
|
+
*/
|
|
54
|
+
send(channel) {
|
|
55
|
+
// return ipcRenderer.send(`${PACKAGE_NAME}:${channel}`, ...args);
|
|
56
|
+
const args = [`${PACKAGE_NAME}:${channel}`];
|
|
57
|
+
for (let i = 1, l = arguments.length; i < l; i++) {
|
|
58
|
+
args.push(arguments[i]);
|
|
59
|
+
}
|
|
60
|
+
return ipcRenderer.send.apply(ipcRenderer, args);
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 发送事件到主进程(同步)
|
|
65
|
+
* @param {string} channel 频道
|
|
66
|
+
* @param {...any} args 参数
|
|
67
|
+
* @returns {Promise<any>}
|
|
68
|
+
*/
|
|
69
|
+
sendSync(channel) {
|
|
70
|
+
// return ipcRenderer.sendSync(`${PACKAGE_NAME}:${channel}`, ...args);
|
|
71
|
+
const args = [`${PACKAGE_NAME}:${channel}`];
|
|
72
|
+
for (let i = 1, l = arguments.length; i < l; i++) {
|
|
73
|
+
args.push(arguments[i]);
|
|
74
|
+
}
|
|
75
|
+
return ipcRenderer.sendSync.apply(ipcRenderer, args);
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
module.exports = RendererEvent;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
const fetch = require('../../lib/node-fetch');
|
|
2
|
+
const PackageUtil = require('./package-util');
|
|
3
|
+
const { compareVersion } = require('./version-util');
|
|
4
|
+
|
|
5
|
+
/** 本地版本 */
|
|
6
|
+
const LOCAL_VERSION = PackageUtil.version;
|
|
7
|
+
|
|
8
|
+
/** 远程仓库地址 */
|
|
9
|
+
const REMOTE_URL = PackageUtil.repository;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 更新器
|
|
13
|
+
* @author 陈皮皮 (ifaswind)
|
|
14
|
+
* @version 20210804
|
|
15
|
+
*/
|
|
16
|
+
const Updater = {
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 远程仓库地址
|
|
20
|
+
* @type {string}
|
|
21
|
+
*/
|
|
22
|
+
get remote() {
|
|
23
|
+
return REMOTE_URL;
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 分支
|
|
28
|
+
* @type {string}
|
|
29
|
+
*/
|
|
30
|
+
branch: 'master',
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 获取远端的 package.json
|
|
34
|
+
* @returns {Promise<object>}
|
|
35
|
+
*/
|
|
36
|
+
async getRemotePackageJson() {
|
|
37
|
+
const packageJsonUrl = `${Updater.remote}/raw/${Updater.branch}/package.json`;
|
|
38
|
+
// 发起网络请求
|
|
39
|
+
const response = await fetch(packageJsonUrl, {
|
|
40
|
+
method: 'GET',
|
|
41
|
+
cache: 'no-cache',
|
|
42
|
+
mode: 'no-cors',
|
|
43
|
+
});
|
|
44
|
+
// 请求结果
|
|
45
|
+
if (response.status !== 200) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
// 读取 json
|
|
49
|
+
const json = response.json();
|
|
50
|
+
return json;
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 获取远端版本号
|
|
55
|
+
* @returns {Promise<string>}
|
|
56
|
+
*/
|
|
57
|
+
async getRemoteVersion() {
|
|
58
|
+
const package = await Updater.getRemotePackageJson();
|
|
59
|
+
if (package && package.version) {
|
|
60
|
+
return package.version;
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* 获取本地版本号
|
|
67
|
+
* @returns {string}
|
|
68
|
+
*/
|
|
69
|
+
getLocalVersion() {
|
|
70
|
+
return LOCAL_VERSION;
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* 检查远端是否有新版本
|
|
75
|
+
* @returns {Promise<boolean>}
|
|
76
|
+
*/
|
|
77
|
+
async check() {
|
|
78
|
+
// 远端版本号
|
|
79
|
+
const remoteVersion = await Updater.getRemoteVersion();
|
|
80
|
+
if (!remoteVersion) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
// 本地版本号
|
|
84
|
+
const localVersion = Updater.getLocalVersion();
|
|
85
|
+
// 对比版本号
|
|
86
|
+
const result = compareVersion(localVersion, remoteVersion);
|
|
87
|
+
return (result < 0);
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
module.exports = Updater;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 版本工具
|
|
3
|
+
* @author 陈皮皮 (ifaswind)
|
|
4
|
+
* @version 20210814
|
|
5
|
+
*/
|
|
6
|
+
const VersionUtil = {
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 拆分版本号
|
|
10
|
+
* @param {string | number} version 版本号文本
|
|
11
|
+
* @returns {number[]}
|
|
12
|
+
* @example
|
|
13
|
+
* splitVersionString('1.2.0'); // [1, 2, 0]
|
|
14
|
+
*/
|
|
15
|
+
splitVersionString(version) {
|
|
16
|
+
if (typeof version === 'number') {
|
|
17
|
+
return [version];
|
|
18
|
+
}
|
|
19
|
+
if (typeof version === 'string') {
|
|
20
|
+
return (
|
|
21
|
+
version.replace(/-/g, '.')
|
|
22
|
+
.split('.')
|
|
23
|
+
.map(v => (parseInt(v) || 0))
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
return [0];
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 对比版本号
|
|
31
|
+
* @param {string | number} a 版本 a
|
|
32
|
+
* @param {string | number} b 版本 b
|
|
33
|
+
* @returns {-1 | 0 | 1}
|
|
34
|
+
* @example
|
|
35
|
+
* compareVersion('1.0.0', '1.0.1'); // -1
|
|
36
|
+
* compareVersion('1.1.0', '1.1.0'); // 0
|
|
37
|
+
* compareVersion('1.2.1', '1.2.0'); // 1
|
|
38
|
+
* compareVersion('1.2.0.1', '1.2.0'); // 1
|
|
39
|
+
*/
|
|
40
|
+
compareVersion(a, b) {
|
|
41
|
+
const acs = VersionUtil.splitVersionString(a),
|
|
42
|
+
bcs = VersionUtil.splitVersionString(b);
|
|
43
|
+
const count = Math.max(acs.length, bcs.length);
|
|
44
|
+
for (let i = 0; i < count; i++) {
|
|
45
|
+
const ac = acs[i],
|
|
46
|
+
bc = bcs[i];
|
|
47
|
+
// 前者缺少分量或前者小于后者
|
|
48
|
+
if (ac == undefined || ac < bc) {
|
|
49
|
+
return -1;
|
|
50
|
+
}
|
|
51
|
+
// 后者缺少分量或前者大于后者
|
|
52
|
+
if (bc == undefined || ac > bc) {
|
|
53
|
+
return 1;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return 0;
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
module.exports = VersionUtil;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
const { BrowserWindow } = require('electron');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 窗口工具(主进程)
|
|
5
|
+
* @author 陈皮皮 (ifaswind)
|
|
6
|
+
* @version 20210825
|
|
7
|
+
*/
|
|
8
|
+
const WindowUtil = {
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 最先打开的窗口
|
|
12
|
+
* @returns {BrowserWindow}
|
|
13
|
+
*/
|
|
14
|
+
getFirstWindow() {
|
|
15
|
+
const wins = BrowserWindow.getAllWindows();
|
|
16
|
+
return wins[wins.length - 1];
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 获取当前聚焦的窗口
|
|
21
|
+
* @returns {BrowserWindow}
|
|
22
|
+
*/
|
|
23
|
+
getFocusedWindow() {
|
|
24
|
+
return BrowserWindow.getFocusedWindow();
|
|
25
|
+
},
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 计算窗口位置(相对于最先打开的窗口)
|
|
29
|
+
* @param {[number, number]} size 窗口尺寸
|
|
30
|
+
* @param {'top' | 'center'} anchor 锚点
|
|
31
|
+
* @returns {[number, number]}
|
|
32
|
+
*/
|
|
33
|
+
calcWindowPosition(size, anchor) {
|
|
34
|
+
const win = WindowUtil.getFirstWindow();
|
|
35
|
+
return WindowUtil.calcWindowPositionByTarget(size, anchor, win);
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 计算窗口位置(相对于当前聚焦的窗口)
|
|
40
|
+
* @param {[number, number]} size 窗口尺寸
|
|
41
|
+
* @param {'top' | 'center'} anchor 锚点
|
|
42
|
+
* @returns {[number, number]}
|
|
43
|
+
*/
|
|
44
|
+
calcWindowPositionByFocused(size, anchor) {
|
|
45
|
+
const win = WindowUtil.getFocusedWindow();
|
|
46
|
+
return WindowUtil.calcWindowPositionByTarget(size, anchor, win);
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 计算窗口位置(相对于当前聚焦的窗口)
|
|
51
|
+
* @param {[number, number]} size 窗口尺寸
|
|
52
|
+
* @param {'top' | 'center'} anchor 锚点
|
|
53
|
+
* @param {BrowserWindow} win 目标窗口
|
|
54
|
+
* @returns {[number, number]}
|
|
55
|
+
*/
|
|
56
|
+
calcWindowPositionByTarget(size, anchor, win) {
|
|
57
|
+
// 根据目标窗口的位置和尺寸来计算
|
|
58
|
+
const winSize = win.getSize(),
|
|
59
|
+
winPos = win.getPosition();
|
|
60
|
+
// 注意:原点 (0, 0) 在屏幕左上角
|
|
61
|
+
// 另外,窗口的位置值必须是整数,否则修改无效(像素的最小粒度为 1)
|
|
62
|
+
const x = Math.floor(winPos[0] + (winSize[0] / 2) - (size[0] / 2));
|
|
63
|
+
let y;
|
|
64
|
+
switch (anchor) {
|
|
65
|
+
case 'top': {
|
|
66
|
+
y = Math.floor(winPos[1]);
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
default:
|
|
70
|
+
case 'center': {
|
|
71
|
+
y = Math.floor(winPos[1] + (winSize[1] / 2) - (size[1] / 2));
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return [x, y];
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
module.exports = WindowUtil;
|