mirror of
https://gitee.com/dromara/electron-egg.git
synced 2026-05-23 00:18:08 +08:00
chore: del vite
This commit is contained in:
154
electronts/config/config.default.ts
Normal file
154
electronts/config/config.default.ts
Normal file
@@ -0,0 +1,154 @@
|
||||
import path from 'path';
|
||||
import { getBaseDir } from 'ee-core/ps';
|
||||
|
||||
interface WindowOption {
|
||||
title: string;
|
||||
width: number;
|
||||
height: number;
|
||||
minWidth: number;
|
||||
minHeight: number;
|
||||
webPreferences: {
|
||||
contextIsolation: boolean;
|
||||
nodeIntegration: boolean;
|
||||
};
|
||||
frame: boolean;
|
||||
show: boolean;
|
||||
icon: string;
|
||||
}
|
||||
|
||||
interface Logger {
|
||||
level: 'INFO' | 'DEBUG' | 'WARN' | 'ERROR';
|
||||
outputJSON: boolean;
|
||||
appLogName: string;
|
||||
coreLogName: string;
|
||||
errorLogName: string;
|
||||
}
|
||||
|
||||
interface Remote {
|
||||
enable: boolean;
|
||||
url: string;
|
||||
}
|
||||
|
||||
interface SocketServer {
|
||||
enable: boolean;
|
||||
port: number;
|
||||
path: string;
|
||||
connectTimeout: number;
|
||||
pingTimeout: number;
|
||||
pingInterval: number;
|
||||
maxHttpBufferSize: number;
|
||||
transports: ('polling' | 'websocket')[];
|
||||
cors: {
|
||||
origin: boolean | string | ((origin: string, callback: (err: any, allow: boolean) => void) => void);
|
||||
};
|
||||
channel: string;
|
||||
}
|
||||
|
||||
interface HttpServer {
|
||||
enable: boolean;
|
||||
https: {
|
||||
enable: boolean;
|
||||
key: string;
|
||||
cert: string;
|
||||
};
|
||||
host: string;
|
||||
port: number;
|
||||
}
|
||||
|
||||
interface MainServer {
|
||||
indexPath: string;
|
||||
}
|
||||
|
||||
interface Customize {
|
||||
tray: {
|
||||
title: string;
|
||||
icon: string;
|
||||
};
|
||||
awaken: {
|
||||
protocol: string;
|
||||
args: any[];
|
||||
};
|
||||
}
|
||||
|
||||
interface AppConfig {
|
||||
openDevTools: boolean;
|
||||
singleLock: boolean;
|
||||
windowsOption: WindowOption;
|
||||
logger: Logger;
|
||||
remote: Remote;
|
||||
socketServer: SocketServer;
|
||||
httpServer: HttpServer;
|
||||
mainServer: MainServer;
|
||||
customize: Customize;
|
||||
}
|
||||
|
||||
const config: () => AppConfig = () => {
|
||||
return {
|
||||
openDevTools: false,
|
||||
singleLock: true,
|
||||
windowsOption: {
|
||||
title: 'electron-egg',
|
||||
width: 980,
|
||||
height: 650,
|
||||
minWidth: 400,
|
||||
minHeight: 300,
|
||||
webPreferences: {
|
||||
contextIsolation: false,
|
||||
nodeIntegration: true,
|
||||
},
|
||||
frame: true,
|
||||
show: true,
|
||||
icon: path.join(getBaseDir(), 'public', 'images', 'logo-32.png'),
|
||||
},
|
||||
logger: {
|
||||
level: 'INFO',
|
||||
outputJSON: false,
|
||||
appLogName: 'ee.log',
|
||||
coreLogName: 'ee-core.log',
|
||||
errorLogName: 'ee-error.log',
|
||||
},
|
||||
remote: {
|
||||
enable: false,
|
||||
url: 'http://electron-egg.kaka996.com/',
|
||||
},
|
||||
socketServer: {
|
||||
enable: false,
|
||||
port: 7070,
|
||||
path: "/socket.io/",
|
||||
connectTimeout: 45000,
|
||||
pingTimeout: 30000,
|
||||
pingInterval: 25000,
|
||||
maxHttpBufferSize: 1e8,
|
||||
transports: ["polling", "websocket"],
|
||||
cors: {
|
||||
origin: true,
|
||||
},
|
||||
channel: 'c1',
|
||||
},
|
||||
httpServer: {
|
||||
enable: false,
|
||||
https: {
|
||||
enable: false,
|
||||
key: '/public/ssl/localhost+1.key',
|
||||
cert: '/public/ssl/localhost+1.pem',
|
||||
},
|
||||
host: '127.0.0.1',
|
||||
port: 7071,
|
||||
},
|
||||
mainServer: {
|
||||
indexPath: '/public/dist/index.html',
|
||||
},
|
||||
customize: {
|
||||
tray: {
|
||||
title: 'EE程序',
|
||||
icon: '/public/images/tray.png',
|
||||
},
|
||||
awaken: {
|
||||
protocol: 'ee',
|
||||
args: [],
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export default config;
|
||||
25
electronts/config/config.local.ts
Normal file
25
electronts/config/config.local.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
interface OpenDevTools {
|
||||
mode: string;
|
||||
}
|
||||
|
||||
interface Jobs {
|
||||
messageLog: boolean;
|
||||
}
|
||||
|
||||
interface AppConfig {
|
||||
openDevTools: OpenDevTools;
|
||||
jobs: Jobs;
|
||||
}
|
||||
|
||||
const config: () => AppConfig = () => {
|
||||
return {
|
||||
openDevTools: {
|
||||
mode: 'bottom'
|
||||
},
|
||||
jobs: {
|
||||
messageLog: true
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export default config;
|
||||
11
electronts/config/config.prod.ts
Normal file
11
electronts/config/config.prod.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
interface AppConfig {
|
||||
openDevTools: boolean;
|
||||
}
|
||||
|
||||
const config: () => AppConfig = () => {
|
||||
return {
|
||||
openDevTools: false,
|
||||
};
|
||||
};
|
||||
|
||||
export default config;
|
||||
19
electronts/main.ts
Normal file
19
electronts/main.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { ElectronEgg } from 'ee-core';
|
||||
import { Lifecycle } from './preload/lifecycle';
|
||||
import { preload } from './preload';
|
||||
|
||||
// New app
|
||||
const app = new ElectronEgg();
|
||||
|
||||
// Register lifecycle
|
||||
const life = new Lifecycle();
|
||||
app.register("ready", life.ready);
|
||||
app.register("electron-app-ready", life.electronAppReady);
|
||||
app.register("window-ready", life.windowReady);
|
||||
app.register("before-close", life.beforeClose);
|
||||
|
||||
// Register preload
|
||||
app.register("preload", preload);
|
||||
|
||||
// Run
|
||||
app.run();
|
||||
16
electronts/preload/bridge.ts
Normal file
16
electronts/preload/bridge.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* 如果启用了上下文隔离,渲染进程无法使用electron的api,
|
||||
* 可通过contextBridge 导出api给渲染进程使用
|
||||
*/
|
||||
|
||||
import { type IpcRenderer, contextBridge, ipcRenderer } from 'electron';
|
||||
|
||||
// 确保contextBridge.exposeInMainWorld的参数类型正确,这里进行简单的类型定义示例
|
||||
type ElectronApi = {
|
||||
ipcRenderer: IpcRenderer;
|
||||
};
|
||||
|
||||
const ele: ElectronApi = {
|
||||
ipcRenderer: ipcRenderer,
|
||||
};
|
||||
contextBridge.exposeInMainWorld('electron', ele);
|
||||
12
electronts/preload/index.ts
Normal file
12
electronts/preload/index.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* Preload module, this file will be loaded when the program starts.
|
||||
*/
|
||||
function preload(): void {
|
||||
// Example feature module, optional to use and modify
|
||||
console.log('preload/index.js');
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry point of the preload module
|
||||
*/
|
||||
export { preload };
|
||||
49
electronts/preload/lifecycle.ts
Normal file
49
electronts/preload/lifecycle.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { getConfig, Config } from 'ee-core/config';
|
||||
import { getMainWindow } from 'ee-core/electron';
|
||||
|
||||
class Lifecycle {
|
||||
/**
|
||||
* Core app has been loaded
|
||||
*/
|
||||
async ready(): Promise<void> {
|
||||
// Do some things
|
||||
console.log('[lifecycle] ready');
|
||||
}
|
||||
|
||||
/**
|
||||
* Electron app is ready
|
||||
*/
|
||||
async electronAppReady(): Promise<void> {
|
||||
// Do some things
|
||||
console.log('[lifecycle] electron-app-ready');
|
||||
}
|
||||
|
||||
/**
|
||||
* Main window has been loaded
|
||||
*/
|
||||
async windowReady(): Promise<void> {
|
||||
console.log('[lifecycle] window-ready');
|
||||
// Delay loading, no white screen
|
||||
const config: Config = getConfig();
|
||||
const { windowsOption } = config;
|
||||
if (windowsOption.show === false) {
|
||||
const win = getMainWindow();
|
||||
win.once('ready-to-show', () => {
|
||||
win.show();
|
||||
win.focus();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Before app close
|
||||
*/
|
||||
async beforeClose(): Promise<void> {
|
||||
console.log('[lifecycle] before-close');
|
||||
}
|
||||
}
|
||||
|
||||
// 设置类的toString方法,虽然在TypeScript中不常见
|
||||
Lifecycle.toString = () => '[class Lifecycle]';
|
||||
|
||||
export { Lifecycle };
|
||||
35
electronts/tsconfig.json
Normal file
35
electronts/tsconfig.json
Normal file
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "esnext",
|
||||
"module": "esnext",
|
||||
"useDefineForClassFields": true,
|
||||
"skipLibCheck": true,
|
||||
"types": ["node"],
|
||||
"esModuleInterop": true,
|
||||
|
||||
// "allowJs": true,
|
||||
// "checkJs": true,
|
||||
|
||||
/* Bundler mode */
|
||||
"moduleResolution": "node", // node
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
//"noEmit": true,
|
||||
|
||||
/* Linting */
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"noImplicitAny": false,
|
||||
"noImplicitReturns": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"outDir": "../public/electron"
|
||||
},
|
||||
"include": [
|
||||
"**/*"
|
||||
],
|
||||
"exclude": [
|
||||
"tsconfig.json"
|
||||
],
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user