lwe.handlers.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { ipcMain, type BrowserWindow } from 'electron'
  2. import { IpcChannels } from '@shared/ipc-channels'
  3. import { getLweStatus, detectDistro, installLweDeps, installLwe, uninstallLwe, launchLweAsync, stopLwe, isLweRunning, killAllLweProcesses } from '../services/lwe.service'
  4. import { invalidateEnvCache } from '../services/wallpaper.service'
  5. export function registerLweHandlers(win: BrowserWindow): void {
  6. ipcMain.handle(IpcChannels.LWE_STATUS, () => {
  7. return getLweStatus()
  8. })
  9. ipcMain.handle(IpcChannels.LWE_DETECT_DISTRO, () => {
  10. return detectDistro()
  11. })
  12. ipcMain.handle(IpcChannels.LWE_INSTALL_DEPS, async () => {
  13. await installLweDeps(win)
  14. return { ok: true }
  15. })
  16. ipcMain.handle(IpcChannels.LWE_INSTALL, async () => {
  17. await installLwe(win)
  18. invalidateEnvCache()
  19. return getLweStatus()
  20. })
  21. ipcMain.handle(IpcChannels.LWE_UNINSTALL, async () => {
  22. const result = await uninstallLwe()
  23. invalidateEnvCache()
  24. return result
  25. })
  26. ipcMain.handle(IpcChannels.LWE_LAUNCH, async (_e, wallpaperPath: string, options?: { screenRoot?: string; fps?: number }) => {
  27. await launchLweAsync(wallpaperPath, options)
  28. return { ok: true, running: isLweRunning() }
  29. })
  30. ipcMain.handle(IpcChannels.LWE_STOP, () => {
  31. stopLwe()
  32. return { ok: true }
  33. })
  34. ipcMain.handle(IpcChannels.LWE_KILL_ALL, async () => {
  35. return await killAllLweProcesses()
  36. })
  37. }