@@ -17,12 +17,14 @@ function App() {
1717 const [ logs , setLogs ] = useState < LogEntry [ ] > ( [ ] ) ;
1818 const nextLogId = useRef ( 1 ) ;
1919 const logEndRef = useRef < HTMLSpanElement | null > ( null ) ;
20+ const bridge = window . openCodePlusPlus ;
2021
2122 useEffect ( ( ) => {
22- const offOutput = window . openCodePlusPlus . onTaskOutput ( ( event ) => {
23+ if ( ! bridge ) return ;
24+ const offOutput = bridge . onTaskOutput ( ( event ) => {
2325 appendLog ( event . stream , event . text ) ;
2426 } ) ;
25- const offExit = window . openCodePlusPlus . onTaskExit ( ( event ) => {
27+ const offExit = bridge . onTaskExit ( ( event ) => {
2628 setRunning ( false ) ;
2729 setReportPath ( event . reportPath ) ;
2830 appendLog ( "system" , `\nTask exited with ${ event . code === null ? `signal ${ event . signal ?? "unknown" } ` : `code ${ event . code } ` } \n` ) ;
@@ -32,7 +34,7 @@ function App() {
3234 offOutput ( ) ;
3335 offExit ( ) ;
3436 } ;
35- } , [ ] ) ;
37+ } , [ bridge ] ) ;
3638
3739 useEffect ( ( ) => {
3840 logEndRef . current ?. scrollIntoView ( { behavior : "smooth" , block : "end" } ) ;
@@ -43,22 +45,39 @@ function App() {
4345 return `opencode-plusplus.cmd oc run "${ task . trim ( ) } " --repo "${ repo } " --max-loops 2` ;
4446 } , [ repo , task ] ) ;
4547
48+ if ( ! bridge ) {
49+ return (
50+ < main className = "shell" >
51+ < section className = "header" >
52+ < div >
53+ < p className = "eyebrow" > OpenCode++ Desktop MVP</ p >
54+ < h1 > Desktop bridge failed to load</ h1 >
55+ </ div >
56+ < div className = "status" > Error</ div >
57+ </ section >
58+ < section className = "controls" >
59+ < p className = "error-text" > The Electron preload bridge is unavailable. Rebuild the desktop app and restart it from `apps/desktop`.</ p >
60+ </ section >
61+ </ main >
62+ ) ;
63+ }
64+
4665 function appendLog ( stream : LogEntry [ "stream" ] , text : string ) : void {
4766 setLogs ( ( current ) => [ ...current , { id : nextLogId . current ++ , stream, text } ] ) ;
4867 }
4968
5069 async function selectRepo ( ) : Promise < void > {
51- const selected = await window . openCodePlusPlus . selectRepo ( ) ;
70+ const selected = await bridge . selectRepo ( ) ;
5271 if ( ! selected ) return ;
5372 setRepo ( selected ) ;
54- setReportPath ( await window . openCodePlusPlus . getLatestReport ( selected ) ) ;
73+ setReportPath ( await bridge . getLatestReport ( selected ) ) ;
5574 setStatus ( "Repository selected." ) ;
5675 }
5776
5877 async function runTask ( ) : Promise < void > {
5978 setLogs ( [ ] ) ;
6079 setReportPath ( undefined ) ;
61- const result = await window . openCodePlusPlus . runTask ( { repo, task } ) ;
80+ const result = await bridge . runTask ( { repo, task } ) ;
6281 if ( result . error ) {
6382 appendLog ( "stderr" , `${ result . error } \n` ) ;
6483 setStatus ( result . error ) ;
@@ -70,15 +89,15 @@ function App() {
7089 }
7190
7291 async function stopTask ( ) : Promise < void > {
73- const result = await window . openCodePlusPlus . stopTask ( ) ;
92+ const result = await bridge . stopTask ( ) ;
7493 if ( result . stopped ) {
7594 appendLog ( "system" , "\nStop requested.\n" ) ;
7695 setStatus ( "Stop requested." ) ;
7796 }
7897 }
7998
8099 async function openReport ( ) : Promise < void > {
81- const result = await window . openCodePlusPlus . openLatestReport ( repo ) ;
100+ const result = await bridge . openLatestReport ( repo ) ;
82101 if ( result . opened ) {
83102 setReportPath ( result . path ) ;
84103 setStatus ( "Report opened." ) ;
0 commit comments