diff --git a/src/main/index.ts b/src/main/index.ts index d949636..93bc3fa 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -1,6 +1,7 @@ import { app, BrowserWindow, shell, ipcMain, dialog, Menu, globalShortcut, clipboard } from 'electron' import { join, basename } from 'node:path' -import { statSync } from 'node:fs' +import { statSync, mkdirSync, copyFileSync, writeFileSync, readdirSync, unlinkSync, existsSync } from 'node:fs' +import { homedir } from 'node:os' import { AccountManager } from './services/account-manager' import { registerAccountHandlers } from './ipc/accounts.handler' import { registerFolderHandlers } from './ipc/folders.handler' @@ -142,7 +143,55 @@ ipcMain.handle('app:copyToClipboard', (_event, { text }: { text: string }) => { clipboard.writeText(text) }) +function setupLinuxIntegration(): void { + if (process.platform !== 'linux' || !app.isPackaged) return + + const home = homedir() + const appImagePath = process.env['APPIMAGE'] ?? '' + + // Копируем иконку из ресурсов AppImage в hicolor-тему + const srcIcon = join(process.resourcesPath, 'icon.png') + if (existsSync(srcIcon)) { + for (const size of ['512x512', '256x256', '128x128']) { + const dir = join(home, `.local/share/icons/hicolor/${size}/apps`) + mkdirSync(dir, { recursive: true }) + copyFileSync(srcIcon, join(dir, 'aero-mail.png')) + } + } + + // Удаляем старые записи AppImageLauncher + const appsDir = join(home, '.local/share/applications') + mkdirSync(appsDir, { recursive: true }) + try { + for (const f of readdirSync(appsDir)) { + if (/^appimagekit_.*Aero_Mail\.desktop$/.test(f)) { + unlinkSync(join(appsDir, f)) + } + } + } catch (_) {} + + // Пишем чистый desktop-файл + if (appImagePath) { + writeFileSync( + join(appsDir, 'aero-mail.desktop'), + [ + '[Desktop Entry]', + 'Name=Aero Mail', + `Exec=${appImagePath} --no-sandbox %U`, + 'Terminal=false', + 'Type=Application', + 'Icon=aero-mail', + 'StartupWMClass=Aero Mail', + 'Comment=Desktop email client built with Vue 3 + Electron', + 'Categories=Network;', + '', + ].join('\n'), + ) + } +} + app.whenReady().then(async () => { + setupLinuxIntegration() await accountManager.initialize() // Register all IPC handlers