ref: update electron code to TypeScript
This commit is contained in:
parent
2c6c07647a
commit
ab9a51bfad
@ -8,6 +8,6 @@
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/main.tsx"></script>
|
||||
<script type="module" src="/src/web/main.tsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
10
package.json
10
package.json
@ -7,13 +7,17 @@
|
||||
"dev": "cross-env NODE_ENV=dev bun run dev:all",
|
||||
"dev:all": "concurrently -n=react,electron -c='#ff3e00',blue \"bun run dev:react\" \"bun run dev:electron\"",
|
||||
"dev:react": "vite dev",
|
||||
"dev:electron": "electron src/electron.js"
|
||||
"dev:electron": "tsc && electron dist/dev/index.js",
|
||||
"build": "cross-env NODE_ENV=production bun run build:all",
|
||||
"build:all": "concurrently -n=react,electron -c='#ff3e00',blue \"bun run build:react\" \"bun run build:electron\"",
|
||||
"build:react": "vite build",
|
||||
"build:electron": "electron-builder",
|
||||
"start": "cross-env NODE_ENV=production bun run start:all"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"electron": "^33.2.0",
|
||||
"electron-context-menu": "^4.0.4",
|
||||
"electron-reloader": "^1.2.3",
|
||||
"electron-serve": "^2.1.1",
|
||||
@ -28,12 +32,14 @@
|
||||
"vite-tsconfig-paths": "^5.1.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"electron": "^33.2.0",
|
||||
"@eslint/js": "^9.13.0",
|
||||
"@types/react": "^18.3.12",
|
||||
"@types/react-dom": "^18.3.1",
|
||||
"@vitejs/plugin-react": "^4.3.3",
|
||||
"concurrently": "^9.0.1",
|
||||
"cross-env": "^7.0.3",
|
||||
"electron-builder": "^25.1.8",
|
||||
"eslint": "^9.13.0",
|
||||
"eslint-plugin-react-hooks": "^5.0.0",
|
||||
"eslint-plugin-react-refresh": "^0.4.14",
|
||||
|
1890
pnpm-lock.yaml
1890
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
@ -15,14 +15,14 @@ function createTray() {
|
||||
label: '显示主窗口',
|
||||
click: () => {
|
||||
if (!mainWindow) createMainWindow();
|
||||
mainWindow.show();
|
||||
mainWindow!.show();
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '显示设置',
|
||||
click: () => {
|
||||
if (!settingsWindow) createSettingsWindow();
|
||||
settingsWindow.show();
|
||||
settingsWindow!.show();
|
||||
}
|
||||
},
|
||||
{ type: 'separator' },
|
||||
@ -50,8 +50,8 @@ const serveURL = serve({ directory: '.' });
|
||||
const port = process.env.PORT || "5173";
|
||||
const dev = !app.isPackaged;
|
||||
|
||||
let mainWindow;
|
||||
let settingsWindow;
|
||||
let mainWindow: BrowserWindow | null;
|
||||
let settingsWindow: BrowserWindow | null;
|
||||
|
||||
|
||||
function createSettingsWindow() {
|
||||
@ -71,7 +71,7 @@ function createSettingsWindow() {
|
||||
settingsWindow = window;
|
||||
|
||||
if (dev) loadVite(window ,port, "settings");
|
||||
else serveURL(mainWindow);
|
||||
else serveURL(mainWindow!);
|
||||
}
|
||||
|
||||
contextMenu({
|
||||
@ -80,7 +80,7 @@ contextMenu({
|
||||
showCopyImage: true,
|
||||
});
|
||||
|
||||
function loadVite(window, port, path = "") {
|
||||
function loadVite(window: BrowserWindow, port: string | undefined, path = "") {
|
||||
console.log(`http://localhost:${port}/${path}`);
|
||||
window.loadURL(`http://localhost:${port}/${path}`).catch((e) => {
|
||||
console.log('Error loading URL, retrying', e);
|
||||
@ -134,8 +134,8 @@ function createMainWindow() {
|
||||
|
||||
mainWindow = window;
|
||||
|
||||
if (dev) loadVite(port);
|
||||
else serveURL(mainWindow);
|
||||
if (dev) loadVite(window, port);
|
||||
else serveURL(mainWindow).then(()=>{});
|
||||
}
|
||||
|
||||
app.once('ready', () => {
|
||||
@ -147,6 +147,7 @@ app.on('activate', () => {
|
||||
app.on('ready', () => {
|
||||
createTray();
|
||||
globalShortcut.register('Escape', () => {
|
||||
if (!mainWindow) return;
|
||||
mainWindow.hide();
|
||||
});
|
||||
});
|
||||
@ -155,5 +156,6 @@ app.on('window-all-closed', () => {
|
||||
});
|
||||
|
||||
ipcMain.on('to-main', (_event, count) => {
|
||||
if (!mainWindow) return;
|
||||
return mainWindow.webContents.send('from-main', `next count is ${count + 1}`);
|
||||
});
|
@ -1,6 +1,6 @@
|
||||
import { StrictMode } from "react";
|
||||
import { createRoot } from "react-dom/client";
|
||||
import { App } from "./app";
|
||||
import { App } from "./app.tsx";
|
||||
import "./index.css";
|
||||
|
||||
const app = createRoot(document.getElementById("root")!);
|
@ -15,7 +15,6 @@
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"moduleDetection": "force",
|
||||
"noEmit": true,
|
||||
"jsx": "react-jsx",
|
||||
|
||||
/* Linting */
|
||||
@ -24,5 +23,5 @@
|
||||
"noUnusedParameters": true,
|
||||
"noFallthroughCasesInSwitch": true
|
||||
},
|
||||
"include": ["src", "**/*.ts", "**/*.tsx", "global.d.ts"]
|
||||
"include": ["src/web", "src/web/**/*.ts", "src/web/**/*.tsx", "global.d.ts"],
|
||||
}
|
||||
|
@ -1,5 +1,19 @@
|
||||
{
|
||||
"files": [],
|
||||
// "files": [
|
||||
// "src/electron/index.ts"
|
||||
// ],
|
||||
"compilerOptions": {
|
||||
"target": "ESNext",
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "node",
|
||||
"outDir": "./dist/dev",
|
||||
"rootDir": "./src/electron",
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"include": ["src/electron"],
|
||||
"references": [
|
||||
{ "path": "./tsconfig.app.json"},
|
||||
{ "path": "./tsconfig.node.json"}
|
||||
|
@ -5,13 +5,13 @@
|
||||
"lib": ["ES2023"],
|
||||
"module": "ESNext",
|
||||
"skipLibCheck": true,
|
||||
"composite": true,
|
||||
|
||||
/* Bundler mode */
|
||||
"moduleResolution": "Bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"isolatedModules": true,
|
||||
"moduleDetection": "force",
|
||||
"noEmit": true,
|
||||
|
||||
/* Linting */
|
||||
"strict": true,
|
||||
|
Loading…
Reference in New Issue
Block a user