diff --git a/src/main/apis/core/picgo/index.ts b/src/main/apis/core/picgo/index.ts index a4703d7a2..9be36b716 100644 --- a/src/main/apis/core/picgo/index.ts +++ b/src/main/apis/core/picgo/index.ts @@ -16,4 +16,7 @@ picgo.saveConfig({ PICGO_ENV: 'GUI' }) +// @ts-ignore +picgo.GUI_VERSION = global.PICGO_GUI_VERSION + export default picgo! as PicGoCore diff --git a/src/main/utils/beforeOpen.ts b/src/main/utils/beforeOpen.ts index 8fb548720..6f30b347c 100644 --- a/src/main/utils/beforeOpen.ts +++ b/src/main/utils/beforeOpen.ts @@ -2,11 +2,18 @@ import fs from 'fs-extra' import path from 'path' import os from 'os' import { remote, app } from 'electron' +import pkg from 'root/package.json' const APP = process.type === 'renderer' ? remote.app : app const STORE_PATH = APP.getPath('userData') +function injectPicGoVersion () { + global.PICGO_GUI_VERSION = pkg.version + global.PICGO_CORE_VERSION = pkg.dependencies.picgo.replace('^', '') +} + function beforeOpen () { + injectPicGoVersion() if (process.platform === 'darwin') { resolveMacWorkFlow() } diff --git a/src/universal/types/electron.d.ts b/src/universal/types/electron.d.ts index 7c72374c8..66658b63a 100644 --- a/src/universal/types/electron.d.ts +++ b/src/universal/types/electron.d.ts @@ -20,3 +20,13 @@ declare interface IWindowManager { deleteById: (id: number) => void getAvailableWindow: () => BrowserWindow } + +// https://stackoverflow.com/questions/35074713/extending-typescript-global-object-in-node-js/44387594#44387594 +declare global { + namespace NodeJS { + interface Global { + PICGO_GUI_VERSION: string + PICGO_CORE_VERSION: string + } + } +}