11import { ipcMain , dialog , shell , BrowserWindow } from "electron" ;
2+ import { IPC } from "./channels.js" ;
23import {
34 spawnAgent ,
45 writeToAgent ,
@@ -28,75 +29,75 @@ import { saveAppState, loadAppState } from "./persistence.js";
2829
2930export function registerAllHandlers ( win : BrowserWindow ) : void {
3031 // --- PTY commands ---
31- ipcMain . handle ( "spawn_agent" , ( _e , args ) => spawnAgent ( win , args ) ) ;
32- ipcMain . handle ( "write_to_agent" , ( _e , args ) => writeToAgent ( args . agentId , args . data ) ) ;
33- ipcMain . handle ( "resize_agent" , ( _e , args ) => resizeAgent ( args . agentId , args . cols , args . rows ) ) ;
34- ipcMain . handle ( "pause_agent" , ( _e , args ) => pauseAgent ( args . agentId ) ) ;
35- ipcMain . handle ( "resume_agent" , ( _e , args ) => resumeAgent ( args . agentId ) ) ;
36- ipcMain . handle ( "kill_agent" , ( _e , args ) => killAgent ( args . agentId ) ) ;
37- ipcMain . handle ( "count_running_agents" , ( ) => countRunningAgents ( ) ) ;
38- ipcMain . handle ( "kill_all_agents" , ( ) => killAllAgents ( ) ) ;
32+ ipcMain . handle ( IPC . SpawnAgent , ( _e , args ) => spawnAgent ( win , args ) ) ;
33+ ipcMain . handle ( IPC . WriteToAgent , ( _e , args ) => writeToAgent ( args . agentId , args . data ) ) ;
34+ ipcMain . handle ( IPC . ResizeAgent , ( _e , args ) => resizeAgent ( args . agentId , args . cols , args . rows ) ) ;
35+ ipcMain . handle ( IPC . PauseAgent , ( _e , args ) => pauseAgent ( args . agentId ) ) ;
36+ ipcMain . handle ( IPC . ResumeAgent , ( _e , args ) => resumeAgent ( args . agentId ) ) ;
37+ ipcMain . handle ( IPC . KillAgent , ( _e , args ) => killAgent ( args . agentId ) ) ;
38+ ipcMain . handle ( IPC . CountRunningAgents , ( ) => countRunningAgents ( ) ) ;
39+ ipcMain . handle ( IPC . KillAllAgents , ( ) => killAllAgents ( ) ) ;
3940
4041 // --- Agent commands ---
41- ipcMain . handle ( "list_agents" , ( ) => listAgents ( ) ) ;
42+ ipcMain . handle ( IPC . ListAgents , ( ) => listAgents ( ) ) ;
4243
4344 // --- Task commands ---
44- ipcMain . handle ( "create_task" , ( _e , args ) =>
45+ ipcMain . handle ( IPC . CreateTask , ( _e , args ) =>
4546 createTask ( args . name , args . projectRoot , args . symlinkDirs , args . branchPrefix )
4647 ) ;
47- ipcMain . handle ( "delete_task" , ( _e , args ) =>
48+ ipcMain . handle ( IPC . DeleteTask , ( _e , args ) =>
4849 deleteTask ( args . agentIds , args . branchName , args . deleteBranch , args . projectRoot )
4950 ) ;
5051
5152 // --- Git commands ---
52- ipcMain . handle ( "get_changed_files" , ( _e , args ) => getChangedFiles ( args . worktreePath ) ) ;
53- ipcMain . handle ( "get_file_diff" , ( _e , args ) => getFileDiff ( args . worktreePath , args . filePath ) ) ;
54- ipcMain . handle ( "get_gitignored_dirs" , ( _e , args ) => getGitIgnoredDirs ( args . projectRoot ) ) ;
55- ipcMain . handle ( "get_worktree_status" , ( _e , args ) => getWorktreeStatus ( args . worktreePath ) ) ;
56- ipcMain . handle ( "check_merge_status" , ( _e , args ) => checkMergeStatus ( args . worktreePath ) ) ;
57- ipcMain . handle ( "merge_task" , ( _e , args ) =>
53+ ipcMain . handle ( IPC . GetChangedFiles , ( _e , args ) => getChangedFiles ( args . worktreePath ) ) ;
54+ ipcMain . handle ( IPC . GetFileDiff , ( _e , args ) => getFileDiff ( args . worktreePath , args . filePath ) ) ;
55+ ipcMain . handle ( IPC . GetGitignoredDirs , ( _e , args ) => getGitIgnoredDirs ( args . projectRoot ) ) ;
56+ ipcMain . handle ( IPC . GetWorktreeStatus , ( _e , args ) => getWorktreeStatus ( args . worktreePath ) ) ;
57+ ipcMain . handle ( IPC . CheckMergeStatus , ( _e , args ) => checkMergeStatus ( args . worktreePath ) ) ;
58+ ipcMain . handle ( IPC . MergeTask , ( _e , args ) =>
5859 mergeTask ( args . projectRoot , args . branchName , args . squash , args . message , args . cleanup )
5960 ) ;
60- ipcMain . handle ( "get_branch_log" , ( _e , args ) => getBranchLog ( args . worktreePath ) ) ;
61- ipcMain . handle ( "push_task" , ( _e , args ) => pushTask ( args . projectRoot , args . branchName ) ) ;
62- ipcMain . handle ( "rebase_task" , ( _e , args ) => rebaseTask ( args . worktreePath ) ) ;
63- ipcMain . handle ( "get_main_branch" , ( _e , args ) => getMainBranch ( args . projectRoot ) ) ;
64- ipcMain . handle ( "get_current_branch" , ( _e , args ) => getCurrentBranch ( args . projectRoot ) ) ;
61+ ipcMain . handle ( IPC . GetBranchLog , ( _e , args ) => getBranchLog ( args . worktreePath ) ) ;
62+ ipcMain . handle ( IPC . PushTask , ( _e , args ) => pushTask ( args . projectRoot , args . branchName ) ) ;
63+ ipcMain . handle ( IPC . RebaseTask , ( _e , args ) => rebaseTask ( args . worktreePath ) ) ;
64+ ipcMain . handle ( IPC . GetMainBranch , ( _e , args ) => getMainBranch ( args . projectRoot ) ) ;
65+ ipcMain . handle ( IPC . GetCurrentBranch , ( _e , args ) => getCurrentBranch ( args . projectRoot ) ) ;
6566
6667 // --- Persistence ---
67- ipcMain . handle ( "save_app_state" , ( _e , args ) => saveAppState ( args . json ) ) ;
68- ipcMain . handle ( "load_app_state" , ( ) => loadAppState ( ) ) ;
68+ ipcMain . handle ( IPC . SaveAppState , ( _e , args ) => saveAppState ( args . json ) ) ;
69+ ipcMain . handle ( IPC . LoadAppState , ( ) => loadAppState ( ) ) ;
6970
7071 // --- Window management ---
71- ipcMain . handle ( "__window_is_focused" , ( ) => win . isFocused ( ) ) ;
72- ipcMain . handle ( "__window_is_maximized" , ( ) => win . isMaximized ( ) ) ;
73- ipcMain . handle ( "__window_minimize" , ( ) => win . minimize ( ) ) ;
74- ipcMain . handle ( "__window_toggle_maximize" , ( ) => {
72+ ipcMain . handle ( IPC . WindowIsFocused , ( ) => win . isFocused ( ) ) ;
73+ ipcMain . handle ( IPC . WindowIsMaximized , ( ) => win . isMaximized ( ) ) ;
74+ ipcMain . handle ( IPC . WindowMinimize , ( ) => win . minimize ( ) ) ;
75+ ipcMain . handle ( IPC . WindowToggleMaximize , ( ) => {
7576 if ( win . isMaximized ( ) ) win . unmaximize ( ) ;
7677 else win . maximize ( ) ;
7778 } ) ;
78- ipcMain . handle ( "__window_close" , ( ) => win . close ( ) ) ;
79- ipcMain . handle ( "__window_force_close" , ( ) => win . destroy ( ) ) ;
80- ipcMain . handle ( "__window_hide" , ( ) => win . hide ( ) ) ;
81- ipcMain . handle ( "__window_maximize" , ( ) => win . maximize ( ) ) ;
82- ipcMain . handle ( "__window_unmaximize" , ( ) => win . unmaximize ( ) ) ;
83- ipcMain . handle ( "__window_set_size" , ( _e , args ) =>
79+ ipcMain . handle ( IPC . WindowClose , ( ) => win . close ( ) ) ;
80+ ipcMain . handle ( IPC . WindowForceClose , ( ) => win . destroy ( ) ) ;
81+ ipcMain . handle ( IPC . WindowHide , ( ) => win . hide ( ) ) ;
82+ ipcMain . handle ( IPC . WindowMaximize , ( ) => win . maximize ( ) ) ;
83+ ipcMain . handle ( IPC . WindowUnmaximize , ( ) => win . unmaximize ( ) ) ;
84+ ipcMain . handle ( IPC . WindowSetSize , ( _e , args ) =>
8485 win . setSize ( args . width , args . height )
8586 ) ;
86- ipcMain . handle ( "__window_set_position" , ( _e , args ) =>
87+ ipcMain . handle ( IPC . WindowSetPosition , ( _e , args ) =>
8788 win . setPosition ( args . x , args . y )
8889 ) ;
89- ipcMain . handle ( "__window_get_position" , ( ) => {
90+ ipcMain . handle ( IPC . WindowGetPosition , ( ) => {
9091 const [ x , y ] = win . getPosition ( ) ;
9192 return { x, y } ;
9293 } ) ;
93- ipcMain . handle ( "__window_get_size" , ( ) => {
94+ ipcMain . handle ( IPC . WindowGetSize , ( ) => {
9495 const [ width , height ] = win . getSize ( ) ;
9596 return { width, height } ;
9697 } ) ;
9798
9899 // --- Dialog ---
99- ipcMain . handle ( "__dialog_confirm" , async ( _e , args ) => {
100+ ipcMain . handle ( IPC . DialogConfirm , async ( _e , args ) => {
100101 const result = await dialog . showMessageBox ( win , {
101102 type : args . kind === "warning" ? "warning" : "question" ,
102103 title : args . title || "Confirm" ,
@@ -108,7 +109,7 @@ export function registerAllHandlers(win: BrowserWindow): void {
108109 return result . response === 0 ;
109110 } ) ;
110111
111- ipcMain . handle ( "__dialog_open" , async ( _e , args ) => {
112+ ipcMain . handle ( IPC . DialogOpen , async ( _e , args ) => {
112113 const properties : Array <
113114 "openDirectory" | "openFile" | "multiSelections"
114115 > = [ ] ;
@@ -121,25 +122,25 @@ export function registerAllHandlers(win: BrowserWindow): void {
121122 } ) ;
122123
123124 // --- Shell/Opener ---
124- ipcMain . handle ( "__shell_reveal" , ( _e , filePath ) => {
125+ ipcMain . handle ( IPC . ShellReveal , ( _e , filePath ) => {
125126 shell . showItemInFolder ( filePath as string ) ;
126127 } ) ;
127128
128129 // --- Forward window events to renderer ---
129130 win . on ( "focus" , ( ) => {
130- if ( ! win . isDestroyed ( ) ) win . webContents . send ( "__window_focus" ) ;
131+ if ( ! win . isDestroyed ( ) ) win . webContents . send ( IPC . WindowFocus ) ;
131132 } ) ;
132133 win . on ( "blur" , ( ) => {
133- if ( ! win . isDestroyed ( ) ) win . webContents . send ( "__window_blur" ) ;
134+ if ( ! win . isDestroyed ( ) ) win . webContents . send ( IPC . WindowBlur ) ;
134135 } ) ;
135136 win . on ( "resize" , ( ) => {
136- if ( ! win . isDestroyed ( ) ) win . webContents . send ( "__window_resized" ) ;
137+ if ( ! win . isDestroyed ( ) ) win . webContents . send ( IPC . WindowResized ) ;
137138 } ) ;
138139 win . on ( "move" , ( ) => {
139- if ( ! win . isDestroyed ( ) ) win . webContents . send ( "__window_moved" ) ;
140+ if ( ! win . isDestroyed ( ) ) win . webContents . send ( IPC . WindowMoved ) ;
140141 } ) ;
141142 win . on ( "close" , ( e ) => {
142143 e . preventDefault ( ) ;
143- if ( ! win . isDestroyed ( ) ) win . webContents . send ( "__window_close_requested" ) ;
144+ if ( ! win . isDestroyed ( ) ) win . webContents . send ( IPC . WindowCloseRequested ) ;
144145 } ) ;
145146}
0 commit comments