@zwa73/dev-utils 1.0.61 → 1.0.62
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.
@@ -1,5 +1,5 @@
|
|
1
|
-
import { app, BrowserWindow, ipcMain, IpcMainInvokeEvent } from
|
2
|
-
import { FuncObj } from
|
1
|
+
import { app, BrowserWindow, ipcMain, IpcMainInvokeEvent, nativeTheme } from "electron";
|
2
|
+
import { FuncObj } from "./Static";
|
3
3
|
// This allows TypeScript to pick up the magic constants that's auto-generated by Forge's Webpack
|
4
4
|
// plugin that tells the Electron app where to look for the Webpack-bundled app code (depending on
|
5
5
|
// whether you're running in development or production).
|
@@ -7,86 +7,79 @@ declare const MAIN_WINDOW_WEBPACK_ENTRY: string;
|
|
7
7
|
declare const MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY: string;
|
8
8
|
|
9
9
|
// Handle creating/removing shortcuts on Windows when installing/uninstalling.
|
10
|
-
if (require(
|
11
|
-
|
10
|
+
if (require("electron-squirrel-startup")) {
|
11
|
+
app.quit();
|
12
12
|
}
|
13
13
|
|
14
14
|
const createWindow = (): void => {
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
},
|
24
|
-
});
|
25
|
-
|
26
|
-
mainWindow.webContents.session.webRequest.onHeadersReceived((details, callback) => {
|
27
|
-
callback({
|
28
|
-
responseHeaders: {
|
29
|
-
...details.responseHeaders,
|
30
|
-
"Content-Security-Policy": [],
|
15
|
+
// Create the browser window.
|
16
|
+
const mainWindow = new BrowserWindow({
|
17
|
+
height: 600,
|
18
|
+
width: 800,
|
19
|
+
webPreferences: {
|
20
|
+
preload: MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY,
|
21
|
+
webSecurity: false,
|
22
|
+
allowRunningInsecureContent: true,
|
31
23
|
},
|
32
24
|
});
|
33
|
-
});
|
34
25
|
|
35
|
-
|
36
|
-
|
26
|
+
mainWindow.webContents.session.webRequest.onHeadersReceived((details, callback) => {
|
27
|
+
callback({
|
28
|
+
responseHeaders: {
|
29
|
+
...details.responseHeaders,
|
30
|
+
"Content-Security-Policy": [],
|
31
|
+
},
|
32
|
+
});
|
33
|
+
});
|
34
|
+
|
35
|
+
// and load the index.html of the app.
|
36
|
+
void mainWindow.loadURL(MAIN_WINDOW_WEBPACK_ENTRY);
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
}
|
49
|
-
})();
|
50
|
-
`);
|
51
|
-
});
|
52
|
-
mainWindow.webContents.openDevTools();
|
38
|
+
// Open the DevTools.
|
39
|
+
mainWindow.webContents.openDevTools();
|
40
|
+
mainWindow.webContents.on("devtools-opened", () => {
|
41
|
+
// First, set the theme to 'light'
|
42
|
+
nativeTheme.themeSource = "light";
|
43
|
+
// After a short delay, set it to 'dark'
|
44
|
+
setTimeout(() => {
|
45
|
+
nativeTheme.themeSource = "system";
|
46
|
+
}, 100); // 100ms delay; adjust if necessary
|
47
|
+
});
|
53
48
|
};
|
54
49
|
|
55
50
|
// This method will be called when Electron has finished
|
56
51
|
// initialization and is ready to create browser windows.
|
57
52
|
// Some APIs can only be used after this event occurs.
|
58
|
-
app.on(
|
59
|
-
|
53
|
+
app.on("ready", createWindow);
|
60
54
|
|
61
55
|
//#region function define
|
62
|
-
Object.entries(FuncObj).forEach(([k, v]) =>
|
63
|
-
ipcMain.handle(k, v);
|
64
|
-
});
|
56
|
+
Object.entries(FuncObj).forEach(([k, v]) => ipcMain.handle(k, v));
|
65
57
|
|
66
|
-
type RemoveFirstArg<T> = T extends (arg1: IpcMainInvokeEvent, ...args: infer Rest) => infer R
|
58
|
+
type RemoveFirstArg<T> = T extends (arg1: IpcMainInvokeEvent, ...args: infer Rest) => infer R
|
59
|
+
? (...args: Rest) => R
|
60
|
+
: T;
|
67
61
|
|
68
62
|
export type Bridge = {
|
69
|
-
|
70
|
-
|
71
|
-
|
63
|
+
[P in keyof FuncObj]: FuncObj[P] extends (...args: infer Arg) => infer Out
|
64
|
+
? RemoveFirstArg<(...args: Arg) => Promise<Out>>
|
65
|
+
: never;
|
72
66
|
};
|
73
67
|
//#endregion
|
74
68
|
|
75
69
|
// Quit when all windows are closed, except on macOS. There, it's common
|
76
70
|
// for applications and their menu bar to stay active until the user quits
|
77
71
|
// explicitly with Cmd + Q.
|
78
|
-
app.on(
|
79
|
-
|
80
|
-
|
81
|
-
|
72
|
+
app.on("window-all-closed", () => {
|
73
|
+
if (process.platform !== "darwin") {
|
74
|
+
app.quit();
|
75
|
+
}
|
82
76
|
});
|
83
77
|
|
84
|
-
app.on(
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
}
|
78
|
+
app.on("activate", () => {
|
79
|
+
// On OS X it's common to re-create a window in the app when the
|
80
|
+
// dock icon is clicked and there are no other windows open.
|
81
|
+
if (BrowserWindow.getAllWindows().length === 0)
|
82
|
+
createWindow();
|
90
83
|
});
|
91
84
|
|
92
85
|
// In this file you can include the rest of your app's specific main process
|
@@ -51,7 +51,7 @@ async function copyData() {
|
|
51
51
|
const CmdCreateElectronFrame = (program) => program
|
52
52
|
.command('CreateElectronFrame')
|
53
53
|
.command('createelectronframe')
|
54
|
-
.description('
|
54
|
+
.description('对当前目录进行项目初始化,创建Electron基础环境')
|
55
55
|
.action(async (opt) => {
|
56
56
|
(0, RouteInterface_1.checkProject)();
|
57
57
|
utils_1.SLogger.info(`开始初始化设置当前目录 ${RouteInterface_1.PROJECT_PATH}`);
|
package/dist/Command/Route.js
CHANGED
@@ -10,6 +10,7 @@ const ScanDups_1 = require("./ScanDups");
|
|
10
10
|
const GenSchema_1 = require("./GenSchema");
|
11
11
|
const ExpandMacro_1 = require("./ExpandMacro");
|
12
12
|
const GenI18n_1 = require("./GenI18n");
|
13
|
+
const CreateElectronFrame_1 = require("./CreateElectronFrame");
|
13
14
|
async function cliRoute() {
|
14
15
|
(0, Init_1.CmdInit)(commander_1.program);
|
15
16
|
(0, Node_1.CmdNode)(commander_1.program);
|
@@ -19,5 +20,6 @@ async function cliRoute() {
|
|
19
20
|
(0, GenSchema_1.CmdGenSchema)(commander_1.program);
|
20
21
|
(0, ExpandMacro_1.CmdExpandMacro)(commander_1.program);
|
21
22
|
(0, GenI18n_1.CmdGenI18n)(commander_1.program);
|
23
|
+
(0, CreateElectronFrame_1.CmdCreateElectronFrame)(commander_1.program);
|
22
24
|
commander_1.program.parse(process.argv);
|
23
25
|
}
|
package/package.json
CHANGED
@@ -29,7 +29,7 @@ async function copyData() {
|
|
29
29
|
export const CmdCreateElectronFrame = (program:Command)=>program
|
30
30
|
.command('CreateElectronFrame')
|
31
31
|
.command('createelectronframe')
|
32
|
-
.description('
|
32
|
+
.description('对当前目录进行项目初始化,创建Electron基础环境')
|
33
33
|
.action(async (opt) => {
|
34
34
|
checkProject();
|
35
35
|
SLogger.info(`开始初始化设置当前目录 ${PROJECT_PATH}`);
|
package/src/Command/Route.ts
CHANGED
@@ -8,6 +8,7 @@ import { CmdScanDups } from './ScanDups';
|
|
8
8
|
import { CmdGenSchema } from './GenSchema';
|
9
9
|
import { CmdExpandMacro } from './ExpandMacro';
|
10
10
|
import { CmdGenI18n } from './GenI18n';
|
11
|
+
import { CmdCreateElectronFrame } from './CreateElectronFrame';
|
11
12
|
|
12
13
|
export async function cliRoute(){
|
13
14
|
CmdInit(program);
|
@@ -18,5 +19,6 @@ export async function cliRoute(){
|
|
18
19
|
CmdGenSchema(program);
|
19
20
|
CmdExpandMacro(program);
|
20
21
|
CmdGenI18n(program);
|
22
|
+
CmdCreateElectronFrame(program);
|
21
23
|
program.parse(process.argv);
|
22
24
|
}
|