From 74a3333a43b4f5dbf4879f9ddbe577e18bb1c95c Mon Sep 17 00:00:00 2001 From: Kuingsmile <96409857+Kuingsmile@users.noreply.github.com> Date: Thu, 14 Aug 2025 11:09:21 +0800 Subject: [PATCH] :bug: Fix(custom): fix resources path --- src/main/i18n/index.ts | 5 ++++- src/main/utils/beforeOpen.ts | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/i18n/index.ts b/src/main/i18n/index.ts index aeee2c11..5c8535f5 100644 --- a/src/main/i18n/index.ts +++ b/src/main/i18n/index.ts @@ -1,4 +1,5 @@ import path from 'node:path' +import { fileURLToPath } from 'node:url' import { I18n, ObjectAdapter } from '@piclist/i18n' import fs from 'fs-extra' @@ -7,6 +8,8 @@ import yaml from 'js-yaml' import type { ILocales, ILocalesKey } from '#/types/i18n' import type { II18nItem, IStringKeyMap } from '#/types/types' +const __dirname = path.dirname(fileURLToPath(import.meta.url)) + const builtinI18nList: II18nItem[] = [ { label: '简体中文', @@ -23,7 +26,7 @@ const builtinI18nList: II18nItem[] = [ ] class I18nManager { private i18n: I18n | null = null - private builtinI18nFolder = path.join('./resources', 'i18n') + private builtinI18nFolder = path.join(__dirname, '../../resources', 'i18n') private outterI18nFolder = '' private localesMap: Map = new Map() private currentLanguage: string = 'zh-CN' diff --git a/src/main/utils/beforeOpen.ts b/src/main/utils/beforeOpen.ts index 1daa9301..b2439dd6 100644 --- a/src/main/utils/beforeOpen.ts +++ b/src/main/utils/beforeOpen.ts @@ -1,5 +1,6 @@ import os from 'node:os' import path from 'node:path' +import { fileURLToPath } from 'node:url' import { dbPathChecker } from '@core/datastore/dbChecker' import fs from 'fs-extra' @@ -10,6 +11,7 @@ import { i18nManager } from '~/i18n' const configPath = dbPathChecker() const CONFIG_DIR = path.dirname(configPath) +const __dirname = path.dirname(fileURLToPath(import.meta.url)) function beforeOpen () { if (process.platform === 'darwin') { @@ -46,7 +48,7 @@ function copyFileOutsideOfElectronAsar (sourceInAsarArchive: string, destOutside function resolveMacWorkFlow () { const dest = `${os.homedir()}/Library/Services/Upload pictures with PicList.workflow` try { - copyFileOutsideOfElectronAsar(path.join('./resources', 'Upload pictures with PicList.workflow'), dest) + copyFileOutsideOfElectronAsar(path.join(__dirname, '../../resources', 'Upload pictures with PicList.workflow'), dest) } catch (e) { console.log(e) } @@ -86,7 +88,7 @@ function resolveClipboardImageGenerator () { return files.map(item => { return { - origin: path.join('./resources', item), + origin: path.join(__dirname, '../../resources', item), dest: path.join(CONFIG_DIR, item) } })