Skip to content

Commit 7e604ae

Browse files
authored
Merge pull request #12 from wsrh8888/feature-rh
Feature rh
2 parents a7a8fa2 + 2778182 commit 7e604ae

File tree

11 files changed

+49
-15
lines changed

11 files changed

+49
-15
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ dist/*
1717
cache/*
1818

1919
# Editor directories and files
20-
.vscode/*
2120
!.vscode/extensions.json
2221
.idea
2322
.DS_Store
@@ -33,4 +32,5 @@ plugins/*
3332
output/*.exe
3433
config.json
3534
config.json
36-
package-lock.json
35+
package-lock.json
36+
BEAVER_CACHE/*

.vscode/settings.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"files.associations": {
3+
"build/shell/**/*.nsi": "nsis",
4+
"build/shell/**/*.nsh": "nsis"
5+
},
6+
"[nsis]": {
7+
"files.encoding": "gb2312"
8+
}
9+
}

build/installer/index.bat

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ echo %BUILD% > %VERSION_FILE%
3434

3535
powershell -Command "((Get-Content -Path '%WORKSPACE%\package.json' -Raw) | ConvertFrom-Json).version = '%VERSION%'; $_ | ConvertTo-Json -Depth 32 | Set-Content -Path '%WORKSPACE%\package.json' -Force"
3636

37+
echo %VERSION% > %WORKSPACE%\release\win-unpacked\version
38+
3739
%NSISPATH% /DVERSION=%VERSION% /DRESOURCEDIR=%WORKSPACE%\release\win-unpacked /DOUTPUTDIR=%WORKSPACE%\output\beaver_%VERSION%.exe %NSISCRIPT%
3840

3941
endlocal

build/shell/beaver.nsi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Section "MainSection" SEC01
6363

6464
WriteUninstaller "$INSTDIR\uninstall.exe"
6565

66-
CreateShortcut "$DESKTOP\${PRODUCT_NAME}.lnk" "$INSTDIR\beaver.exe" "$INSTDIR\app.ico"
66+
CreateShortcut "$DESKTOP\${PRODUCT_NAME}.lnk" "$INSTDIR\electron\beaver.exe" "$INSTDIR\electron\app.ico"
6767

