-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fe028b7
commit 2f88c41
Showing
7 changed files
with
135 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
/* | ||
* @Date: 2024-01-25 15:52:14 | ||
* @LastEditors: [email protected] | ||
* @LastEditTime: 2024-03-09 12:51:06 | ||
* @FilePath: \electron-hiprint\main.js | ||
*/ | ||
const { | ||
app, | ||
BrowserWindow, | ||
|
@@ -6,12 +12,14 @@ const { | |
Notification, | ||
Tray, | ||
Menu, | ||
shell | ||
} = require("electron"); | ||
const path = require("path"); | ||
const server = require("http").createServer(); | ||
const helper = require("./src/helper"); | ||
const printSetup = require("./src/print"); | ||
const setSetup = require("./src/set"); | ||
const log = require("./tools/log"); | ||
const { | ||
store, | ||
address, | ||
|
@@ -118,6 +126,7 @@ async function initialize() { | |
createWindow(); | ||
} | ||
}); | ||
log("==> Electron-hiprint 启动 <==") | ||
}); | ||
} | ||
|
||
|
@@ -282,6 +291,12 @@ function initTray() { | |
} | ||
}, | ||
}, | ||
{ | ||
label: "查看日志", | ||
click: () => { | ||
shell.openPath(app.getPath("logs")); | ||
} | ||
}, | ||
{ | ||
label: "退出", | ||
click: () => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
/* | ||
* @Date: 2023-09-05 17:34:28 | ||
* @LastEditors: [email protected] | ||
* @LastEditTime: 2024-02-20 13:09:38 | ||
* @LastEditTime: 2024-03-09 12:00:46 | ||
* @FilePath: \electron-hiprint\src\set.js | ||
*/ | ||
"use strict"; | ||
|
||
const { app, BrowserWindow, ipcMain, dialog } = require("electron"); | ||
const path = require("path"); | ||
const { store } = require("../tools/utils"); | ||
const log = require("../tools/log"); | ||
|
||
/** | ||
* @description: 创建设置窗口 | ||
|
@@ -65,6 +66,7 @@ function getConfig(event) { | |
* @return {Void} | ||
*/ | ||
function setConfig(event, data) { | ||
log("==> 设置窗口:保存配置 <==") | ||
// 保存配置前,弹出 dialog 确认 | ||
dialog | ||
.showMessageBox(SET_WINDOW, { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* @Date: 2024-03-08 13:05:10 | ||
* @LastEditors: [email protected] | ||
* @LastEditTime: 2024-03-09 12:53:03 | ||
* @FilePath: \electron-hiprint\tools\log.js | ||
*/ | ||
const { app } = require("electron"); | ||
const { access, appendFile, constants, writeFile } = require("node:fs"); | ||
const dayjs = require("dayjs"); | ||
|
||
const logs = app.getPath('logs') | ||
|
||
/** | ||
* This function checks if a log file exists. If it does not exist, a new log file will be created. | ||
* @returns {Promise} A Promise object that resolves if the file exists, or rejects if creating the file fails. | ||
*/ | ||
function checkLogFile() { | ||
const filePath = `${logs}/${dayjs().format("YYYY-MM-DD")}.log`; | ||
return new Promise((resolve, reject) => { | ||
access(filePath, constants.F_OK, (err) => { | ||
if (err) { | ||
writeFile(filePath, "", (err) => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
/** | ||
* Writes log message to log file. | ||
* @param {string} message - The log message to be written. | ||
* @returns {Promise} - A Promise object that resolves when writing is successful, or rejects when writing fails. | ||
*/ | ||
function log(message) { | ||
const filePath = `${logs}/${dayjs().format("YYYY-MM-DD")}.log`; | ||
return new Promise((resolve, reject) => { | ||
checkLogFile() | ||
.then(() => { | ||
const logMessage = `${dayjs().format( | ||
"YYYY/MM/DD HH:mm:ss" | ||
)}: ${message}\n`; | ||
appendFile(filePath, logMessage, (err) => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
}) | ||
.catch((err) => { | ||
reject(err); | ||
}); | ||
}); | ||
} | ||
|
||
module.exports = log; |
Oops, something went wrong.