提交 4a06282c 作者: test

feat: 新增一些基础配置、优化打包配置等

上级 f3acc5af
...@@ -2,3 +2,5 @@ ...@@ -2,3 +2,5 @@
* The name of the configuration file entered in the production environment * The name of the configuration file entered in the production environment
*/ */
export const GLOB_CONFIG_FILE_NAME = '_app.config.js' export const GLOB_CONFIG_FILE_NAME = '_app.config.js'
export const OUTPUT_DIR = 'out/renderer'
...@@ -2,6 +2,6 @@ ...@@ -2,6 +2,6 @@
* Get the configuration file variable name * Get the configuration file variable name
* @param env * @param env
*/ */
export const getConfigFileName = (env: Record<string, any>) => { export function getConfigFileName(env: Record<string, any>) {
return `__PRODUCTION__${env.VITE_GLOB_APP_SHORT_NAME || '__APP'}__CONF__`.toUpperCase().replace(/\s/g, '') return `__PRODUCTION__${env.VITE_GLOB_APP_SHORT_NAME || '__APP'}__CONF__`.toUpperCase().replace(/\s/g, '')
} }
/**
* Generate additional configuration files when used for packaging. The file can be configured with some global variables, so that it can be changed directly externally without repackaging
*/
import fs, { writeFileSync } from 'fs-extra'
import colors from 'picocolors'
import { GLOB_CONFIG_FILE_NAME, OUTPUT_DIR } from '../constant'
import { getEnvConfig, getRootPath } from '../utils'
import { getConfigFileName } from '../getConfigFileName'
import pkg from '../../package.json'
interface CreateConfigParams {
configName: string
config: any
configFileName?: string
}
function createConfig(params: CreateConfigParams) {
const { configName, config, configFileName } = params
try {
const windowConf = `window.${configName}`
// Ensure that the variable will not be modified
let configStr = `${windowConf}=${JSON.stringify(config)};`
configStr += `
Object.freeze(${windowConf});
Object.defineProperty(window, "${configName}", {
configurable: false,
writable: false,
});
`.replace(/\s/g, '')
fs.mkdirp(getRootPath(OUTPUT_DIR))
writeFileSync(getRootPath(`${OUTPUT_DIR}/${configFileName}`), configStr)
console.log(`${colors.cyan(`✨ [${pkg.name}]`)} - configuration file is build successfully:`)
console.log(`${colors.gray(`${OUTPUT_DIR}/${colors.green(configFileName)}`)}\n`)
} catch (error) {
console.log(colors.red(`configuration file configuration file failed to package:\n${error}`))
}
}
export function runBuildConfig() {
const config = getEnvConfig()
const configFileName = getConfigFileName(config)
createConfig({ config, configName: configFileName, configFileName: GLOB_CONFIG_FILE_NAME })
}
// #!/usr/bin/env node
import colors from 'picocolors'
import pkg from '../../package.json'
import { runBuildConfig } from './buildConf'
export async function runBuild() {
try {
const argvList = process.argv.splice(2)
// Generate configuration file
if (!argvList.includes('disabled-config')) {
runBuildConfig()
}
console.log(`✨ ${colors.cyan(`[${pkg.name}]`)}` + ' - build successfully!')
} catch (error) {
console.log(colors.red(`vite build error:\n${error}`))
process.exit(1)
}
}
runBuild()
...@@ -15,7 +15,6 @@ import { configVisualizerConfig } from './visualizer' ...@@ -15,7 +15,6 @@ import { configVisualizerConfig } from './visualizer'
import { configThemePlugin } from './theme' import { configThemePlugin } from './theme'
import { configSvgIconsPlugin } from './svgSprite' import { configSvgIconsPlugin } from './svgSprite'
import { configAutoImportPlugin } from './autoImport' import { configAutoImportPlugin } from './autoImport'
import { configBuildPlugin } from './config'
export function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean) { export function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean) {
const { VITE_USE_MOCK, VITE_LEGACY, VITE_BUILD_COMPRESS, VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE } = viteEnv const { VITE_USE_MOCK, VITE_LEGACY, VITE_BUILD_COMPRESS, VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE } = viteEnv
...@@ -65,7 +64,7 @@ export function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean) { ...@@ -65,7 +64,7 @@ export function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean) {
// The following plugins only work in the production environment // The following plugins only work in the production environment
if (isBuild) { if (isBuild) {
// config // config
vitePlugins.push(configBuildPlugin()) // vitePlugins.push(configBuildPlugin())
if (process.env.RUNTIME !== 'electron') { if (process.env.RUNTIME !== 'electron') {
// rollup-plugin-gzip // rollup-plugin-gzip
......
appId: com.yiring.basic.electron.app
productName: 'Basic Electron App' productName: 'Basic Electron App'
appId: com.yiring.basic.electron.app
asar: true
npmRebuild: false
buildDependenciesFromSource: true
directories: directories:
buildResources: build buildResources: build
output: release/${version} output: 'release/${version}'
files: files:
- 'out' - 'out'
- 'build/electron' - 'build/electron'
asarUnpack:
- '**/*.{node,dll}'
afterSign: build/electron/notarize.js
win: win:
executableName: basic-electron-app icon: build/electron/icon.ico
artifactName: '${productName}_${version}_${arch}.${ext}'
target:
- target: nsis
arch:
- x64
nsis: nsis:
artifactName: ${productName}_${version}.${ext}
shortcutName: ${productName} shortcutName: ${productName}
uninstallDisplayName: ${productName} uninstallDisplayName: ${productName}
createDesktopShortcut: always createDesktopShortcut: always
...@@ -20,25 +24,6 @@ nsis: ...@@ -20,25 +24,6 @@ nsis:
perMachine: false perMachine: false
allowToChangeInstallationDirectory: true allowToChangeInstallationDirectory: true
deleteAppDataOnUninstall: false deleteAppDataOnUninstall: false
mac:
entitlementsInherit: build/electron/entitlements.mac.plist
extendInfo:
- NSCameraUsageDescription: Application requests access to the device's camera.
- NSMicrophoneUsageDescription: Application requests access to the device's microphone.
- NSDocumentsFolderUsageDescription: Application requests access to the user's Documents folder.
- NSDownloadsFolderUsageDescription: Application requests access to the user's Downloads folder.
dmg:
artifactName: ${name}-${version}.${ext}
linux:
target:
- AppImage
- snap
- deb
maintainer: electronjs.org
category: Utility
appImage:
artifactName: ${name}-${version}.${ext}
npmRebuild: false
publish: publish:
provider: generic provider: generic
url: https://example.com/auto-updates url: https://example.com/auto-updates
...@@ -44,6 +44,9 @@ export default defineConfig({ ...@@ -44,6 +44,9 @@ export default defineConfig({
input: { input: {
index: resolve(__dirname, 'index.html'), index: resolve(__dirname, 'index.html'),
}, },
// 排除 electron + node 相关的依赖
external: ['node:*', 'path', 'fs', 'process', 'electron', 'electron-store'],
}, },
}, },
} }
......
...@@ -26,9 +26,9 @@ ...@@ -26,9 +26,9 @@
"bootstrap": "pnpm install", "bootstrap": "pnpm install",
"serve": "npm run dev", "serve": "npm run dev",
"dev": "vite", "dev": "vite",
"dev:app": "electron-vite dev", "dev:app": "electron-vite dev --watch",
"preview:app": "electron-vite preview", "preview:app": "electron-vite preview",
"build:app": "electron-vite build", "build:app": "electron-vite build && esno ./build/script/postBuild.ts",
"build:win": "npm run build:app && electron-builder --win --config", "build:win": "npm run build:app && electron-builder --win --config",
"build:mac": "npm run build:app && electron-builder --mac --config", "build:mac": "npm run build:app && electron-builder --mac --config",
"build:linux": "npm run build:app && electron-builder --linux --config", "build:linux": "npm run build:app && electron-builder --linux --config",
...@@ -86,12 +86,14 @@ ...@@ -86,12 +86,14 @@
"default-passive-events": "^2.0.0", "default-passive-events": "^2.0.0",
"echarts": "^5.4.3", "echarts": "^5.4.3",
"electron-log": "^4.4.8", "electron-log": "^4.4.8",
"electron-store": "^8.1.0",
"electron-updater": "^5.3.0", "electron-updater": "^5.3.0",
"intro.js": "^7.0.1", "intro.js": "^7.0.1",
"js-file-download": "^0.4.12", "js-file-download": "^0.4.12",
"lodash-es": "^4.17.21", "lodash-es": "^4.17.21",
"mockjs": "^1.1.0", "mockjs": "^1.1.0",
"nanoid": "^4.0.2", "nanoid": "^4.0.2",
"node-machine-id": "^1.1.12",
"nprogress": "^0.2.0", "nprogress": "^0.2.0",
"path-to-regexp": "^6.2.1", "path-to-regexp": "^6.2.1",
"pinia": "^2.1.6", "pinia": "^2.1.6",
......
...@@ -77,6 +77,9 @@ dependencies: ...@@ -77,6 +77,9 @@ dependencies:
electron-log: electron-log:
specifier: ^4.4.8 specifier: ^4.4.8
version: 4.4.8 version: 4.4.8
electron-store:
specifier: ^8.1.0
version: 8.1.0
electron-updater: electron-updater:
specifier: ^5.3.0 specifier: ^5.3.0
version: 5.3.0 version: 5.3.0
...@@ -95,6 +98,9 @@ dependencies: ...@@ -95,6 +98,9 @@ dependencies:
nanoid: nanoid:
specifier: ^4.0.2 specifier: ^4.0.2
version: 4.0.2 version: 4.0.2
node-machine-id:
specifier: ^1.1.12
version: 1.1.12
nprogress: nprogress:
specifier: ^0.2.0 specifier: ^0.2.0
version: 0.2.0 version: 0.2.0
...@@ -1764,6 +1770,7 @@ packages: ...@@ -1764,6 +1770,7 @@ packages:
/@commitlint/config-validator@17.6.7: /@commitlint/config-validator@17.6.7:
resolution: {integrity: sha512-vJSncmnzwMvpr3lIcm0I8YVVDJTzyjy7NZAeXbTXy+MPUdAr9pKyyg7Tx/ebOQ9kqzE6O9WT6jg2164br5UdsQ==} resolution: {integrity: sha512-vJSncmnzwMvpr3lIcm0I8YVVDJTzyjy7NZAeXbTXy+MPUdAr9pKyyg7Tx/ebOQ9kqzE6O9WT6jg2164br5UdsQ==}
engines: {node: '>=v14'} engines: {node: '>=v14'}
requiresBuild: true
dependencies: dependencies:
'@commitlint/types': 17.4.4 '@commitlint/types': 17.4.4
ajv: 8.12.0 ajv: 8.12.0
...@@ -1784,6 +1791,7 @@ packages: ...@@ -1784,6 +1791,7 @@ packages:
/@commitlint/execute-rule@17.4.0: /@commitlint/execute-rule@17.4.0:
resolution: {integrity: sha512-LIgYXuCSO5Gvtc0t9bebAMSwd68ewzmqLypqI2Kke1rqOqqDbMpYcYfoPfFlv9eyLIh4jocHWwCK5FS7z9icUA==} resolution: {integrity: sha512-LIgYXuCSO5Gvtc0t9bebAMSwd68ewzmqLypqI2Kke1rqOqqDbMpYcYfoPfFlv9eyLIh4jocHWwCK5FS7z9icUA==}
engines: {node: '>=v14'} engines: {node: '>=v14'}
requiresBuild: true
dev: true dev: true
/@commitlint/format@17.4.4: /@commitlint/format@17.4.4:
...@@ -1863,6 +1871,7 @@ packages: ...@@ -1863,6 +1871,7 @@ packages:
/@commitlint/resolve-extends@17.6.7: /@commitlint/resolve-extends@17.6.7:
resolution: {integrity: sha512-PfeoAwLHtbOaC9bGn/FADN156CqkFz6ZKiVDMjuC2N5N0740Ke56rKU7Wxdwya8R8xzLK9vZzHgNbuGhaOVKIg==} resolution: {integrity: sha512-PfeoAwLHtbOaC9bGn/FADN156CqkFz6ZKiVDMjuC2N5N0740Ke56rKU7Wxdwya8R8xzLK9vZzHgNbuGhaOVKIg==}
engines: {node: '>=v14'} engines: {node: '>=v14'}
requiresBuild: true
dependencies: dependencies:
'@commitlint/config-validator': 17.6.7 '@commitlint/config-validator': 17.6.7
'@commitlint/types': 17.4.4 '@commitlint/types': 17.4.4
...@@ -3406,6 +3415,7 @@ packages: ...@@ -3406,6 +3415,7 @@ packages:
/@types/node@20.4.7: /@types/node@20.4.7:
resolution: {integrity: sha512-bUBrPjEry2QUTsnuEjzjbS7voGWCc30W0qzgMf90GPeDGFRakvrz47ju+oqDAKCXLUCe39u57/ORMl/O/04/9g==} resolution: {integrity: sha512-bUBrPjEry2QUTsnuEjzjbS7voGWCc30W0qzgMf90GPeDGFRakvrz47ju+oqDAKCXLUCe39u57/ORMl/O/04/9g==}
requiresBuild: true
dev: true dev: true
/@types/normalize-package-data@2.4.1: /@types/normalize-package-data@2.4.1:
...@@ -4033,6 +4043,17 @@ packages: ...@@ -4033,6 +4043,17 @@ packages:
indent-string: 4.0.0 indent-string: 4.0.0
dev: true dev: true
/ajv-formats@2.1.1(ajv@8.12.0):
resolution: {integrity: sha512-Wx0Kx52hxE7C18hkMEggYlEifqWZtYaRgouJor+WMdPnQyEK13vgEWyVNup7SoeeoLMsr4kf5h6dOW11I15MUA==}
peerDependencies:
ajv: ^8.0.0
peerDependenciesMeta:
ajv:
optional: true
dependencies:
ajv: 8.12.0
dev: false
/ajv-keywords@3.5.2(ajv@6.12.6): /ajv-keywords@3.5.2(ajv@6.12.6):
resolution: {integrity: sha512-5p6WTN0DdTGVQk6VjcEju19IgaHudalcfabD7yhDGeA6bcQnmL+CpveLJq/3hvfwd1aof6L386Ougkx6RfyMIQ==} resolution: {integrity: sha512-5p6WTN0DdTGVQk6VjcEju19IgaHudalcfabD7yhDGeA6bcQnmL+CpveLJq/3hvfwd1aof6L386Ougkx6RfyMIQ==}
peerDependencies: peerDependencies:
...@@ -4057,7 +4078,6 @@ packages: ...@@ -4057,7 +4078,6 @@ packages:
json-schema-traverse: 1.0.0 json-schema-traverse: 1.0.0
require-from-string: 2.0.2 require-from-string: 2.0.2
uri-js: 4.4.1 uri-js: 4.4.1
dev: true
/ansi-escapes@4.3.2: /ansi-escapes@4.3.2:
resolution: {integrity: sha512-gKXj5ALrKWQLsYG9jlTRmR/xKluxHV+Z9QEwNIgCfM1/uwPMCuzVVnh5mwTd+OuBZcwSIMbqssNWRm1lE51QaQ==} resolution: {integrity: sha512-gKXj5ALrKWQLsYG9jlTRmR/xKluxHV+Z9QEwNIgCfM1/uwPMCuzVVnh5mwTd+OuBZcwSIMbqssNWRm1lE51QaQ==}
...@@ -4351,6 +4371,11 @@ packages: ...@@ -4351,6 +4371,11 @@ packages:
hasBin: true hasBin: true
dev: true dev: true
/atomically@1.7.0:
resolution: {integrity: sha512-Xcz9l0z7y9yQ9rdDaxlmaI4uJHf/T8g9hOEzJcsEqX2SjCj4J20uK7+ldkDHMbpJDK76wF7xEIgxc/vSlsfw5w==}
engines: {node: '>=10.12.0'}
dev: false
/autoprefixer@10.4.14(postcss@8.4.27): /autoprefixer@10.4.14(postcss@8.4.27):
resolution: {integrity: sha512-FQzyfOsTlwVzjHxKEqRIAdJx9niO6VCBCoEwax/VLSoQF29ggECcPuBqUMZ+u8jCZOPSy8b8/8KnuFbp0SaFZQ==} resolution: {integrity: sha512-FQzyfOsTlwVzjHxKEqRIAdJx9niO6VCBCoEwax/VLSoQF29ggECcPuBqUMZ+u8jCZOPSy8b8/8KnuFbp0SaFZQ==}
engines: {node: ^10 || ^12 || >=14} engines: {node: ^10 || ^12 || >=14}
...@@ -4530,6 +4555,7 @@ packages: ...@@ -4530,6 +4555,7 @@ packages:
/base64-js@1.5.1: /base64-js@1.5.1:
resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==} resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==}
requiresBuild: true
dev: true dev: true
/base@0.11.2: /base@0.11.2:
...@@ -5211,6 +5237,22 @@ packages: ...@@ -5211,6 +5237,22 @@ packages:
/concat-map@0.0.1: /concat-map@0.0.1:
resolution: {integrity: sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==} resolution: {integrity: sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==}
/conf@10.2.0:
resolution: {integrity: sha512-8fLl9F04EJqjSqH+QjITQfJF8BrOVaYr1jewVgSRAEWePfxT0sku4w2hrGQ60BC/TNLGQ2pgxNlTbWQmMPFvXg==}
engines: {node: '>=12'}
dependencies:
ajv: 8.12.0
ajv-formats: 2.1.1(ajv@8.12.0)
atomically: 1.7.0
debounce-fn: 4.0.0
dot-prop: 6.0.1
env-paths: 2.2.1
json-schema-typed: 7.0.3
onetime: 5.1.2
pkg-up: 3.1.0
semver: 7.5.4
dev: false
/config-chain@1.1.13: /config-chain@1.1.13:
resolution: {integrity: sha512-qj+f8APARXHrM0hraqXYb2/bOVSV4PvJQlNZ/DVj0QrmNM2q2euizkeuVckQ57J+W0mRH6Hvi+k50M4Jul2VRQ==} resolution: {integrity: sha512-qj+f8APARXHrM0hraqXYb2/bOVSV4PvJQlNZ/DVj0QrmNM2q2euizkeuVckQ57J+W0mRH6Hvi+k50M4Jul2VRQ==}
dependencies: dependencies:
...@@ -5481,6 +5523,7 @@ packages: ...@@ -5481,6 +5523,7 @@ packages:
/cosmiconfig-typescript-loader@4.4.0(@types/node@20.4.7)(cosmiconfig@8.2.0)(ts-node@10.9.1)(typescript@4.9.5): /cosmiconfig-typescript-loader@4.4.0(@types/node@20.4.7)(cosmiconfig@8.2.0)(ts-node@10.9.1)(typescript@4.9.5):
resolution: {integrity: sha512-BabizFdC3wBHhbI4kJh0VkQP9GkBfoHPydD0COMce1nJ1kJAB3F2TmJ/I7diULBKtmEWSwEbuN/KDtgnmUUVmw==} resolution: {integrity: sha512-BabizFdC3wBHhbI4kJh0VkQP9GkBfoHPydD0COMce1nJ1kJAB3F2TmJ/I7diULBKtmEWSwEbuN/KDtgnmUUVmw==}
engines: {node: '>=v14.21.3'} engines: {node: '>=v14.21.3'}
requiresBuild: true
peerDependencies: peerDependencies:
'@types/node': '*' '@types/node': '*'
cosmiconfig: '>=7' cosmiconfig: '>=7'
...@@ -5705,6 +5748,13 @@ packages: ...@@ -5705,6 +5748,13 @@ packages:
resolution: {integrity: sha512-e/1zu3xH5MQryN2zdVaF0OrdNLUbvWxzMbi+iNA6Bky7l1RoP8a2fIbRocyHclXt/arDrrR6lL3TqFD9pMQTsg==} resolution: {integrity: sha512-e/1zu3xH5MQryN2zdVaF0OrdNLUbvWxzMbi+iNA6Bky7l1RoP8a2fIbRocyHclXt/arDrrR6lL3TqFD9pMQTsg==}
dev: true dev: true
/debounce-fn@4.0.0:
resolution: {integrity: sha512-8pYCQiL9Xdcg0UPSD3d+0KMlOjp+KGU5EPwYddgzQ7DATsg4fuUDjQtsYLmWjnk2obnNHgV3vE2Y4jejSOJVBQ==}
engines: {node: '>=10'}
dependencies:
mimic-fn: 3.1.0
dev: false
/debug@2.6.9: /debug@2.6.9:
resolution: {integrity: sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==} resolution: {integrity: sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==}
peerDependencies: peerDependencies:
...@@ -6054,6 +6104,13 @@ packages: ...@@ -6054,6 +6104,13 @@ packages:
is-obj: 2.0.0 is-obj: 2.0.0
dev: true dev: true
/dot-prop@6.0.1:
resolution: {integrity: sha512-tE7ztYzXHIeyvc7N+hR3oi7FIbf/NIjVP9hmAt3yMXzrQ072/fpjGLx2GxNxGxUl5V73MEqYzioOMoVhGMJ5cA==}
engines: {node: '>=10'}
dependencies:
is-obj: 2.0.0
dev: false
/dotenv-expand@5.1.0: /dotenv-expand@5.1.0:
resolution: {integrity: sha512-YXQl1DSa4/PQyRfgrv6aoNjhasp/p4qs9FjJ4q4cQk+8m4r6k4ZSiEyytKG8f8W9gi8WsQtIObNmKd+tMzNTmA==} resolution: {integrity: sha512-YXQl1DSa4/PQyRfgrv6aoNjhasp/p4qs9FjJ4q4cQk+8m4r6k4ZSiEyytKG8f8W9gi8WsQtIObNmKd+tMzNTmA==}
dev: true dev: true
...@@ -6169,6 +6226,13 @@ packages: ...@@ -6169,6 +6226,13 @@ packages:
- supports-color - supports-color
dev: true dev: true
/electron-store@8.1.0:
resolution: {integrity: sha512-2clHg/juMjOH0GT9cQ6qtmIvK183B39ZXR0bUoPwKwYHJsEF3quqyDzMFUAu+0OP8ijmN2CbPRAelhNbWUbzwA==}
dependencies:
conf: 10.2.0
type-fest: 2.19.0
dev: false
/electron-to-chromium@1.4.490: /electron-to-chromium@1.4.490:
resolution: {integrity: sha512-6s7NVJz+sATdYnIwhdshx/N/9O6rvMxmhVoDSDFdj6iA45gHR8EQje70+RYsF4GeB+k0IeNSBnP7yG9ZXJFr7A==} resolution: {integrity: sha512-6s7NVJz+sATdYnIwhdshx/N/9O6rvMxmhVoDSDFdj6iA45gHR8EQje70+RYsF4GeB+k0IeNSBnP7yG9ZXJFr7A==}
...@@ -7311,7 +7375,6 @@ packages: ...@@ -7311,7 +7375,6 @@ packages:
/fast-deep-equal@3.1.3: /fast-deep-equal@3.1.3:
resolution: {integrity: sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==} resolution: {integrity: sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==}
dev: true
/fast-diff@1.3.0: /fast-diff@1.3.0:
resolution: {integrity: sha512-VxPP4NqbUjj6MaAOafWeUn2cXWLcCtljklUtZf0Ind4XQ+QPtmA0b18zZy0jIQx+ExRVCR/ZQpBmik5lXshNsw==} resolution: {integrity: sha512-VxPP4NqbUjj6MaAOafWeUn2cXWLcCtljklUtZf0Ind4XQ+QPtmA0b18zZy0jIQx+ExRVCR/ZQpBmik5lXshNsw==}
...@@ -7445,6 +7508,13 @@ packages: ...@@ -7445,6 +7508,13 @@ packages:
locate-path: 2.0.0 locate-path: 2.0.0
dev: true dev: true
/find-up@3.0.0:
resolution: {integrity: sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg==}
engines: {node: '>=6'}
dependencies:
locate-path: 3.0.0
dev: false
/find-up@4.1.0: /find-up@4.1.0:
resolution: {integrity: sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==} resolution: {integrity: sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==}
engines: {node: '>=8'} engines: {node: '>=8'}
...@@ -8238,6 +8308,7 @@ packages: ...@@ -8238,6 +8308,7 @@ packages:
/ieee754@1.2.1: /ieee754@1.2.1:
resolution: {integrity: sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==} resolution: {integrity: sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==}
requiresBuild: true
dev: true dev: true
/ignore@5.2.4: /ignore@5.2.4:
...@@ -8594,7 +8665,6 @@ packages: ...@@ -8594,7 +8665,6 @@ packages:
/is-obj@2.0.0: /is-obj@2.0.0:
resolution: {integrity: sha512-drqDG3cbczxxEJRoOXcOjtdp1J/lyp1mNn0xaznRs8+muBhgQcrnbspox5X5fOw0HnMnbfDzvnEMEtqDEJEo8w==} resolution: {integrity: sha512-drqDG3cbczxxEJRoOXcOjtdp1J/lyp1mNn0xaznRs8+muBhgQcrnbspox5X5fOw0HnMnbfDzvnEMEtqDEJEo8w==}
engines: {node: '>=8'} engines: {node: '>=8'}
dev: true
/is-path-inside@3.0.3: /is-path-inside@3.0.3:
resolution: {integrity: sha512-Fd4gABb+ycGAmKou8eMftCupSir5lRxqf4aD/vd0cD2qc4HL07OjCeuHMr8Ro4CoMaeCKDB0/ECBOVWjTwUvPQ==} resolution: {integrity: sha512-Fd4gABb+ycGAmKou8eMftCupSir5lRxqf4aD/vd0cD2qc4HL07OjCeuHMr8Ro4CoMaeCKDB0/ECBOVWjTwUvPQ==}
...@@ -9430,7 +9500,10 @@ packages: ...@@ -9430,7 +9500,10 @@ packages:
/json-schema-traverse@1.0.0: /json-schema-traverse@1.0.0:
resolution: {integrity: sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==} resolution: {integrity: sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==}
dev: true
/json-schema-typed@7.0.3:
resolution: {integrity: sha512-7DE8mpG+/fVw+dTpjbxnx47TaMnDfOI1jwft9g1VybltZCduyRQPJPvc+zzKY9WPHxhPWczyFuYa6I8Mw4iU5A==}
dev: false
/json-schema@0.4.0: /json-schema@0.4.0:
resolution: {integrity: sha512-es94M3nTIfsEPisRafak+HDLfHXnKBhV3vU5eqPcS3flIWqcxJWgXHXiey3YrpaNsanY5ei1VoYEbOzijuq9BA==} resolution: {integrity: sha512-es94M3nTIfsEPisRafak+HDLfHXnKBhV3vU5eqPcS3flIWqcxJWgXHXiey3YrpaNsanY5ei1VoYEbOzijuq9BA==}
...@@ -9675,6 +9748,14 @@ packages: ...@@ -9675,6 +9748,14 @@ packages:
path-exists: 3.0.0 path-exists: 3.0.0
dev: true dev: true
/locate-path@3.0.0:
resolution: {integrity: sha512-7AO748wWnIhNqAuaty2ZWHkQHRSNfPVIsPIfwEOWO22AmaoVrWavlOcMR5nzTLNYvp36X220/maaRsrec1G65A==}
engines: {node: '>=6'}
dependencies:
p-locate: 3.0.0
path-exists: 3.0.0
dev: false
/locate-path@5.0.0: /locate-path@5.0.0:
resolution: {integrity: sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==} resolution: {integrity: sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==}
engines: {node: '>=8'} engines: {node: '>=8'}
...@@ -9718,6 +9799,7 @@ packages: ...@@ -9718,6 +9799,7 @@ packages:
/lodash.isplainobject@4.0.6: /lodash.isplainobject@4.0.6:
resolution: {integrity: sha512-oSXzaWypCMHkPC3NvBEaPHf0KsA5mvPrOPgQWDsbg8n7orZ290M0BmC/jgRZ4vcJ6DTAhjrsSYgdsW/F+MFOBA==} resolution: {integrity: sha512-oSXzaWypCMHkPC3NvBEaPHf0KsA5mvPrOPgQWDsbg8n7orZ290M0BmC/jgRZ4vcJ6DTAhjrsSYgdsW/F+MFOBA==}
requiresBuild: true
dev: true dev: true
/lodash.kebabcase@4.1.1: /lodash.kebabcase@4.1.1:
...@@ -9734,6 +9816,7 @@ packages: ...@@ -9734,6 +9816,7 @@ packages:
/lodash.mergewith@4.6.2: /lodash.mergewith@4.6.2:
resolution: {integrity: sha512-GK3g5RPZWTRSeLSpgP8Xhra+pnjBC56q9FZYe1d5RN3TJ35dbkGy3YqBSMbyCrlbi+CM9Z3Jk5yTL7RCsqboyQ==} resolution: {integrity: sha512-GK3g5RPZWTRSeLSpgP8Xhra+pnjBC56q9FZYe1d5RN3TJ35dbkGy3YqBSMbyCrlbi+CM9Z3Jk5yTL7RCsqboyQ==}
requiresBuild: true
dev: true dev: true
/lodash.snakecase@4.1.1: /lodash.snakecase@4.1.1:
...@@ -9754,6 +9837,7 @@ packages: ...@@ -9754,6 +9837,7 @@ packages:
/lodash.uniq@4.5.0: /lodash.uniq@4.5.0:
resolution: {integrity: sha512-xfBaXQd9ryd9dlSDvnvI0lvxfLJlYAZzXomUYzLKtUeOQvOP5piqAWuGtrhWeqaXK9hhoM/iyJc5AV+XfsX3HQ==} resolution: {integrity: sha512-xfBaXQd9ryd9dlSDvnvI0lvxfLJlYAZzXomUYzLKtUeOQvOP5piqAWuGtrhWeqaXK9hhoM/iyJc5AV+XfsX3HQ==}
requiresBuild: true
dev: true dev: true
/lodash.upperfirst@4.3.1: /lodash.upperfirst@4.3.1:
...@@ -10039,6 +10123,11 @@ packages: ...@@ -10039,6 +10123,11 @@ packages:
resolution: {integrity: sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==} resolution: {integrity: sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==}
engines: {node: '>=6'} engines: {node: '>=6'}
/mimic-fn@3.1.0:
resolution: {integrity: sha512-Ysbi9uYW9hFyfrThdDEQuykN4Ey6BuwPD2kpI5ES/nFTDn/98yxYNLZJcgUAKPT/mcrLLKaGzJR9YVxJrIdASQ==}
engines: {node: '>=8'}
dev: false
/mimic-fn@4.0.0: /mimic-fn@4.0.0:
resolution: {integrity: sha512-vqiC06CuhBTUdZH+RYl8sFrL096vA45Ok5ISO6sE/Mr1jRbGH4Csnhi8f3wKVl7x8mO4Au7Ir9D3Oyv1VYMFJw==} resolution: {integrity: sha512-vqiC06CuhBTUdZH+RYl8sFrL096vA45Ok5ISO6sE/Mr1jRbGH4Csnhi8f3wKVl7x8mO4Au7Ir9D3Oyv1VYMFJw==}
engines: {node: '>=12'} engines: {node: '>=12'}
...@@ -10171,12 +10260,14 @@ packages: ...@@ -10171,12 +10260,14 @@ packages:
/ms@2.0.0: /ms@2.0.0:
resolution: {integrity: sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==} resolution: {integrity: sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==}
requiresBuild: true
/ms@2.1.2: /ms@2.1.2:
resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==} resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==}
/ms@2.1.3: /ms@2.1.3:
resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==} resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==}
requiresBuild: true
/muggle-string@0.3.1: /muggle-string@0.3.1:
resolution: {integrity: sha512-ckmWDJjphvd/FvZawgygcUeQCxzvohjFO5RxTjj4eq8kw359gFF3E1brjfI+viLMxss5JrHTDRHZvu2/tuy0Qg==} resolution: {integrity: sha512-ckmWDJjphvd/FvZawgygcUeQCxzvohjFO5RxTjj4eq8kw359gFF3E1brjfI+viLMxss5JrHTDRHZvu2/tuy0Qg==}
...@@ -10303,6 +10394,10 @@ packages: ...@@ -10303,6 +10394,10 @@ packages:
resolution: {integrity: sha512-O5lz91xSOeoXP6DulyHfllpq+Eg00MWitZIbtPfoSEvqIHdl5gfcY6hYzDWnj0qD5tz52PI08u9qUvSVeUBeHw==} resolution: {integrity: sha512-O5lz91xSOeoXP6DulyHfllpq+Eg00MWitZIbtPfoSEvqIHdl5gfcY6hYzDWnj0qD5tz52PI08u9qUvSVeUBeHw==}
dev: false dev: false
/node-machine-id@1.1.12:
resolution: {integrity: sha512-QNABxbrPa3qEIfrE6GOJ7BYIuignnJw7iQ2YPbc3Nla1HzRJjXzZOiikfF8m7eAMfichLt3M4VgLOetqgDmgGQ==}
dev: false
/node-releases@2.0.13: /node-releases@2.0.13:
resolution: {integrity: sha512-uYr7J37ae/ORWdZeQ1xxMJe3NtdmqMC/JZK+geofDrkLUApKRHPd18/TxtBOJ4A0/+uUIliorNrfYV6s1b02eQ==} resolution: {integrity: sha512-uYr7J37ae/ORWdZeQ1xxMJe3NtdmqMC/JZK+geofDrkLUApKRHPd18/TxtBOJ4A0/+uUIliorNrfYV6s1b02eQ==}
...@@ -10562,6 +10657,13 @@ packages: ...@@ -10562,6 +10657,13 @@ packages:
p-limit: 1.3.0 p-limit: 1.3.0
dev: true dev: true
/p-locate@3.0.0:
resolution: {integrity: sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ==}
engines: {node: '>=6'}
dependencies:
p-limit: 2.3.0
dev: false
/p-locate@4.1.0: /p-locate@4.1.0:
resolution: {integrity: sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==} resolution: {integrity: sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==}
engines: {node: '>=8'} engines: {node: '>=8'}
...@@ -10678,7 +10780,6 @@ packages: ...@@ -10678,7 +10780,6 @@ packages:
/path-exists@3.0.0: /path-exists@3.0.0:
resolution: {integrity: sha512-bpC7GYwiDYQ4wYLe+FA8lhRjhQCMcQGuSgGGqDkg/QerRWw9CmGRT0iSOVRSZJ29NMLZgIzqaljJ63oaL4NIJQ==} resolution: {integrity: sha512-bpC7GYwiDYQ4wYLe+FA8lhRjhQCMcQGuSgGGqDkg/QerRWw9CmGRT0iSOVRSZJ29NMLZgIzqaljJ63oaL4NIJQ==}
engines: {node: '>=4'} engines: {node: '>=4'}
dev: true
/path-exists@4.0.0: /path-exists@4.0.0:
resolution: {integrity: sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==} resolution: {integrity: sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==}
...@@ -10817,6 +10918,13 @@ packages: ...@@ -10817,6 +10918,13 @@ packages:
pathe: 1.1.1 pathe: 1.1.1
dev: true dev: true
/pkg-up@3.1.0:
resolution: {integrity: sha512-nDywThFk1i4BQK4twPQ6TA4RT8bDY96yeuCVBWL3ePARCiEKDRSrNGbFIgUJpLp+XeIR65v8ra7WuJOFUBtkMA==}
engines: {node: '>=8'}
dependencies:
find-up: 3.0.0
dev: false
/plist@3.1.0: /plist@3.1.0:
resolution: {integrity: sha512-uysumyrvkUX0rX/dEVqt8gC3sTBzd4zoWfLeS29nb53imdaXVvLINYXTI2GNqzaMuvacNx4uJQ8+b3zXR0pkgQ==} resolution: {integrity: sha512-uysumyrvkUX0rX/dEVqt8gC3sTBzd4zoWfLeS29nb53imdaXVvLINYXTI2GNqzaMuvacNx4uJQ8+b3zXR0pkgQ==}
engines: {node: '>=10.4.0'} engines: {node: '>=10.4.0'}
...@@ -11377,7 +11485,6 @@ packages: ...@@ -11377,7 +11485,6 @@ packages:
/require-from-string@2.0.2: /require-from-string@2.0.2:
resolution: {integrity: sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==} resolution: {integrity: sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==}
engines: {node: '>=0.10.0'} engines: {node: '>=0.10.0'}
dev: true
/require-main-filename@2.0.0: /require-main-filename@2.0.0:
resolution: {integrity: sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==} resolution: {integrity: sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==}
...@@ -11801,6 +11908,7 @@ packages: ...@@ -11801,6 +11908,7 @@ packages:
/slice-ansi@3.0.0: /slice-ansi@3.0.0:
resolution: {integrity: sha512-pSyv7bSTC7ig9Dcgbw9AuRNUb5k5V6oDudjZoMBSr13qpLBG7tB+zgCkARjq7xIUgdz5P1Qe8u+rSGdouOOIyQ==} resolution: {integrity: sha512-pSyv7bSTC7ig9Dcgbw9AuRNUb5k5V6oDudjZoMBSr13qpLBG7tB+zgCkARjq7xIUgdz5P1Qe8u+rSGdouOOIyQ==}
engines: {node: '>=8'} engines: {node: '>=8'}
requiresBuild: true
dependencies: dependencies:
ansi-styles: 4.3.0 ansi-styles: 4.3.0
astral-regex: 2.0.0 astral-regex: 2.0.0
...@@ -12871,6 +12979,11 @@ packages: ...@@ -12871,6 +12979,11 @@ packages:
engines: {node: '>=10'} engines: {node: '>=10'}
dev: true dev: true
/type-fest@2.19.0:
resolution: {integrity: sha512-RAH822pAdBgcNMAfWnCBU3CFZcfZ/i1eZjwFU/dsLKumyuuP3niueg2UAukXYF0E2AAoc82ZSSf9J0WQBinzHA==}
engines: {node: '>=12.20'}
dev: false
/type@1.2.0: /type@1.2.0:
resolution: {integrity: sha512-+5nt5AAniqsCnu2cEQQdpzCAh33kVx8n0VoFidKpB1dVVLAN/F+bgVOqOJqOnEnrhp222clB5p3vUlD+1QAnfg==} resolution: {integrity: sha512-+5nt5AAniqsCnu2cEQQdpzCAh33kVx8n0VoFidKpB1dVVLAN/F+bgVOqOJqOnEnrhp222clB5p3vUlD+1QAnfg==}
requiresBuild: true requiresBuild: true
...@@ -13119,7 +13232,6 @@ packages: ...@@ -13119,7 +13232,6 @@ packages:
resolution: {integrity: sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==} resolution: {integrity: sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==}
dependencies: dependencies:
punycode: 2.3.0 punycode: 2.3.0
dev: true
/urix@0.1.0: /urix@0.1.0:
resolution: {integrity: sha512-Am1ousAhSLBeB9cG/7k7r2R0zj50uDRlZHPGbazid5s9rlF1F/QKYObEKSIunSjIOkJZqwRRLpvewjEkM7pSqg==} resolution: {integrity: sha512-Am1ousAhSLBeB9cG/7k7r2R0zj50uDRlZHPGbazid5s9rlF1F/QKYObEKSIunSjIOkJZqwRRLpvewjEkM7pSqg==}
......
import type { BrowserWindow } from 'electron'
import { app, ipcMain } from 'electron'
import type ElectronStore from 'electron-store'
import type { SettingStore } from '/#/store'
export async function useHandler(win: BrowserWindow, store: ElectronStore<SettingStore>) {
// ==================== ipc handle ===================
// 关闭程序
ipcMain.handle('close', () => {
win.close()
app.quit()
})
// 重新加载
ipcMain.handle('reload', () => {
win.reload()
})
// 打开 F12
ipcMain.handle('debug', () => {
win.webContents.toggleDevTools()
})
// 最大化
ipcMain.handle('max', () => {
if (win.isMaximized()) {
win.restore()
} else {
win.maximize()
}
})
// 最小化
ipcMain.handle('min', () => {
win.minimize()
})
// 置顶
ipcMain.handle('top', (_, value: boolean) => {
win.setAlwaysOnTop(value)
})
// 设置窗口是否总在最前
if (store.get('system.alwaysOnTop')) {
win.setAlwaysOnTop(true)
}
}
...@@ -2,30 +2,37 @@ import path from 'node:path' ...@@ -2,30 +2,37 @@ import path from 'node:path'
import { BrowserWindow, app, shell } from 'electron' import { BrowserWindow, app, shell } from 'electron'
import { electronApp, is, optimizer } from '@electron-toolkit/utils' import { electronApp, is, optimizer } from '@electron-toolkit/utils'
import { useStore } from './store'
import { useUpdater } from './update'
import { useHandler } from './handler'
// Remove electron security warnings // Remove electron security warnings
// This warning only shows in development mode // This warning only shows in development mode
// Read more on https://www.electronjs.org/docs/latest/tutorial/security // Read more on https://www.electronjs.org/docs/latest/tutorial/security
process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = 'true' process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = 'true'
process.env.DIST_ELECTRON = path.join(__dirname, '..') process.env.DIST_ELECTRON = path.join(__dirname, '..')
process.env.DIST = path.join(process.env.DIST_ELECTRON, '../dist') process.env.DIST = path.join(process.env.DIST_ELECTRON, '../out/renderer')
process.env.PUBLIC = app.isPackaged ? __dirname : path.join(process.env.DIST_ELECTRON, '../public') process.env.PUBLIC = app.isPackaged ? __dirname : path.join(process.env.DIST_ELECTRON, '../public')
function createWindow(): void { async function createWindow(): Promise<BrowserWindow> {
// Create the browser window. // Create the browser window.
const mainWindow = new BrowserWindow({ const mainWindow = new BrowserWindow({
width: 900, width: 900,
height: 680, height: 685,
show: false, show: false,
autoHideMenuBar: true, autoHideMenuBar: true,
...(process.platform === 'linux' // icon: path.join(__dirname, '../../build/electron/icon.ico'),
? {
icon: path.join(__dirname, '../../build/electron/icon.png'),
}
: {}),
webPreferences: { webPreferences: {
preload: path.join(__dirname, '../preload/index.js'), preload: path.join(__dirname, '../preload/index.js'),
sandbox: false, sandbox: false,
// Warning: Enable nodeIntegration and disable contextIsolation is not secure in production
// Consider using contextBridge.exposeInMainWorld
// Read more on https://www.electronjs.org/docs/latest/tutorial/context-isolation
nodeIntegration: true,
contextIsolation: false,
}, },
// 无边框
// frame: false,
}) })
mainWindow.on('ready-to-show', () => { mainWindow.on('ready-to-show', () => {
...@@ -44,12 +51,14 @@ function createWindow(): void { ...@@ -44,12 +51,14 @@ function createWindow(): void {
} else { } else {
mainWindow.loadFile(path.join(process.env.DIST as string, 'index.html')) mainWindow.loadFile(path.join(process.env.DIST as string, 'index.html'))
} }
return mainWindow
} }
// This method will be called when Electron has finished // This method will be called when Electron has finished
// initialization and is ready to create browser windows. // initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs. // Some APIs can only be used after this event occurs.
app.whenReady().then(() => { app.whenReady().then(async () => {
// Set app user model id for windows // Set app user model id for windows
electronApp.setAppUserModelId('com.electron') electronApp.setAppUserModelId('com.electron')
...@@ -60,13 +69,20 @@ app.whenReady().then(() => { ...@@ -60,13 +69,20 @@ app.whenReady().then(() => {
optimizer.watchWindowShortcuts(window) optimizer.watchWindowShortcuts(window)
}) })
createWindow()
app.on('activate', function () { app.on('activate', function () {
// On macOS it's common to re-create a window in the app when the // On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open. // dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) createWindow() if (BrowserWindow.getAllWindows().length === 0) createWindow()
}) })
// 创建窗口
const win = await createWindow()
// 创建本地存储
const store = await useStore(win)
// 版本更新
await useUpdater(win, store)
// 业务交互事件监听
await useHandler(win, store)
}) })
// Quit when all windows are closed, except on macOS. There, it's common // Quit when all windows are closed, except on macOS. There, it's common
......
import os from 'node:os'
import log from 'electron-log'
log.transports.file.maxSize = 1002430
log.transports.file.format = '[{y}-{m}-{d} {h}:{i}:{s}.{ms}] [{level}]{scope} {text}'
// 需要保存的了路径
log.transports.file.resolvePath = () => `${os.homedir()}\\Documents\\multi-screen-control-client.log`
// 全局的 console.info 写进日志文件
console.info = log.info
export default log
import type { SettingStore } from '/#/store'
import Store from 'electron-store'
import { machineIdSync } from 'node-machine-id'
import type { BrowserWindow } from 'electron'
import { ipcMain } from 'electron'
import { autoUpdater } from 'electron-updater'
export async function useStore(_win: BrowserWindow) {
// 初始化配置
const store = new Store<SettingStore>({
name: 'basic-electron-client-config',
clearInvalidConfig: true,
encryptionKey: 'yiring.com',
defaults: {
system: {
machineId: machineIdSync().toUpperCase(),
// 调试模式
debug: false,
// 是否总在最前
alwaysOnTop: false,
// 检查更新地址
feedURL: '',
},
},
})
// ==================== ipc handle ===================
// 获取配置
ipcMain.handle('store-get', (_, key) => {
return store.get(key)
})
// 设置配置
ipcMain.handle('store-set', (_, key, value) => {
console.log('store-set', key, value)
if (key === 'system') {
const oldValue = store.get(key)
if (oldValue?.feedURL !== value.feedURL) {
try {
// 设置更新地址
autoUpdater.setFeedURL({
provider: 'generic',
url: value.feedURL,
})
} catch (_) {}
}
}
store.set(key, value)
})
// 重置配置
ipcMain.handle('store-reset', (_, keys) => {
store.reset(keys)
})
return store
}
import log from 'electron-log'
import { autoUpdater } from 'electron-updater' import { autoUpdater } from 'electron-updater'
import type { BrowserWindow } from 'electron' import type { BrowserWindow } from 'electron'
import { ipcMain } from 'electron' import { ipcMain } from 'electron'
import log from './log'
import type ElectronStore from 'electron-store'
import type { SettingStore } from '/#/store'
autoUpdater.logger = log autoUpdater.logger = log
log.info('App starting...') log.info('App starting...')
...@@ -14,7 +16,7 @@ type MessageType = ...@@ -14,7 +16,7 @@ type MessageType =
| 'download-progress' | 'download-progress'
| 'update-downloaded' | 'update-downloaded'
export async function useUpdater(win: BrowserWindow) { export async function useUpdater(win: BrowserWindow, store: ElectronStore<SettingStore>) {
function checkForUpdate() { function checkForUpdate() {
autoUpdater.checkForUpdates() autoUpdater.checkForUpdates()
} }
...@@ -31,7 +33,7 @@ export async function useUpdater(win: BrowserWindow) { ...@@ -31,7 +33,7 @@ export async function useUpdater(win: BrowserWindow) {
sendUpdateMessageToWindow({ type: 'update-available', text: `发现新版本 v${info.version}` }) sendUpdateMessageToWindow({ type: 'update-available', text: `发现新版本 v${info.version}` })
}) })
autoUpdater.on('update-not-available', () => { autoUpdater.on('update-not-available', () => {
sendUpdateMessageToWindow({ type: 'update-not-available', text: '当前已是最新版本' }) sendUpdateMessageToWindow({ type: 'update-not-available', text: '当前已是最新版本~' })
}) })
autoUpdater.on('error', (err) => { autoUpdater.on('error', (err) => {
sendUpdateMessageToWindow({ type: 'error', text: err.message }) sendUpdateMessageToWindow({ type: 'error', text: err.message })
...@@ -57,6 +59,23 @@ export async function useUpdater(win: BrowserWindow) { ...@@ -57,6 +59,23 @@ export async function useUpdater(win: BrowserWindow) {
checkForUpdate() checkForUpdate()
}) })
// 检查更新 try {
checkForUpdate() const feedURL = store.get('system.feedURL')
if (feedURL) {
// 设置更新地址
autoUpdater.setFeedURL({
provider: 'generic',
url: feedURL as string,
})
// 检查更新
checkForUpdate()
}
} catch (error: any) {
log.info(`[检查更新] 出现异常: ${error}`)
win.webContents.send('app-notify', {
type: 'error',
message: error.message,
})
}
} }
...@@ -62,7 +62,7 @@ ...@@ -62,7 +62,7 @@
<!-- 公司 + 版权信息 --> <!-- 公司 + 版权信息 -->
<div class="about-app-info-wrap"> <div class="about-app-info-wrap">
<div class="app-icon"> <div class="app-icon">
<img src="logo.png" /> <img src="/logo.png" />
</div> </div>
<!-- <div class="app-name">{{ $app.name }}</div> --> <!-- <div class="app-name">{{ $app.name }}</div> -->
<div class="app-description">{{ $app.description }}</div> <div class="app-description">{{ $app.description }}</div>
......
/* eslint-disable */ /* eslint-disable */
/* prettier-ignore */ /* prettier-ignore */
// @ts-nocheck // @ts-nocheck
// noinspection JSUnusedGlobalSymbols
// Generated by unplugin-auto-import // Generated by unplugin-auto-import
export {} export {}
declare global { declare global {
......
...@@ -46,3 +46,37 @@ export interface BeforeMiniState { ...@@ -46,3 +46,37 @@ export interface BeforeMiniState {
menuMode?: MenuModeEnum menuMode?: MenuModeEnum
menuType?: MenuTypeEnum menuType?: MenuTypeEnum
} }
export type ISystem = {
/**
* 机器 UUID
*/
machineId?: string
/**
* 系统平台
*/
platform?: string
/**
* 本机 IP
*/
ip?: string
/**
* 调试模式
*/
debug?: boolean
/**
* 置顶
*/
alwaysOnTop?: boolean
/**
* 版本更新地址
*/
feedURL?: string
}
export type SettingStore = {
/**
* 系统配置
*/
system?: ISystem
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论