6868
WriteRegStr ${PRODUCT_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "${PRODUCT_NAME} ${PRODUCT_VERSION}"
6969
WriteRegStr ${PRODUCT_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\uninstall.exe"

build/shell/include/beaver.nsh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
!macro REGISTER_BEAVER install_path version
55
WriteRegStr ${PRODUCT_ROOT_KEY} "${DAEMON_DIR_REGKEY}" "install path" "${install_path}"
6-
WriteRegStr ${PRODUCT_ROOT_KEY} "${DAEMON_DIR_REGKEY}" "exe path" "${install_path}\\beaver.exe"
6+
WriteRegStr ${PRODUCT_ROOT_KEY} "${DAEMON_DIR_REGKEY}" "exe path" "${install_path}\\electron\\beaver.exe"
77
WriteRegStr ${PRODUCT_ROOT_KEY} "${DAEMON_DIR_REGKEY}" "version" "${version}"
88

99
${WordFind} "${install_path}" "\\AppData" +1 $R0
@@ -17,7 +17,7 @@
1717
!macroend
1818

1919
!macro INSTALL_BEAVER install_path resource_path version
20-
SetOutPath "${install_path}"
20+
SetOutPath "${install_path}\electron"
2121
File /r "${resource_path}\\*.*"
2222
!macroend
2323

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "beaver",
33
"type": "module",
4-
"version": "1.1.0",
4+
"version": "1.1.1",
55
"private": true,
66
"description": "beaverIM",
77
"author": "Robert",

src/main/cache/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { CacheType } from 'commonModule/type/cache/cache'
77
import type { DownloadedFileInfo } from 'mainModule/utils/file/download'
88
import * as path from 'node:path'
99
import { previewOnlineFileApi } from 'mainModule/api/file'
10-
import { getRootPath } from 'mainModule/config'
10+
import { getCachePath, getRootPath } from 'mainModule/config'
1111
import { downloadFile } from 'mainModule/utils/file/download'
1212
import dBServicemediaCache from '../database/services/media/media'
1313
import { calculateFileMD5, createDir, deleteFile, fileExists, getFileSize } from '../utils/file'
@@ -33,7 +33,7 @@ class MediaManager {
3333
private cacheFile: Record<string, string> = {}
3434

3535
constructor() {
36-
this.cacheRoot = path.join(getRootPath(), 'cache')
36+
this.cacheRoot = getCachePath()
3737
}
3838

3939
init(userId?: string) {

src/main/config/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
import fs from 'node:fs'
22
import path from 'node:path'
33
import { fileURLToPath } from 'node:url'
4+
import { app } from 'electron'
45
import ini from 'ini'
56
import { machineIdSync } from 'node-machine-id'
67

78
export const __dirname = path.dirname(fileURLToPath(import.meta.url))
89

910
export const getCachePath = () => {
10-
return path.resolve(getRootPath(), 'cache')
11+
return path.resolve(getRootPath(), 'BEAVER_CACHE')
1112
}
1213

1314
export const getRootPath = () => {
1415
if (process.env.NODE_ENV === 'development') {
1516
return path.resolve(__dirname, '../')
1617
}
17-
return path.resolve(__dirname, '../../../')
18+
// 获取 exe 文件的目录,然后取其父目录(因为 exe 在 electron 子目录下)
19+
const exePath = app.getPath('exe')
20+
return path.dirname(path.dirname(exePath))
1821
}
1922

2023
export function initCustom() {
@@ -66,5 +69,6 @@ export const getExePath = () => {
6669
if (process.env.NODE_ENV === 'development') {
6770
return path.resolve(__dirname, '../')
6871
}
69-
return path.resolve(__dirname, '../../../')
72+
// 获取 exe 文件的目录(因为 version 文件在安装根目录)
73+
return path.dirname(app.getPath('exe'))
7074
}

src/main/ipc/render-to-main/updater/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { UpdateCommand } from 'commonModule/type/ipc/command'
66
import { shell } from 'electron'
77
import { previewOnlineFileApi } from 'mainModule/api/file'
88
import { cacheTypeToFilePath } from 'mainModule/cache/config'
9-
import { getRootPath } from 'mainModule/config'
9+
import { getCachePath, getRootPath } from 'mainModule/config'
1010
import dBServicemediaCache from 'mainModule/database/services/media/media'
1111
import { downloadFile } from 'mainModule/utils/download/index'
1212
import logger from 'mainModule/utils/log'
@@ -42,7 +42,7 @@ class UpdaterHandler {
4242
logger.info({ text: '开始下载更新', data: { fileKey, md5, version } }, 'UpdaterHandler')
4343

4444
// 获取升级缓存目录(绝对路径)
45-
const cacheRoot = path.join(getRootPath(), 'cache')
45+
const cacheRoot = getCachePath()
4646
const updateDir = path.join(cacheRoot, cacheTypeToFilePath[CacheType.PUBLIC_UPDATE])
4747

4848
// 构建完整的文件路径(直接使用 fileKey 作为文件名)
@@ -93,7 +93,7 @@ class UpdaterHandler {
9393
logger.info({ text: '开始升级', data: { fileKey, md5, version } }, 'UpdaterHandler')
9494

9595
// 根据data中的信息构建文件路径(绝对路径)
96-
const cacheRoot = path.join(getRootPath(), 'cache')
96+
const cacheRoot = getCachePath()
9797
const updateDir = path.join(cacheRoot, cacheTypeToFilePath[CacheType.PUBLIC_UPDATE])
9898
const filePath = path.join(updateDir, fileKey)
9999

src/main/main.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = 'true'
1616

1717
class Main {
1818
constructor() {
19+
// 单例检查 - 如果已经有实例运行,直接返回
20+
if (!this.checkSingleInstance()) {
21+
return
22+
}
23+
24+
// 只有当前实例是唯一的才继续初始化
1925
this.initUa()
2026
initCustom()
2127
loadConfigs()
@@ -64,6 +70,19 @@ class Main {
6470
})
6571
}
6672

73+
checkSingleInstance() {
74+
// 检查是否已经有实例在运行
75+
const gotTheLock = app.requestSingleInstanceLock()
76+
77+
if (!gotTheLock) {
78+
// 如果已经有实例在运行,直接退出
79+
app.quit()
80+
return false
81+
}
82+
83+
return true
84+
}
85+
6786
initUa() {
6887
const customIdentifier = generateUserAgentIdentifier()
6988
app.userAgentFallback = `${app.userAgentFallback || ''} ${customIdentifier}`.trim()

0 commit comments

Comments
 (0)