diff --git a/src/main/ipc/services/update-service.ts b/src/main/ipc/services/update-service.ts index 2ad5cab..f403c03 100644 --- a/src/main/ipc/services/update-service.ts +++ b/src/main/ipc/services/update-service.ts @@ -3,6 +3,33 @@ import { type IpcContext, IpcMethod, IpcService } from 'electron-ipc-decorator' import { autoUpdater } from 'electron-updater' import { settingsManager } from '../../settings' +const isNewerVersion = (latest: string, current: string): boolean => { + const toSegments = (version: string) => + version.split(/[.-]/).map((segment) => { + const parsed = Number.parseInt(segment, 10) + return Number.isNaN(parsed) ? 0 : parsed + }) + + const latestSegments = toSegments(latest) + const currentSegments = toSegments(current) + const maxLength = Math.max(latestSegments.length, currentSegments.length) + + for (let index = 0; index < maxLength; index += 1) { + const latestValue = latestSegments[index] ?? 0 + const currentValue = currentSegments[index] ?? 0 + + if (latestValue > currentValue) { + return true + } + + if (latestValue < currentValue) { + return false + } + } + + return false +} + class UpdateService extends IpcService { static readonly groupName = 'update' @@ -11,11 +38,20 @@ class UpdateService extends IpcService { _context: IpcContext ): Promise<{ available: boolean; version?: string; error?: string }> { try { - // In production, use checkForUpdatesAndNotify for automatic notifications - const result = await autoUpdater.checkForUpdatesAndNotify() + const currentVersion = app.getVersion() + const result = await autoUpdater.checkForUpdates() + const latestVersion = result?.updateInfo?.version + + if (latestVersion && isNewerVersion(latestVersion, currentVersion)) { + return { + available: true, + version: latestVersion + } + } + return { - available: result !== null, - version: result?.updateInfo?.version + available: false, + version: latestVersion ?? currentVersion } } catch (error) { return { diff --git a/src/renderer/src/App.tsx b/src/renderer/src/App.tsx index 9281826..cac5210 100644 --- a/src/renderer/src/App.tsx +++ b/src/renderer/src/App.tsx @@ -53,8 +53,8 @@ function AppContent() { {/* Main Content */}
- {/* Custom Title Bar - Hide on macOS */} - {platform !== 'darwin' && } + {/* Custom Title Bar */} + { - // 监听窗口最大化状态变化 + // Listen for window maximize state changes const handleMaximized = () => { setIsMaximized(true) } @@ -41,8 +45,17 @@ export function TitleBar() { ipcServices.window.close() } + const isMac = platform === 'darwin' + const containerClass = `flex drag-region bg-background select-none ${ + isMac ? 'h-10 items-center px-4' : 'justify-end pt-4 px-5' + }` + + if (isMac) { + return
+ } + return ( -
+
{/* Window controls */}