From eaa02a366e9293ccf81da7ac27c8a4f7e541b998 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E4=B8=AD=E5=90=9B?= Date: Tue, 23 Apr 2024 22:26:29 +0800 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20=E8=B7=AF=E5=BE=84=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E6=B7=BB=E5=8A=A0=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron/main/index.ts | 7 +++++-- electron/src/config.ts | 19 +++++++++++++------ package.json | 2 +- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/electron/main/index.ts b/electron/main/index.ts index df351b5..f6590c0 100644 --- a/electron/main/index.ts +++ b/electron/main/index.ts @@ -5,7 +5,7 @@ import { format } from 'util'; import { setLoggerConfig, closeAllLogger } from '@modules/logger'; import paths from '@src/path'; -import { formatDate } from '@utils'; +import { formatDate, tryCatch } from '@utils'; import { app } from 'electron'; const isDev = import.meta.env.DEV; @@ -44,7 +44,10 @@ process.on('uncaughtExceptionMonitor', (e) => { }); function onError(type: string, e: Error) { - const logPath = path.join(app.getPath('userData'), 'logs'); + const appPath = app.getAppPath(); + const userDataPath = tryCatch(() => app.getPath('userData'), appPath); + const logPath = path.join(userDataPath, 'logs'); + if (!fs.existsSync(logPath)) { fs.mkdirSync(logPath); } diff --git a/electron/src/config.ts b/electron/src/config.ts index 6cd0f85..da5e682 100644 --- a/electron/src/config.ts +++ b/electron/src/config.ts @@ -8,17 +8,24 @@ import { exifFields, defTemps, getDefTemp } from '@/common/const'; import { arrToObj, normalize, tryCatch } from '@/common/utils'; const needResetVer = ['1.5.0']; +const appPath = app.getAppPath(); +const userDataPath = tryCatch(() => app.getPath('userData'), appPath); +const desktopPath = tryCatch(() => app.getPath('desktop'), userDataPath); + +function getPath(name: Parameters[0]) { + return tryCatch(() => app.getPath(name), desktopPath, () => {}); +} export const DefaultConfig: IConfig = { version: import.meta.env.VITE_VERSION, - dir: path.join(app.getPath('userData'), 'config.json'), - output: path.join(app.getPath('pictures'), 'watermark'), - cacheDir: path.join(app.getPath('temp'), 'yiyin'), - staticDir: path.join(app.getPath('userData'), 'static'), + dir: path.join(userDataPath, 'config.json'), + output: path.join(getPath('pictures'), 'watermark'), + cacheDir: path.join(getPath('temp'), 'yiyin'), + staticDir: path.join(userDataPath, 'static'), font: { - path: path.join(app.getPath('userData'), 'font.json'), - dir: path.join(app.getPath('userData'), 'font'), + path: path.join(userDataPath, 'font.json'), + dir: path.join(userDataPath, 'font'), map: {}, }, diff --git a/package.json b/package.json index 7db8055..2841020 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "yiyin", - "version": "1.5.5", + "version": "1.5.6", "license": "MIT", "type": "module", "main": "dist-electron/main/index.js", From fee0257d1a445859f0a66b93e560fd470dc8d66e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E4=B8=AD=E5=90=9B?= Date: Sat, 27 Apr 2024 15:59:27 +0800 Subject: [PATCH 2/4] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E8=B4=A8=E9=87=8F=E6=8C=87=E5=AE=9A=20refactor:=20?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E8=8E=B7=E5=8F=96=E7=A7=BB=E5=88=B0path?= =?UTF-8?q?=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron/main/app.ts | 4 +-- electron/src/config.ts | 11 +++----- electron/src/modules/image-tool/index.ts | 2 +- electron/src/modules/image-tool/interface.ts | 5 ++++ electron/src/path.ts | 10 ++++++- web/main/components/actions/index.scss | 1 + web/main/components/actions/index.svelte | 28 +++++++++++++++----- web/main/index.scss | 2 +- 8 files changed, 44 insertions(+), 19 deletions(-) diff --git a/electron/main/app.ts b/electron/main/app.ts index a06ed55..f44f1a4 100644 --- a/electron/main/app.ts +++ b/electron/main/app.ts @@ -142,8 +142,8 @@ export default class Application { private async createDefWin() { const opts: BrowserWindowConstructorOptions = { - width: 800 + (isDev ? 500 : 0), - height: 610, + width: 900 + (isDev ? 500 : 0), + height: 650, title: '壹印', frame: false, webPreferences: { diff --git a/electron/src/config.ts b/electron/src/config.ts index da5e682..acda26c 100644 --- a/electron/src/config.ts +++ b/electron/src/config.ts @@ -2,19 +2,13 @@ import fs from 'node:fs'; import path from 'node:path'; import type { IFieldInfoItem, IConfig } from '@src/interface'; -import { app } from 'electron'; + +import { userDataPath, getPath } from './path'; import { exifFields, defTemps, getDefTemp } from '@/common/const'; import { arrToObj, normalize, tryCatch } from '@/common/utils'; const needResetVer = ['1.5.0']; -const appPath = app.getAppPath(); -const userDataPath = tryCatch(() => app.getPath('userData'), appPath); -const desktopPath = tryCatch(() => app.getPath('desktop'), userDataPath); - -function getPath(name: Parameters[0]) { - return tryCatch(() => app.getPath(name), desktopPath, () => {}); -} export const DefaultConfig: IConfig = { version: import.meta.env.VITE_VERSION, @@ -47,6 +41,7 @@ export const DefaultConfig: IConfig = { font: 'PingFang SC', main_img_w_rate: 90, text_margin: 0.4, + quality: 100, }, tempFields: [getDefOptionItem('')], diff --git a/electron/src/modules/image-tool/index.ts b/electron/src/modules/image-tool/index.ts index da4dc73..33e72f9 100644 --- a/electron/src/modules/image-tool/index.ts +++ b/electron/src/modules/image-tool/index.ts @@ -292,7 +292,7 @@ export class ImageTool extends Event { }) .withMetadata({ density: this.meta.density }) .composite(composite) - .toFormat('jpeg', { quality: 100 }) + .toFormat('jpeg', { quality: this.outputOpt.quality || 100 }) .toFile(this.outputFileNames.composite); log.info('【%s】图片合成完毕,输出到文件: ', this.id, this.outputFileNames.composite); diff --git a/electron/src/modules/image-tool/interface.ts b/electron/src/modules/image-tool/interface.ts index cf800be..747cf50 100644 --- a/electron/src/modules/image-tool/interface.ts +++ b/electron/src/modules/image-tool/interface.ts @@ -70,6 +70,11 @@ export interface OutputOption { * 文字上下间隔 */ text_margin: number + + /** + * 输出质量 + */ + quality: number } export interface OutputFilePaths { diff --git a/electron/src/path.ts b/electron/src/path.ts index b3e2d46..62ea859 100644 --- a/electron/src/path.ts +++ b/electron/src/path.ts @@ -1,16 +1,24 @@ import { join } from 'node:path'; import os from 'os'; +import { tryCatch } from '@utils'; import { app } from 'electron'; const env = import.meta.env; const isDev = env.DEV; +export const appPath = app.getAppPath(); +export const userDataPath = tryCatch(() => app.getPath('userData'), appPath); +export const desktopPath = tryCatch(() => app.getPath('desktop'), userDataPath); +export function getPath(name: Parameters[0]) { + return tryCatch(() => app.getPath(name), desktopPath, () => {}); +} + const paths = { preload: join(isDev ? env.VITE_DIST_ELECTRON : app.getAppPath(), 'preload/index.js'), web: join(isDev ? env.VITE_WEB : app.getAppPath(), 'web'), public: env.VITE_PUBLIC, - logger: join(app.getPath('userData'), 'logs'), + logger: join(userDataPath, 'logs'), logo: '', exiftool: join(isDev ? env.VITE_DIST_ELECTRON : app.getAppPath(), 'exiftool', os.platform() === 'win32' ? 'exiftool.exe' : 'exiftool'), }; diff --git a/web/main/components/actions/index.scss b/web/main/components/actions/index.scss index baa937e..bb7cd4d 100644 --- a/web/main/components/actions/index.scss +++ b/web/main/components/actions/index.scss @@ -42,6 +42,7 @@ width: 350px; flex-basis: 350px; flex-grow: 0; + overflow: hidden; .output-setting { padding: 0 4px; diff --git a/web/main/components/actions/index.svelte b/web/main/components/actions/index.svelte index b1cde7e..849bafb 100644 --- a/web/main/components/actions/index.svelte +++ b/web/main/components/actions/index.svelte @@ -1,5 +1,5 @@