From 40163e5c63dddc0963042e8bf36417fc790f100b Mon Sep 17 00:00:00 2001 From: kangfenmao Date: Sun, 9 Mar 2025 16:19:38 +0800 Subject: [PATCH] refactor: Remove deprecated userData path update logic --- src/main/index.ts | 3 -- src/main/utils/upgrade.ts | 77 --------------------------------------- 2 files changed, 80 deletions(-) delete mode 100644 src/main/utils/upgrade.ts diff --git a/src/main/index.ts b/src/main/index.ts index 9c0dd471..19a121ad 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -7,7 +7,6 @@ import { registerIpc } from './ipc' import { registerShortcuts } from './services/ShortcutService' import { TrayService } from './services/TrayService' import { windowService } from './services/WindowService' -import { updateUserDataPath } from './utils/upgrade' // Check for single instance lock if (!app.requestSingleInstanceLock()) { @@ -19,8 +18,6 @@ if (!app.requestSingleInstanceLock()) { // Some APIs can only be used after this event occurs. app.whenReady().then(async () => { - await updateUserDataPath() - // Set app user model id for windows electronApp.setAppUserModelId(import.meta.env.VITE_MAIN_BUNDLE_ID || 'com.kangfenmao.CherryStudio') diff --git a/src/main/utils/upgrade.ts b/src/main/utils/upgrade.ts deleted file mode 100644 index 8febb8de..00000000 --- a/src/main/utils/upgrade.ts +++ /dev/null @@ -1,77 +0,0 @@ -import { spawn } from 'child_process' -import { app, dialog } from 'electron' -import Logger from 'electron-log' -import fs from 'fs' -import path from 'path' - -export async function updateUserDataPath() { - const currentPath = app.getPath('userData') - const oldPath = currentPath.replace('CherryStudio', 'cherry-studio') - - if (currentPath !== oldPath && fs.existsSync(oldPath)) { - Logger.log('Update userData path') - - try { - if (process.platform === 'win32') { - // Windows 系统:创建 bat 文件 - const batPath = await createWindowsBatFile(oldPath, currentPath) - await promptRestartAndExecute(batPath) - } else { - // 其他系统:直接更新 - fs.rmSync(currentPath, { recursive: true, force: true }) - fs.renameSync(oldPath, currentPath) - Logger.log(`Directory renamed: ${currentPath}`) - await promptRestart() - } - } catch (error: any) { - Logger.error('Error updating userData path:', error) - dialog.showErrorBox('错误', `更新用户数据目录时发生错误: ${error.message}`) - } - } else { - Logger.log('userData path does not need to be updated') - } -} - -async function createWindowsBatFile(oldPath: string, currentPath: string): Promise { - const batPath = path.join(app.getPath('temp'), 'rename_userdata.bat') - const appPath = app.getPath('exe') - const batContent = ` -@echo off -timeout /t 2 /nobreak -rmdir /s /q "${currentPath}" -rename "${oldPath}" "${path.basename(currentPath)}" -start "" "${appPath}" -del "%~f0" - ` - fs.writeFileSync(batPath, batContent) - return batPath -} - -async function promptRestartAndExecute(batPath: string) { - await dialog.showMessageBox({ - type: 'info', - title: '应用需要重启', - message: '用户数据目录将在重启后更新。请重启应用以应用更改。', - buttons: ['手动重启'] - }) - - // 执行 bat 文件 - spawn('cmd.exe', ['/c', batPath], { - detached: true, - stdio: 'ignore' - }) - - app.exit(0) -} - -async function promptRestart() { - await dialog.showMessageBox({ - type: 'info', - title: '应用需要重启', - message: '用户数据目录已更新。请重启应用以应用更改。', - buttons: ['重启'] - }) - - app.relaunch() - app.exit(0) -}