@@ -304,7 +304,7 @@ function addSession(persistedSession: PersistedSession, hasActivePty: boolean) {
304304 sessions . set ( persistedSession . id , session ) ;
305305
306306 // Add to sidebar
307- addToSidebar ( persistedSession . id , persistedSession . name , hasActivePty ) ;
307+ addToSidebar ( persistedSession . id , persistedSession . name , hasActivePty , persistedSession . config ) ;
308308
309309 // Only add tab if terminal is active
310310 if ( hasActivePty ) {
@@ -351,10 +351,13 @@ function updateSessionState(sessionId: string, isActive: boolean) {
351351 }
352352}
353353
354- function addToSidebar ( sessionId : string , name : string , hasActivePty : boolean ) {
354+ function addToSidebar ( sessionId : string , name : string , hasActivePty : boolean , config : SessionConfig ) {
355355 const list = document . getElementById ( "session-list" ) ;
356356 if ( ! list ) return ;
357357
358+ const isWorktree = config . sessionType === SessionType . WORKTREE ;
359+ const applyMenuItem = isWorktree ? `<button class="session-menu-item apply-to-project-btn" data-id="${ sessionId } ">Apply to project</button>` : '' ;
360+
358361 const item = document . createElement ( "div" ) ;
359362 item . id = `sidebar-${ sessionId } ` ;
360363 item . className = "session-list-item" ;
@@ -368,6 +371,7 @@ function addToSidebar(sessionId: string, name: string, hasActivePty: boolean) {
368371 <button class="session-menu-btn" data-id="${ sessionId } " title="Session options">⋯</button>
369372 <div class="session-menu hidden" data-id="${ sessionId } ">
370373 <button class="session-menu-item rename-session-btn" data-id="${ sessionId } ">Rename</button>
374+ ${ applyMenuItem }
371375 <button class="session-menu-item delete-session-btn" data-id="${ sessionId } ">Delete</button>
372376 </div>
373377 </div>
@@ -430,6 +434,14 @@ function addToSidebar(sessionId: string, name: string, hasActivePty: boolean) {
430434 deleteSession ( sessionId ) ;
431435 } ) ;
432436
437+ // Apply to project button (only for worktree sessions)
438+ const applyBtn = item . querySelector ( ".apply-to-project-btn" ) ;
439+ applyBtn ?. addEventListener ( "click" , ( e ) => {
440+ e . stopPropagation ( ) ;
441+ menu ?. classList . add ( "hidden" ) ;
442+ showApplyToProjectDialog ( sessionId ) ;
443+ } ) ;
444+
433445 list . appendChild ( item ) ;
434446}
435447
@@ -721,6 +733,27 @@ function deleteSession(sessionId: string) {
721733 }
722734}
723735
736+ function showApplyToProjectDialog ( sessionId : string ) {
737+ const session = sessions . get ( sessionId ) ;
738+ if ( ! session ) return ;
739+
740+ const modal = document . getElementById ( "apply-to-project-modal" ) ;
741+ const branchName = document . getElementById ( "apply-branch-name" ) ;
742+ const parentBranch = document . getElementById ( "apply-parent-branch" ) ;
743+
744+ if ( branchName && session . config . branchName ) {
745+ branchName . textContent = session . config . branchName ;
746+ }
747+ if ( parentBranch && session . config . parentBranch ) {
748+ parentBranch . textContent = session . config . parentBranch ;
749+ }
750+
751+ // Store session ID for later use in confirm handler
752+ modal ?. setAttribute ( "data-session-id" , sessionId ) ;
753+
754+ modal ?. classList . remove ( "hidden" ) ;
755+ }
756+
724757// Handle session output
725758ipcRenderer . on ( "session-output" , ( _event , sessionId : string , data : string ) => {
726759 const session = sessions . get ( sessionId ) ;
@@ -1496,6 +1529,45 @@ saveSettingsBtn?.addEventListener("click", async () => {
14961529// Load settings on startup
14971530loadSettings ( ) ;
14981531
1532+ // Apply to Project Modal
1533+ const applyToProjectModal = document . getElementById ( "apply-to-project-modal" ) ;
1534+ const cancelApplyToProjectBtn = document . getElementById ( "cancel-apply-to-project" ) ;
1535+ const confirmApplyToProjectBtn = document . getElementById ( "confirm-apply-to-project" ) ;
1536+
1537+ cancelApplyToProjectBtn ?. addEventListener ( "click" , ( ) => {
1538+ applyToProjectModal ?. classList . add ( "hidden" ) ;
1539+ } ) ;
1540+
1541+ confirmApplyToProjectBtn ?. addEventListener ( "click" , async ( ) => {
1542+ const sessionId = applyToProjectModal ?. getAttribute ( "data-session-id" ) ;
1543+ if ( ! sessionId ) return ;
1544+
1545+ // Disable button during operation
1546+ if ( confirmApplyToProjectBtn ) {
1547+ confirmApplyToProjectBtn . textContent = "Applying..." ;
1548+ confirmApplyToProjectBtn . setAttribute ( "disabled" , "true" ) ;
1549+ }
1550+
1551+ try {
1552+ const result = await ipcRenderer . invoke ( "apply-session-to-project" , sessionId ) ;
1553+
1554+ if ( result . success ) {
1555+ alert ( `Changes applied successfully to project directory.` ) ;
1556+ applyToProjectModal ?. classList . add ( "hidden" ) ;
1557+ } else {
1558+ alert ( `Failed to apply changes: ${ result . error } ` ) ;
1559+ }
1560+ } catch ( error ) {
1561+ alert ( `Error applying changes: ${ error } ` ) ;
1562+ } finally {
1563+ // Re-enable button
1564+ if ( confirmApplyToProjectBtn ) {
1565+ confirmApplyToProjectBtn . textContent = "Apply Changes" ;
1566+ confirmApplyToProjectBtn . removeAttribute ( "disabled" ) ;
1567+ }
1568+ }
1569+ } ) ;
1570+
14991571// Close session menus when clicking outside
15001572document . addEventListener ( "click" , ( e ) => {
15011573 const target = e . target as HTMLElement ;
0 commit comments