diff --git a/electron/main/app.ts b/electron/main/app.ts index a06ed55..a6273da 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: 690, title: '壹印', frame: false, webPreferences: { 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..f04cdfe 100644 --- a/electron/src/config.ts +++ b/electron/src/config.ts @@ -2,7 +2,8 @@ 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'; @@ -11,14 +12,14 @@ const needResetVer = ['1.5.0']; 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: {}, }, @@ -40,6 +41,8 @@ export const DefaultConfig: IConfig = { font: 'PingFang SC', main_img_w_rate: 90, text_margin: 0.4, + quality: 100, + mini_top_bottom_margin: 0, }, tempFields: [getDefOptionItem('')], diff --git a/electron/src/modules/image-tool/index.ts b/electron/src/modules/image-tool/index.ts index da4dc73..2da2c2a 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); @@ -436,7 +436,7 @@ export class ImageTool extends Event { calcContentHeight() { const opt = this.outputOpt; const bgHeight = this.material.bg.h; - const mainImgTopOffset = bgHeight * 0.036; + const mainImgTopOffset = bgHeight * (opt.mini_top_bottom_margin / 100); const textButtomOffset = bgHeight * 0.027; // 主图上下间隔最小间隔 @@ -446,7 +446,7 @@ export class ImageTool extends Event { // 阴影宽度 if (opt.shadow_show) { const shadowHeight = Math.ceil(this.material.main[0].h * ((opt.shadow || 0) / 100)); - contentTop = Math.ceil(shadowHeight); + contentTop = Math.max(contentTop, Math.ceil(shadowHeight)); mainImgOffset = contentTop * 2; } diff --git a/electron/src/modules/image-tool/interface.ts b/electron/src/modules/image-tool/interface.ts index cf800be..99b5430 100644 --- a/electron/src/modules/image-tool/interface.ts +++ b/electron/src/modules/image-tool/interface.ts @@ -70,6 +70,16 @@ export interface OutputOption { * 文字上下间隔 */ text_margin: number + + /** + * 输出质量 + */ + quality: number + + /** + * 最小上下边距 + */ + mini_top_bottom_margin: 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/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", 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..b004a03 100644 --- a/web/main/components/actions/index.svelte +++ b/web/main/components/actions/index.svelte @@ -1,5 +1,5 @@