diff --git a/build/icon.icns b/build/icon.icns index 28644aa..c256135 100644 Binary files a/build/icon.icns and b/build/icon.icns differ diff --git a/build/icon.ico b/build/icon.ico index 72c391e..dff2133 100644 Binary files a/build/icon.ico and b/build/icon.ico differ diff --git a/build/icon.png b/build/icon.png index cf9e8b2..a7a88f8 100644 Binary files a/build/icon.png and b/build/icon.png differ diff --git a/package.json b/package.json index 3e04efb..2d55432 100644 --- a/package.json +++ b/package.json @@ -59,6 +59,7 @@ "eslint": "^8.57.1", "eslint-plugin-vue": "^9.32.0", "prettier": "^3.5.1", + "rotating-file-stream": "^3.2.6", "simplebar-vue": "^2.4.0", "typescript": "^5.7.3", "unocss": "^0.64.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 281c7d6..d2919a8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -105,6 +105,9 @@ importers: prettier: specifier: ^3.5.1 version: 3.5.1 + rotating-file-stream: + specifier: ^3.2.6 + version: 3.2.6 simplebar-vue: specifier: ^2.4.0 version: 2.4.0(vue@3.5.13(typescript@5.7.3)) @@ -752,21 +755,25 @@ packages: resolution: {integrity: sha512-eEwxY+0Cf76HnQwr1+Qy48qwf4dAebTHaKhzEgxLqLK6szbglnK6SThjY95YHrYWwsH1GujWiFoX51jwZNYfSw==} cpu: [arm64] os: [linux] + libc: [glibc] '@oxc-resolver/binding-linux-arm64-musl@3.0.3': resolution: {integrity: sha512-LdxbLv8qVkzro4/ZoP9MuytIL6NOVsbhoZ5Wl1KXOa/2DSxBiksrAPMSChCTyeLy6P3ebSHxQSb52ku18t1LBA==} cpu: [arm64] os: [linux] + libc: [musl] '@oxc-resolver/binding-linux-x64-gnu@3.0.3': resolution: {integrity: sha512-bN8elR9AV/DZZPdcteOWWElkz8KyxLtOvmfVl7Dnehcs6f9e+fWYKyqiKvva1jsxG4znGKCPT1gfMhpYW8QuKg==} cpu: [x64] os: [linux] + libc: [glibc] '@oxc-resolver/binding-linux-x64-musl@3.0.3': resolution: {integrity: sha512-Zy1U49BjriwbAds2ho6CGjZIk2KVn0+lrc/G5bvhQg7UJYxEkAueMGBuA5rULIhx9xVtIPsT9Q+J5Xhb4ffVNw==} cpu: [x64] os: [linux] + libc: [musl] '@oxc-resolver/binding-wasm32-wasi@3.0.3': resolution: {integrity: sha512-7rteQnn7i5f9nkFZs1VRdBqFhvOx3zWavyKkWjXYVxc9vsSLTg0moh2MRZw5dw5m/bEi1u/p3YAKJ9gdHyBhNQ==} @@ -812,36 +819,42 @@ packages: engines: {node: '>= 10.0.0'} cpu: [arm] os: [linux] + libc: [glibc] '@parcel/watcher-linux-arm-musl@2.5.0': resolution: {integrity: sha512-6uHywSIzz8+vi2lAzFeltnYbdHsDm3iIB57d4g5oaB9vKwjb6N6dRIgZMujw4nm5r6v9/BQH0noq6DzHrqr2pA==} engines: {node: '>= 10.0.0'} cpu: [arm] os: [linux] + libc: [musl] '@parcel/watcher-linux-arm64-glibc@2.5.0': resolution: {integrity: sha512-BfNjXwZKxBy4WibDb/LDCriWSKLz+jJRL3cM/DllnHH5QUyoiUNEp3GmL80ZqxeumoADfCCP19+qiYiC8gUBjA==} engines: {node: '>= 10.0.0'} cpu: [arm64] os: [linux] + libc: [glibc] '@parcel/watcher-linux-arm64-musl@2.5.0': resolution: {integrity: sha512-S1qARKOphxfiBEkwLUbHjCY9BWPdWnW9j7f7Hb2jPplu8UZ3nes7zpPOW9bkLbHRvWM0WDTsjdOTUgW0xLBN1Q==} engines: {node: '>= 10.0.0'} cpu: [arm64] os: [linux] + libc: [musl] '@parcel/watcher-linux-x64-glibc@2.5.0': resolution: {integrity: sha512-d9AOkusyXARkFD66S6zlGXyzx5RvY+chTP9Jp0ypSTC9d4lzyRs9ovGf/80VCxjKddcUvnsGwCHWuF2EoPgWjw==} engines: {node: '>= 10.0.0'} cpu: [x64] os: [linux] + libc: [glibc] '@parcel/watcher-linux-x64-musl@2.5.0': resolution: {integrity: sha512-iqOC+GoTDoFyk/VYSFHwjHhYrk8bljW6zOhPuhi5t9ulqiYq1togGJB5e3PwYVFFfeVgc6pbz3JdQyDoBszVaA==} engines: {node: '>= 10.0.0'} cpu: [x64] os: [linux] + libc: [musl] '@parcel/watcher-win32-arm64@2.5.0': resolution: {integrity: sha512-twtft1d+JRNkM5YbmexfcH/N4znDtjgysFaV9zvZmmJezQsKpkfLYJ+JFV3uygugK6AtIM2oADPkB2AdhBrNig==} @@ -928,46 +941,55 @@ packages: resolution: {integrity: sha512-paHF1bMXKDuizaMODm2bBTjRiHxESWiIyIdMugKeLnjuS1TCS54MF5+Y5Dx8Ui/1RBPVRE09i5OUlaLnv8OGnA==} cpu: [arm] os: [linux] + libc: [glibc] '@rollup/rollup-linux-arm-musleabihf@4.26.0': resolution: {integrity: sha512-cwxiHZU1GAs+TMxvgPfUDtVZjdBdTsQwVnNlzRXC5QzIJ6nhfB4I1ahKoe9yPmoaA/Vhf7m9dB1chGPpDRdGXg==} cpu: [arm] os: [linux] + libc: [musl] '@rollup/rollup-linux-arm64-gnu@4.26.0': resolution: {integrity: sha512-4daeEUQutGRCW/9zEo8JtdAgtJ1q2g5oHaoQaZbMSKaIWKDQwQ3Yx0/3jJNmpzrsScIPtx/V+1AfibLisb3AMQ==} cpu: [arm64] os: [linux] + libc: [glibc] '@rollup/rollup-linux-arm64-musl@4.26.0': resolution: {integrity: sha512-eGkX7zzkNxvvS05ROzJ/cO/AKqNvR/7t1jA3VZDi2vRniLKwAWxUr85fH3NsvtxU5vnUUKFHKh8flIBdlo2b3Q==} cpu: [arm64] os: [linux] + libc: [musl] '@rollup/rollup-linux-powerpc64le-gnu@4.26.0': resolution: {integrity: sha512-Odp/lgHbW/mAqw/pU21goo5ruWsytP7/HCC/liOt0zcGG0llYWKrd10k9Fj0pdj3prQ63N5yQLCLiE7HTX+MYw==} cpu: [ppc64] os: [linux] + libc: [glibc] '@rollup/rollup-linux-riscv64-gnu@4.26.0': resolution: {integrity: sha512-MBR2ZhCTzUgVD0OJdTzNeF4+zsVogIR1U/FsyuFerwcqjZGvg2nYe24SAHp8O5sN8ZkRVbHwlYeHqcSQ8tcYew==} cpu: [riscv64] os: [linux] + libc: [glibc] '@rollup/rollup-linux-s390x-gnu@4.26.0': resolution: {integrity: sha512-YYcg8MkbN17fMbRMZuxwmxWqsmQufh3ZJFxFGoHjrE7bv0X+T6l3glcdzd7IKLiwhT+PZOJCblpnNlz1/C3kGQ==} cpu: [s390x] os: [linux] + libc: [glibc] '@rollup/rollup-linux-x64-gnu@4.26.0': resolution: {integrity: sha512-ZuwpfjCwjPkAOxpjAEjabg6LRSfL7cAJb6gSQGZYjGhadlzKKywDkCUnJ+KEfrNY1jH5EEoSIKLCb572jSiglA==} cpu: [x64] os: [linux] + libc: [glibc] '@rollup/rollup-linux-x64-musl@4.26.0': resolution: {integrity: sha512-+HJD2lFS86qkeF8kNu0kALtifMpPCZU80HvwztIKnYwym3KnA1os6nsX4BGSTLtS2QVAGG1P3guRgsYyMA0Yhg==} cpu: [x64] os: [linux] + libc: [musl] '@rollup/rollup-win32-arm64-msvc@4.26.0': resolution: {integrity: sha512-WUQzVFWPSw2uJzX4j6YEbMAiLbs0BUysgysh8s817doAYhR5ybqTI1wtKARQKo6cGop3pHnrUJPFCsXdoFaimQ==} @@ -2809,6 +2831,10 @@ packages: engines: {node: '>=18.0.0', npm: '>=8.0.0'} hasBin: true + rotating-file-stream@3.2.6: + resolution: {integrity: sha512-r8yShzMWUvWXkRzbOXDM1fEaMpc3qo2PzK7bBH/0p0Nl/uz8Mud/Y+0XTQxe3kbSnDF7qBH2tSe83WDKA7o3ww==} + engines: {node: '>=14.0'} + run-parallel@1.2.0: resolution: {integrity: sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==} @@ -6347,6 +6373,8 @@ snapshots: '@rollup/rollup-win32-x64-msvc': 4.26.0 fsevents: 2.3.3 + rotating-file-stream@3.2.6: {} + run-parallel@1.2.0: dependencies: queue-microtask: 1.2.3 diff --git a/src/main/index.ts b/src/main/index.ts index 5823e9d..8c09dd0 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -2,5 +2,84 @@ import "reflect-metadata" import { _ioc } from "main/_ioc" import { App } from "main/App" +import debug from "debug" +import fs from "fs" +import path from "path" +import * as rfs from "rotating-file-stream" +import { app } from "electron" + +// 配置根目录 +const logsPath = app.getPath("logs") +console.log(`日志地址:${logsPath}`) + +const LOG_ROOT = path.join(logsPath) + +// 缓存已创建的文件流(避免重复创建) +const streams = new Map() + +// 转换命名空间为安全路径 +function sanitizeNamespace(namespace) { + return namespace + .split(":") // 按层级分隔符拆分 + .map(part => part.replace(/[\\/:*?"<>|]/g, "_")) // 替换非法字符 + .join(path.sep) // 拼接为系统路径分隔符(如 / 或 \) +} + +// 覆盖 debug.log 方法 +const originalLog = debug.log +debug.log = function (...args) { + // 保留原始控制台输出(可选) + originalLog.apply(this, args) + // 获取当前命名空间 + // @ts-ignore ... + const namespace = this.namespace + if (!namespace) { + // TODO 增加容错机制,如果没有命名空间就输出到一个默认文件中 + return + } + + // 生成日志文件路径(示例:logs/app/server.log) + const sanitizedPath = sanitizeNamespace(namespace) + // const logFilePath = path.join(LOG_ROOT, `${sanitizedPath}.log`) + + const today = new Date().toISOString().split("T")[0] + const logFilePath = path.join(LOG_ROOT, sanitizedPath, `${today}.log`) + + // 确保目录存在 + const dir = path.dirname(logFilePath) + if (!fs.existsSync(dir)) { + fs.mkdirSync(dir, { recursive: true }) // 自动创建多级目录 + } + + // 获取或创建文件流 + let stream = streams.get(logFilePath) + if (!stream) { + // stream = fs.createWriteStream(logFilePath, { flags: "a" }) // 追加模式 + stream = rfs.createStream(path.parse(logFilePath).base, { + path: dir, + size: "10M", // 单个文件最大 10MB + rotate: 5, // 保留最近 5 个文件 + }) + streams.set(logFilePath, stream) + } + + // 写入日志(添加时间戳) + const message = args.join(" ") + stream.write(`${message}\n`) + + // const timestamp = new Date().toISOString() + // stream.write(`[${timestamp}] ${message}\n`) +} + const curApp = _ioc.get(App) curApp.init() + +const _debug = debug("app:app") +app.on("before-quit", () => { + _debug("应用关闭") + streams.forEach(stream => { + stream.end() + stream.destroy() + }) + streams.clear() +}) diff --git a/src/renderer/src/pages/about/index.vue b/src/renderer/src/pages/about/index.vue index 1a3de1e..0cd85c0 100644 --- a/src/renderer/src/pages/about/index.vue +++ b/src/renderer/src/pages/about/index.vue @@ -6,7 +6,31 @@ definePage({ bg: "gs", }, }) + +// const activeTab = ref(0) +// const TopMenu = computed(() => { +// return [ +// { key: 0, title: "sada", url: "/setting" }, +// { key: 1, title: "sdas", url: "/setting/editor" }, +// { key: 2, title: "asdas", url: "/setting/update" }, +// ] +// }) +// const route = useRoute() +// watch( +// () => route, +// route => { +// for (let i = 0; i < TopMenu.value.length; i++) { +// const element = TopMenu.value[i] +// if (route.path.startsWith(element.url)) { +// activeTab.value = element.key +// } +// } +// }, +// { immediate: true }, +// )