@@ -107,9 +107,7 @@ class LauncherMigrator {
107
107
* <ul>
108
108
* <li>If launched with the old ImageJ launcher, call
109
109
* {@link #switchToNewLauncher()}.</li>
110
- * <li>If launched with the new Jaunch launcher, call
111
- * {@link #migrateShortcuts()} and {@link #migrateUpdateSite()}.</li>
112
- * <li>If launched in some other creative way, do nothing.</li>
110
+ * <li>Do nothing if launched with Jaunch or in some other creative way.</li>
113
111
* </ul>
114
112
*/
115
113
void checkLaunchStatus () {
@@ -124,20 +122,9 @@ void checkLaunchStatus() {
124
122
// The old launcher does not set the scijava.app.name property.
125
123
boolean oldLauncherUsed = System .getProperty ("scijava.app.name" ) == null ;
126
124
if (oldLauncherUsed ) switchToNewLauncher ();
127
- else {
128
- // FIXME if we change update shortcuts to be windows-style "warn only"
129
- // then it's not a problem to do it beforehand.
130
- // If we leave as-is then we need to make sure we're instructing the user
131
- // to run Help > Update... a second time after restarting to complete the
132
- // installation
133
- migrateShortcuts ();
134
- // FIXME if we are doing the actual site toggling here then they will need
135
- // to restart again to update. I'd prefer to do it in the switchToNewLauncher
136
- // logic. Also, I am curious if having this logic here would *prevent*
137
- // a user from using the new launcher with old update sites, which I think
138
- // is not intended/desired?
139
- migrateUpdateSite ();
140
- }
125
+ // NB: it is possible and valid to use Jaunch with the old Fiji update sites
126
+ // So we do not want to force updating to them just because the new launcher
127
+ // is being used.
141
128
}
142
129
143
130
/**
@@ -162,9 +149,8 @@ void checkLaunchStatus() {
162
149
* OS level rather than potentially exploding at the application level.
163
150
* </p>
164
151
*/
165
- private void migrateShortcuts () {
152
+ private void warnAboutShortcuts () {
166
153
// If no old launchers are present, assume we already did this.
167
- // FIXME: Which launcher(s) should we look for? All platforms? Or current only?
168
154
169
155
// Fix links within Linux .desktop files.
170
156
// ~/.local/share/applications
@@ -395,31 +381,31 @@ private void switchToNewLauncher() {
395
381
}
396
382
}
397
383
398
- // All looks good! We can finally relaunch safely with the new launcher.
384
+ // All looks good!
385
+ // Switch update sites, and then we can finally relaunch safely with the
386
+ // new launcher.
387
+ migrateUpdateSite ();
388
+ warnAboutShortcuts ();
399
389
File exeFile = exeFile (appSlug , appDir );
400
390
try {
401
- Process p = new ProcessBuilder (exeFile .getPath ()).start ();
402
- boolean terminated = p .waitFor (500 , TimeUnit .MILLISECONDS );
403
- if (terminated || !p .isAlive ()) {
404
- askForBugReport (log , appTitle , appSlug ,
405
- new RuntimeException ("New launcher terminated unexpectedly" ));
406
- return ;
407
- }
408
- // New process seems to be up and running; we are done. Whew!
409
- startExeRenameProcess (appDir .toPath ());
391
+ startExeRenameAndRestart (appDir .toPath (), exeFile .getAbsolutePath ());
410
392
appService .getContext ().dispose ();
411
393
System .exit (0 );
412
394
}
413
- catch (IOException | InterruptedException exc ) {
395
+ catch (IOException exc ) {
414
396
askForBugReport (log , appTitle , appSlug , exc );
415
397
}
416
398
}
417
399
418
400
/**
419
401
* Helper method to rename the current exe to a backup version, to discourage
420
402
* accidental use of a launcher that is incompatible with Java 21, for example
403
+ *
404
+ * After deletion, the given exePath is invoked, starting the post-update app
421
405
*/
422
- private static void startExeRenameProcess (Path appDir ) throws IOException {
406
+ private static void startExeRenameAndRestart (Path appDir ,
407
+ String exePath ) throws IOException
408
+ {
423
409
Path originalExe ;
424
410
if (OS_WIN ) {
425
411
if (ARCH .equals ("x32" )) {
@@ -464,7 +450,8 @@ private static void startExeRenameProcess(Path appDir) throws IOException {
464
450
" Write-Host \" Attempt $tries of " + numTries + " failed...\" ; " +
465
451
" if ($tries -eq " + numTries + ") { Write-Host 'Max attempts reached. Exiting.'; break; } " +
466
452
" Start-Sleep -Milliseconds " + checkIntervalMs + " " +
467
- "} }"
453
+ "} } " +
454
+ exePath
468
455
);
469
456
} else {
470
457
// Unix/Linux/Mac implementation using bash
@@ -486,9 +473,16 @@ private static void startExeRenameProcess(Path appDir) throws IOException {
486
473
" fi; " +
487
474
" sleep " + (checkIntervalMs / 1000.0 ) + "; " +
488
475
"done"
476
+ + exePath
489
477
);
490
478
}
491
479
480
+ // Write error output to a file if it doesn't exist already
481
+ File errFile = appDir .resolve ("fiji-restart.err" ).toFile ();
482
+ if (!errFile .exists ()) {
483
+ pb .redirectError (appDir .resolve ("fiji-restart.err" ).toFile ());
484
+ }
485
+
492
486
// Redirect process output (optional - for debugging)
493
487
// pb.redirectOutput(ProcessBuilder.Redirect.INHERIT);
494
488
// pb.redirectError(ProcessBuilder.Redirect.INHERIT);
0 commit comments