@@ -124,6 +124,7 @@ function spawnCommand(cmd, args, cwd = ROOT_DIR, envOverrides = {}, shell = fals
124124 const child = spawn ( cmd , args , {
125125 cwd,
126126 stdio : 'inherit' ,
127+ windowsHide : true ,
127128 shell,
128129 env : {
129130 ...process . env ,
@@ -192,6 +193,7 @@ function spawnBackgroundCommand(cmd, args, cwd = ROOT_DIR, env = process.env) {
192193 return spawn ( cmd , args , {
193194 cwd,
194195 stdio : 'inherit' ,
196+ windowsHide : true ,
195197 env,
196198 } ) ;
197199}
@@ -208,6 +210,7 @@ function spawnWindowsCommandArgs(command, args, cwd = ROOT_DIR, env = process.en
208210 return spawn ( process . env . ComSpec || 'C:\\Windows\\System32\\cmd.exe' , [ '/d' , '/s' , '/c' , command , ...args ] , {
209211 cwd,
210212 stdio : 'inherit' ,
213+ windowsHide : true ,
211214 env,
212215 } ) ;
213216}
@@ -554,30 +557,31 @@ async function startDesktopPreview() {
554557
555558 printInfo ( `Launching debug desktop binary: ${ desktopBinary } ` ) ;
556559
557- appProcess = spawnBackgroundCommand ( desktopBinary , [ ] , ROOT_DIR , {
558- ...process . env ,
559- // Debug previews must upload the current workspace build. The adjacent
560- // target/debug resource tree is only a build-time copy and can lag behind
561- // mobile-web edits made while the desktop binary is being reused.
562- OPENBITFUN_MOBILE_WEB_DIR : path . join ( ROOT_DIR , 'src/mobile-web/dist' ) ,
563- } ) ;
564-
565- appProcess . on ( 'error' , ( error ) => {
566- printError ( `Desktop preview failed to start: ${ error . message || String ( error ) } ` ) ;
567- void shutdown ( 1 ) ;
568- } ) ;
569-
570- appProcess . on ( 'exit' , ( code , signal ) => {
571- if ( ! shuttingDown ) {
572- printInfo ( `Desktop preview exited (code=${ code ?? 'null' } , signal=${ signal ?? 'null' } )` ) ;
573- }
574- void shutdown ( code ?? 0 ) ;
575- } ) ;
576-
577- printSuccess ( 'Desktop preview is running' ) ;
578- printInfo ( 'Front-end edits continue to use Vite HMR; rebuild Rust only when desktop-side code changes' ) ;
579-
580- await new Promise ( ( ) => { } ) ;
560+ const { runDesktopWithMigrationRestart } = await import (
561+ pathToFileURL ( path . join ( __dirname , 'desktop-dev-migration.mjs' ) ) . href
562+ ) ;
563+ try {
564+ await runDesktopWithMigrationRestart ( ( restartArgs , migrationEnv ) => new Promise ( ( resolve , reject ) => {
565+ appProcess = spawnBackgroundCommand ( desktopBinary , restartArgs , ROOT_DIR , {
566+ ...process . env ,
567+ ...migrationEnv ,
568+ // Upload the current workspace mobile bundle instead of the staged copy.
569+ OPENBITFUN_MOBILE_WEB_DIR : path . join ( ROOT_DIR , 'src/mobile-web/dist' ) ,
570+ } ) ;
571+ appProcess . on ( 'error' , reject ) ;
572+ appProcess . on ( 'close' , ( code , signal ) => {
573+ appProcess = null ;
574+ if ( code === 0 ) resolve ( ) ;
575+ else reject ( new Error ( `Desktop preview exited (code=${ code } , signal=${ signal } )` ) ) ;
576+ } ) ;
577+ printSuccess ( 'Desktop preview is running' ) ;
578+ printInfo ( 'Front-end edits continue to use Vite HMR; rebuild Rust only when desktop-side code changes' ) ;
579+ } ) , { info : printInfo } ) ;
580+ await shutdown ( 0 ) ;
581+ } catch ( error ) {
582+ printError ( error . message || String ( error ) ) ;
583+ await shutdown ( 1 ) ;
584+ }
581585}
582586
583587/**
@@ -747,19 +751,26 @@ async function main() {
747751 OPENBITFUN_MOBILE_WEB_DIR : path . join ( ROOT_DIR , 'src/mobile-web/dist' ) ,
748752 } ;
749753 try {
750- if ( process . platform === 'win32' ) {
751- // Running the generated .cmd shim directly via spawn is flaky on Windows.
752- // Use cmd.exe with an explicit args array so the desktop app directory
753- // stays the Tauri project root without pnpm workspace path rewriting.
754- const tauriBin = path . join ( ROOT_DIR , 'node_modules' , '.bin' , 'tauri.cmd' ) ;
755- await runWindowsCommandArgs ( tauriBin , [ 'dev' , '--config' , tauriConfig ] , desktopDir , tauriDevEnv ) ;
756- } else {
757- const tauriBin = path . join ( ROOT_DIR , 'node_modules' , '.bin' , 'tauri' ) ;
758- await spawnCommand ( tauriBin , [ 'dev' , '--config' , tauriConfig ] , desktopDir , {
759- CARGO_PROFILE_DEV_CODEGEN_UNITS : tauriDevEnv . CARGO_PROFILE_DEV_CODEGEN_UNITS ,
760- OPENBITFUN_MOBILE_WEB_DIR : tauriDevEnv . OPENBITFUN_MOBILE_WEB_DIR ,
761- } ) ;
762- }
754+ const { runDesktopWithMigrationRestart } = await import (
755+ pathToFileURL ( path . join ( __dirname , 'desktop-dev-migration.mjs' ) ) . href
756+ ) ;
757+ await runDesktopWithMigrationRestart ( async ( restartArgs , migrationEnv ) => {
758+ const args = [ 'dev' , '--config' , tauriConfig , ...( restartArgs . length ? [ '--' , '--' , ...restartArgs ] : [ ] ) ] ;
759+ if ( process . platform === 'win32' ) {
760+ // Running the generated .cmd shim directly via spawn is flaky on Windows.
761+ // Use cmd.exe with an explicit args array so the desktop app directory
762+ // stays the Tauri project root without pnpm workspace path rewriting.
763+ const tauriBin = path . join ( ROOT_DIR , 'node_modules' , '.bin' , 'tauri.cmd' ) ;
764+ await runWindowsCommandArgs ( tauriBin , args , desktopDir , { ...tauriDevEnv , ...migrationEnv } ) ;
765+ } else {
766+ const tauriBin = path . join ( ROOT_DIR , 'node_modules' , '.bin' , 'tauri' ) ;
767+ await spawnCommand ( tauriBin , args , desktopDir , {
768+ CARGO_PROFILE_DEV_CODEGEN_UNITS : tauriDevEnv . CARGO_PROFILE_DEV_CODEGEN_UNITS ,
769+ OPENBITFUN_MOBILE_WEB_DIR : tauriDevEnv . OPENBITFUN_MOBILE_WEB_DIR ,
770+ ...migrationEnv ,
771+ } ) ;
772+ }
773+ } , { info : printInfo } ) ;
763774 } finally {
764775 // Option B: prune only when the desktop:dev session ends, not on each rebuild.
765776 await runDesktopTargetGc ( 'debug' ) ;
0 commit comments