Skip to content

Commit

Permalink
WIP: Add logic for migrating to Jaunch launcher
Browse files Browse the repository at this point in the history
Closes #93.
  • Loading branch information
ctrueden authored and hinerm committed Nov 21, 2024
1 parent 237405d commit 0b6b0b1
Show file tree
Hide file tree
Showing 3 changed files with 586 additions and 13 deletions.
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<groupId>net.imagej</groupId>
<artifactId>imagej-ui-swing</artifactId>
<version>1.0.2-SNAPSHOT</version>
<version>1.2.0-SNAPSHOT</version>

<name>ImageJ UI: Swing</name>
<description>ImageJ UI for Java Swing.</description>
Expand Down Expand Up @@ -160,6 +160,7 @@
<!-- NB: Deploy releases to the SciJava Maven repository. -->
<releaseProfiles>sign,deploy-to-scijava</releaseProfiles>

<app-launcher.version>2.0.0</app-launcher.version>
<jhotdraw.version>7.6.0</jhotdraw.version>
</properties>

Expand Down Expand Up @@ -189,6 +190,11 @@
</dependency>

<!-- SciJava dependencies -->
<dependency>
<groupId>org.scijava</groupId>
<artifactId>app-launcher</artifactId>
<version>${app-launcher.version}</version>
</dependency>
<dependency>
<groupId>org.scijava</groupId>
<artifactId>scijava-common</artifactId>
Expand Down
29 changes: 17 additions & 12 deletions src/main/java/net/imagej/ui/swing/updater/ImageJUpdater.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,25 @@

package net.imagej.ui.swing.updater;

import java.awt.EventQueue;
import java.io.DataInputStream;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.Authenticator;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLConnection;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;

import net.imagej.ui.swing.updater.ViewOptions.Option;
import net.imagej.updater.*;
import net.imagej.updater.Conflicts.Conflict;
import net.imagej.updater.util.*;

import org.scijava.Context;
import org.scijava.app.StatusService;
import org.scijava.command.CommandService;
import org.scijava.event.ContextDisposingEvent;
import org.scijava.event.EventHandler;
import org.scijava.log.LogService;
Expand All @@ -59,8 +57,6 @@
import org.scijava.plugin.Plugin;
import org.scijava.util.AppUtils;

import javax.swing.*;

/**
* The Updater. As a command.
*
Expand All @@ -69,8 +65,12 @@
@Plugin(type = UpdaterUI.class, menu = { @Menu(label = "Help"),
@Menu(label = "Update...") })
public class ImageJUpdater implements UpdaterUI {

private UpdaterFrame main;

@Parameter(required = false)
private Context context;

@Parameter(required = false)
private StatusService statusService;

Expand All @@ -82,6 +82,7 @@ public class ImageJUpdater implements UpdaterUI {

@Override
public void run() {
new LauncherMigrator(context).checkLaunchStatus();

if (errorIfDebian()) return;

Expand All @@ -91,14 +92,12 @@ public void run() {

if (errorIfNetworkInaccessible(log)) return;

String imagejDirProperty = System.getProperty("imagej.dir");
final File imagejRoot = imagejDirProperty != null ? new File(imagejDirProperty) :
AppUtils.getBaseDirectory("ij.dir", FilesCollection.class, "updater");
final FilesCollection files = new FilesCollection(log, imagejRoot);
final File appDir = getAppDirectory();
final FilesCollection files = new FilesCollection(log, appDir);

UpdaterUserInterface.set(new SwingUserInterface(log, statusService));

if (new File(imagejRoot, "update").exists()) {
if (new File(appDir, "update").exists()) {
if (!UpdaterUserInterface.get().promptYesNo("It is suggested that you restart ImageJ, then continue the update.\n"
+ "Alternately, you can attempt to continue the upgrade without\n"
+ "restarting, but ImageJ might crash.\n\n"
Expand Down Expand Up @@ -187,14 +186,20 @@ protected void updateConflictList() {
main.updateFilesTable();
}

static File getAppDirectory() {
String imagejDirProperty = System.getProperty("imagej.dir");
return imagejDirProperty != null ? new File(imagejDirProperty) :
AppUtils.getBaseDirectory("ij.dir", FilesCollection.class, "updater");
}

private void refreshUpdateSites(FilesCollection files)
throws InterruptedException, InvocationTargetException
{
List<URLChange>
changes = AvailableSites.initializeAndAddSites(files, (Logger) log);
if(ReviewSiteURLsDialog.shouldBeDisplayed(changes)) {
ReviewSiteURLsDialog dialog = new ReviewSiteURLsDialog(main, changes);
SwingUtilities.invokeAndWait(() -> dialog.setVisible(true));
EventQueue.invokeAndWait(() -> dialog.setVisible(true));
if(dialog.isOkPressed())
AvailableSites.applySitesURLUpdates(files, changes);
}
Expand Down
Loading

0 comments on commit 0b6b0b1

Please sign in to comment.