feat: TypeScript + Electron v2.0.0 构建系统完善

- 添加 vite.config.ts 构建配置
- 添加 tsconfig.main.json(主进程单独编译)
- 修复主进程模块化(menu/tray 使用 setQuitting)
- 修复渲染进程导入路径
- 删除旧版 JS/Web 文件(js/、electron/、sw.js、manifest.json)
- 构建验证通过:NSIS 安装包 + 便携版
This commit is contained in:
thzxx
2026-04-06 03:21:05 +08:00
parent 7ca0e33d77
commit 0ec6e902de
43 changed files with 1932 additions and 11104 deletions
+11 -2
View File
@@ -18,6 +18,10 @@ const IS_DEV = !app.isPackaged;
export let mainWindow: BrowserWindow | null = null;
export let isQuitting = false;
export function setQuitting(): void {
isQuitting = true;
}
export function getIconPath(): string {
return process.platform === 'win32' ? ICO_PATH : ICON_PATH;
}
@@ -45,7 +49,6 @@ function createMainWindow(): BrowserWindow {
backgroundColor: '#202020',
show: false,
autoHideMenuBar: true,
menuBarVisible: false,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
contextIsolation: true,
@@ -56,7 +59,13 @@ function createMainWindow(): BrowserWindow {
}
});
mainWindow.loadFile(path.join(__dirname, '..', '..', 'index.html'));
// 开发模式:从 src/renderer/ 加载;生产模式:从 dist/renderer/ 加载
const isDev = !app.isPackaged;
if (isDev) {
mainWindow.loadFile(path.join(__dirname, '..', '..', 'src', 'renderer', 'index.html'));
} else {
mainWindow.loadFile(path.join(__dirname, '..', 'renderer', 'index.html'));
}
mainWindow.setMenuBarVisibility(false);
mainWindow.once('ready-to-show', () => {
+4 -6
View File
@@ -2,8 +2,8 @@
* Metona Ollama Desktop - 原生菜单
*/
import { Menu, dialog, shell } from 'electron';
import { mainWindow, isQuitting, getIconPath } from './main.js';
import { Menu, dialog, shell, app } from 'electron';
import { mainWindow, setQuitting, getIconPath } from './main.js';
export function createMenu(): void {
const template: Electron.MenuItemConstructorOptions[] = [
@@ -30,8 +30,7 @@ export function createMenu(): void {
label: '退出',
accelerator: 'Ctrl+Q',
click: () => {
const { app } = require('electron');
(require('./main.js') as Record<string, unknown>).isQuitting = true;
setQuitting();
app.quit();
}
}
@@ -112,8 +111,7 @@ export function createMenu(): void {
}
];
const IS_DEV = !require('electron').app.isPackaged;
if (IS_DEV) {
if (!app.isPackaged) {
template.push({
label: 'Dev',
submenu: [
+4 -5
View File
@@ -2,8 +2,8 @@
* Metona Ollama Desktop - 系统托盘
*/
import { Tray, Menu, nativeImage } from 'electron';
import { mainWindow, isQuitting, getIconPath } from './main.js';
import { Tray, Menu, nativeImage, app } from 'electron';
import { mainWindow, setQuitting, getIconPath } from './main.js';
let tray: Tray | null = null;
@@ -32,9 +32,8 @@ export function createTray(): void {
{
label: '退出',
click: () => {
const main = require('./main.js');
main.isQuitting = true;
require('electron').app.quit();
setQuitting();
app.quit();
}
}
]);
+1 -1
View File
@@ -5,7 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="theme-color" content="#202020">
<meta name="description" content="Metona Ollama Desktop - TypeScript + Electron AI 聊天客户端">
<link rel="icon" href="../assets/icons/llama.ico" type="image/x-icon">
<link rel="icon" href="/assets/icons/llama.ico" type="image/x-icon">
<title>Metona Ollama</title>
</head>
<body>
+1 -2
View File
@@ -3,8 +3,7 @@
* 负责初始化所有组件、协调事件流、管理生命周期
*/
import '../styles/style.css';
import './types.js';
import './styles/style.css';
import { ChatDB } from './db/chat-db.js';
import { OllamaAPI } from './api/ollama.js';