This commit is contained in:
2025-10-14 02:59:27 +08:00
commit 424eb9384f
8 changed files with 3099 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
node_modules
dist

8
.npmrc Normal file
View File

@@ -0,0 +1,8 @@
# Electron 镜像(淘宝)
electron_mirror=https://npmmirror.com/mirrors/electron/
# Electron Builder 二进制镜像(如果用了 electron-builder
electron_builder_binaries_mirror=https://npmmirror.com/mirrors/electron-builder-binaries/
# 可选:设置 node-gyp 等构建工具镜像
registry=https://registry.npmmirror.com

20
bun.config.ts Normal file
View File

@@ -0,0 +1,20 @@
// @ts-check
import { resolvePath } from '@kevisual/use-config';
import { execSync } from 'node:child_process';
const entry = 'src/index.ts';
const naming = 'app';
const external = ['electron'];
await Bun.build({
target: 'node',
format: 'esm',
entrypoints: [resolvePath(entry, { meta: import.meta })],
outdir: resolvePath('./dist', { meta: import.meta }),
naming: {
entry: `${naming}.js`,
},
sourcemap: 'external',
external,
env: 'KEVISUAL_*',
});

10
index.html Normal file
View File

@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Electron Template</title>
</head>
<body>
<h1>Hello Electron!</h1>
</body>
</html>

30
package.json Normal file
View File

@@ -0,0 +1,30 @@
{
"name": "electron-template",
"version": "0.0.1",
"description": "",
"main": "dist/app.js",
"scripts": {
"build": "bun bun.config.ts",
"dev": " electron .",
"start": "pnpm build && electron .",
"build:mac": "electron-builder --mac --universal",
"build:win": "electron-builder --win",
"build:linux": "electron-builder --linux"
},
"keywords": [],
"author": "abearxiong <xiongxiao@xiongxiao.me> (https://www.xiongxiao.me)",
"license": "MIT",
"type": "module",
"devDependencies": {
"@kevisual/use-config": "^1.0.19",
"@types/bun": "^1.3.0",
"@types/node": "^22.15.21",
"bun": "^1.3.0",
"cross-env": "^10.1.0",
"electron": "38.2.2",
"electron-builder": "^26.0.12",
"electron-builder-squirrel-windows": "^26.0.12",
"electron-log": "^5.4.0",
"typescript": "^5.8.3"
}
}

2965
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

4
pnpm-workspace.yaml Normal file
View File

@@ -0,0 +1,4 @@
onlyBuiltDependencies:
- bun
- electron
- electron-winstaller

59
src/index.ts Normal file
View File

@@ -0,0 +1,59 @@
import { WebContentsView } from 'electron';
import { app, BrowserWindow } from 'electron';
import path from 'path';
app.commandLine.appendSwitch('--ignore-certificate-errors');
app.commandLine.appendSwitch('--ignore-ssl-errors');
app.commandLine.appendSwitch('--ignore-certificate-errors-spki-list');
const createBase = () => {
var win = new BrowserWindow({
width: 800, height: 400,
webPreferences: {
nodeIntegration: true,
webSecurity: false,
contextIsolation: false,
// 添加允许运行不安全内容
allowRunningInsecureContent: true,
},
});
var view1 = new WebContentsView();
win.contentView.addChildView(view1);
view1.webContents.loadURL('https://www.kevisual.cn');
view1.setBounds({ x: 0, y: 0, width: 400, height: 400 });
var view2 = new WebContentsView();
win.contentView.addChildView(view2);
view2.webContents.loadURL('https://www.xiongxiao.me');
view2.setBounds({ x: 400, y: 0, width: 400, height: 400 });
};
const createWindow = () => {
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
webSecurity: false,
contextIsolation: false,
},
});
mainWindow.loadFile('index.html');
};
app.on('certificate-error', (event, webContents, url, error, certificate, callback) => {
// 开发环境下忽略证书错误
event.preventDefault();
callback(true);
});
app.whenReady().then(() => {
// createWindow();
createBase();
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) createWindow();
});
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit();
});