lwe.handlers.ts 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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, listLweObjects, hotswapLweSettings, listLweProperties } 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. ipcMain.handle(IpcChannels.LWE_LIST_OBJECTS, async (_e, wallpaperPath: string) => {
  38. // Some wallpapers have project data linux-wallpaperengine itself can't parse; treat that as "no objects" rather than a hard error
  39. try {
  40. return await listLweObjects(wallpaperPath)
  41. } catch (err) {
  42. console.warn('[LWE] list-objects failed for', wallpaperPath, ':', (err as Error).message)
  43. return []
  44. }
  45. })
  46. ipcMain.handle(
  47. IpcChannels.LWE_HOTSWAP_SETTINGS,
  48. (
  49. _e,
  50. options: {
  51. disabledObjects?: string[]
  52. enabledObjects?: string[]
  53. volume?: number
  54. xray?: boolean
  55. scaling?: string
  56. zoom?: number
  57. disableParallax?: boolean
  58. cornerColor?: string
  59. }
  60. ) => {
  61. return { ok: hotswapLweSettings(options) }
  62. }
  63. )
  64. ipcMain.handle(IpcChannels.LWE_LIST_PROPERTIES, async (_e, wallpaperPath: string) => {
  65. // Same reasoning as list-objects: some wallpapers have properties linux-wallpaperengine
  66. // itself can't parse, treat that as "no properties" rather than a hard error.
  67. try {
  68. return await listLweProperties(wallpaperPath)
  69. } catch (err) {
  70. console.warn('[LWE] list-properties failed for', wallpaperPath, ':', (err as Error).message)
  71. return []
  72. }
  73. })
  74. }