diff --git a/electron/config/config.default.js b/electron/config/config.default.js index 8f3d7ec..945e364 100644 --- a/electron/config/config.default.js +++ b/electron/config/config.default.js @@ -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: { diff --git a/electron/jobs/example/timer.js b/electron/jobs/example/timer.js index ed70364..6fe19a6 100644 --- a/electron/jobs/example/timer.js +++ b/electron/jobs/example/timer.js @@ -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); } /** diff --git a/electron/preload/lifecycle.js b/electron/preload/lifecycle.js index a18a2cc..cd75ef5 100644 --- a/electron/preload/lifecycle.js +++ b/electron/preload/lifecycle.js @@ -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(); diff --git a/package.json b/package.json index bb67be1..2bdde8d 100644 --- a/package.json +++ b/package.json @@ -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" } }