-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
3,317 additions
and
2,197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"chrome":"126","node":"20"} | ||
{ "chrome": "128", "node": "20" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# 测试环境配置 | ||
NODE_ENV=development | ||
VITE_APP_VERSION=0.2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# 生产环境配置 | ||
NODE_ENV=production | ||
VITE_APP_VERSION=0.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
provider: generic | ||
url: 'http://localhost:8080' | ||
# url: 'https://lumibrowser-test.oss-cn-shenzhen.aliyuncs.com/public/package/app/Windows/64/1.5.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
"use strict"; | ||
const electron = require("electron"); | ||
const node_path = require("node:path"); | ||
class IPCMain { | ||
channel; | ||
listeners = {}; | ||
constructor(channel = "IPC-bridge") { | ||
this.channel = channel; | ||
this.bindMessage(); | ||
} | ||
on(name, fn) { | ||
console.log("on", name); | ||
if (this.listeners[name]) | ||
throw new Error(`消息处理器 ${String(name)} 已存在`); | ||
this.listeners[name] = fn; | ||
} | ||
off(action) { | ||
if (this.listeners[action]) { | ||
delete this.listeners[action]; | ||
} | ||
} | ||
async send(name, ...payload) { | ||
const windows = electron.BrowserWindow.getAllWindows(); | ||
windows.forEach((window) => { | ||
window.webContents.send(this.channel, { | ||
name, | ||
payload | ||
}); | ||
}); | ||
} | ||
bindMessage() { | ||
electron.ipcMain.handle(this.channel, this.handleReceivingMessage.bind(this)); | ||
} | ||
async handleReceivingMessage(event, payload) { | ||
try { | ||
if (this.listeners[payload.name]) { | ||
const res = await this.listeners[payload.name](...payload.payload); | ||
return { | ||
type: "success", | ||
result: res | ||
}; | ||
} else { | ||
throw new Error(`未知的 IPC 消息 ${String(payload.name)}`); | ||
} | ||
} catch (e) { | ||
return { | ||
type: "error", | ||
error: e.toString() | ||
}; | ||
} | ||
} | ||
} | ||
const ipcMain = new IPCMain(); | ||
ipcMain.on("getUsernameById", (userID) => { | ||
console.log("getUsernameById", `User ID: ${userID}`); | ||
return "User Name"; | ||
}); | ||
setTimeout(() => { | ||
ipcMain.send("newUserJoin", 1); | ||
}, 5e3); | ||
const isPackaged = electron.app.isPackaged; | ||
process.platform === "darwin"; | ||
process.platform === "win32"; | ||
async function createWindow() { | ||
const browserWindow = new electron.BrowserWindow({ | ||
// Use 'ready-to-show' event to show window | ||
show: false, | ||
webPreferences: { | ||
// https://www.electronjs.org/docs/latest/api/webview-tag#warning | ||
webviewTag: false, | ||
preload: isPackaged ? node_path.join(__dirname, "./preload/index.cjs") : node_path.join(__dirname, "../../preload/dist/index.cjs") | ||
} | ||
}); | ||
browserWindow.on("ready-to-show", () => { | ||
browserWindow?.show(); | ||
{ | ||
browserWindow?.webContents.openDevTools({ mode: "detach" }); | ||
} | ||
}); | ||
const pageUrl = "http://localhost:5173/"; | ||
await browserWindow.loadURL(pageUrl); | ||
return browserWindow; | ||
} | ||
async function restoreOrCreateWindow() { | ||
let window = electron.BrowserWindow.getAllWindows().find((w) => !w.isDestroyed()); | ||
if (window === void 0) { | ||
window = await createWindow(); | ||
} | ||
if (window.isMinimized()) { | ||
window.restore(); | ||
} | ||
window.focus(); | ||
} | ||
const isSingleInstance = electron.app.requestSingleInstanceLock(); | ||
if (!isSingleInstance) { | ||
electron.app.quit(); | ||
process.exit(0); | ||
} | ||
electron.app.on("second-instance", restoreOrCreateWindow); | ||
electron.app.on("window-all-closed", () => { | ||
if (process.platform !== "darwin") { | ||
electron.app.quit(); | ||
} | ||
}); | ||
electron.app.on("activate", restoreOrCreateWindow); | ||
electron.app.whenReady().then(restoreOrCreateWindow).catch((e) => console.error("Failed create window:", e)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,11 @@ | ||
import { app } from 'electron' | ||
|
||
/** 是否处于开发环境 */ | ||
export const isDev = import.meta.env.DEV | ||
/** 是否处于生产环境 */ | ||
export const isProd = import.meta.env.PROD | ||
/** 是否处于打包状态 */ | ||
export const isPackaged = app.isPackaged | ||
|
||
export const isMac = process.platform === 'darwin' | ||
export const isWindows = process.platform === 'win32' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
const path = require('node:path') | ||
const TerserPlugin = require('terser-webpack-plugin') | ||
|
||
/** @type { import('webpack').Configuration } */ | ||
module.exports = { | ||
mode: 'production', // 或者 'development' | ||
target: 'electron-main', // 目标环境设置为 Node.js | ||
entry: { | ||
main: './dist-vite/index.cjs', | ||
// extensionWorker: './dist-vite/extensionWorker.cjs', | ||
}, | ||
output: { | ||
path: path.resolve(__dirname, 'dist'), // 输出目录 | ||
filename: '[name].cjs', // 使用 [name] 占位符来确保每个 chunk 有唯一的文件名 | ||
}, | ||
node: { | ||
__dirname: false, // 保持 __dirname 的原样(在 Node.js 中很重要) | ||
__filename: false, | ||
}, | ||
optimization: { | ||
minimize: true, // 启用代码压缩和混淆 | ||
minimizer: [ | ||
new TerserPlugin({ | ||
terserOptions: { | ||
compress: true, // 启用代码压缩 | ||
mangle: true, // 混淆变量名称 | ||
}, | ||
extractComments: false, // 禁止生成 LICENSE.txt 文件 | ||
}), | ||
], | ||
splitChunks: { | ||
chunks: 'all', // 对所有类型的代码进行分割 | ||
cacheGroups: { | ||
defaultVendors: { | ||
test: /[\\/]node_modules[\\/]/, | ||
name: 'vendors', | ||
chunks: 'all', | ||
}, | ||
common: { | ||
name: 'common', | ||
minChunks: 2, // 至少两个 chunk 共享的模块会被提取到 common chunk 中 | ||
priority: -10, | ||
reuseExistingChunk: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
// module: { | ||
// rules: [ | ||
// { | ||
// test: /\.js$/, | ||
// exclude: /node_modules/, | ||
// use: 'babel-loader', // 如果需要转换现代 JavaScript 语法 | ||
// }, | ||
// ], | ||
// }, | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
Chrome 126 | ||
Chrome 128 |
Oops, something went wrong.