mirror of
https://gitee.com/dromara/electron-egg.git
synced 2026-06-13 03:11:10 +08:00
[feat] Window adaptation screen & Using sqlite in Jobs & When double clicking the icon, display the opened window
This commit is contained in:
@@ -23,7 +23,7 @@ module.exports = () => {
|
||||
//preload: path.join(getElectronDir(), 'preload', 'bridge.js'),
|
||||
},
|
||||
frame: true,
|
||||
show: true,
|
||||
show: false,
|
||||
icon: path.join(getBaseDir(), 'public', 'images', 'logo-32.png'),
|
||||
},
|
||||
logger: {
|
||||
|
||||
@@ -5,6 +5,7 @@ const { isChildJob, exit } = require('ee-core/ps');
|
||||
const { childMessage } = require('ee-core/message');
|
||||
const { welcome } = require('./hello');
|
||||
const { UserService } = require('../../service/job/user');
|
||||
const { sqlitedbService } = require('../../service/database/sqlitedb');
|
||||
|
||||
/**
|
||||
* example - TimerJob
|
||||
@@ -12,20 +13,21 @@ const { UserService } = require('../../service/job/user');
|
||||
*/
|
||||
class TimerJob {
|
||||
|
||||
constructor(params) {
|
||||
this.params = params;
|
||||
constructor() {
|
||||
this.timer = undefined;
|
||||
this.timeoutTimer = undefined;
|
||||
this.number = 0;
|
||||
this.countdown = 10; // 倒计时
|
||||
sqlitedbService.init();
|
||||
}
|
||||
|
||||
/**
|
||||
* handle()方法是必要的,且会被自动调用
|
||||
* params 传递的参数
|
||||
*/
|
||||
async handle () {
|
||||
logger.info("[child-process] TimerJob params: ", this.params);
|
||||
const { jobId } = this.params;
|
||||
async handle(params) {
|
||||
logger.info("[child-process] TimerJob params: ", params);
|
||||
const { jobId } = params;
|
||||
|
||||
// 子进程中使用service
|
||||
// 1. 确保引入的 service 中不能有electron 的 api或依赖, electron 不支持
|
||||
@@ -33,7 +35,14 @@ class TimerJob {
|
||||
userService.hello('job');
|
||||
|
||||
// 执行任务
|
||||
// 多次运行时,重置倒计时
|
||||
this.number = 0;
|
||||
this.countdown = 10;
|
||||
this.doTimer(jobId);
|
||||
|
||||
// sqlite
|
||||
const userList = await sqlitedbService.getAllTestDataSqlite();
|
||||
logger.info('[child-process] Sqlite userList:', userList);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const { app: electronApp, screen } = require('electron');
|
||||
const { logger } = require('ee-core/log');
|
||||
const { getConfig } = require('ee-core/config');
|
||||
const { getMainWindow } = require('ee-core/electron');
|
||||
@@ -18,6 +19,16 @@ class Lifecycle {
|
||||
*/
|
||||
async electronAppReady() {
|
||||
logger.info('[lifecycle] electron-app-ready');
|
||||
|
||||
// When double clicking the icon, display the opened window
|
||||
electronApp.on('second-instance', () => {
|
||||
const win = getMainWindow();
|
||||
if (win.isMinimized()) {
|
||||
win.restore();
|
||||
}
|
||||
win.show();
|
||||
win.focus();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -25,10 +36,23 @@ class Lifecycle {
|
||||
*/
|
||||
async windowReady() {
|
||||
logger.info('[lifecycle] window-ready');
|
||||
// 延迟加载,无白屏
|
||||
|
||||
const win = getMainWindow();
|
||||
|
||||
// The window is centered and scaled proportionally
|
||||
// Obtain the size information of the main screen, calculate the width and height of the window as a percentage of the screen,
|
||||
// and calculate the coordinates of the upper left corner when the window is centered
|
||||
const mainScreen = screen.getPrimaryDisplay();
|
||||
const { width, height } = mainScreen.workAreaSize;
|
||||
const windowWidth = Math.floor(width * 0.6);
|
||||
const windowHeight = Math.floor(height * 0.8);
|
||||
const x = Math.floor((width - windowWidth) / 2);
|
||||
const y = Math.floor((height - windowHeight) / 2);
|
||||
win.setBounds({ x, y, width: windowWidth, height: windowHeight })
|
||||
|
||||
// Delayed loading, no white screen
|
||||
const { windowsOption } = getConfig();
|
||||
if (windowsOption.show == false) {
|
||||
const win = getMainWindow();
|
||||
win.once('ready-to-show', () => {
|
||||
win.show();
|
||||
win.focus();
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
"devDependencies": {
|
||||
"@electron/rebuild": "^3.7.1",
|
||||
"@types/better-sqlite3": "^7.6.12",
|
||||
"@types/node": "^22.10.2",
|
||||
"@types/node": "^20.16.0",
|
||||
"cross-env": "^7.0.3",
|
||||
"debug": "^4.4.0",
|
||||
"ee-bin": "^4.1.4",
|
||||
@@ -53,7 +53,7 @@
|
||||
"axios": "^1.7.9",
|
||||
"better-sqlite3": "^11.7.0",
|
||||
"dayjs": "^1.11.13",
|
||||
"ee-core": "^4.0.1",
|
||||
"ee-core": "^4.1.0",
|
||||
"electron-updater": "^6.3.8"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user