Skip to content

Commit

Permalink
WIP: Mega switch-up!
Browse files Browse the repository at this point in the history
Closes #93.
  • Loading branch information
ctrueden committed Oct 20, 2024
1 parent ff53573 commit d2c7b61
Show file tree
Hide file tree
Showing 3 changed files with 535 additions and 14 deletions.
10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@
</dependency>

<!-- SciJava dependencies -->
<dependency>
<groupId>org.scijava</groupId>
<artifactId>app-launcher</artifactId>
<version>0</version> <!-- FIXME -->
</dependency>
<dependency>
<groupId>org.scijava</groupId>
<artifactId>scijava-common</artifactId>
Expand Down Expand Up @@ -230,6 +235,11 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency><!--TEMP-->
<groupId>com.formdev</groupId>
<artifactId>flatlaf</artifactId>
<optional>true</optional>
</dependency>
</dependencies>

<repositories>
Expand Down
42 changes: 28 additions & 14 deletions src/main/java/net/imagej/ui/swing/updater/ImageJUpdater.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,28 @@
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 javax.swing.SwingUtilities;

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

import net.imagej.updater.FileObject;
import net.imagej.updater.FilesCollection;
import net.imagej.updater.Installer;
import net.imagej.updater.URLChange;
import net.imagej.updater.UpdaterUI;
import net.imagej.updater.UploaderService;
import net.imagej.updater.util.AvailableSites;
import net.imagej.updater.util.HTTPSUtil;
import net.imagej.updater.util.Progress;
import net.imagej.updater.util.UpdateCanceledException;
import net.imagej.updater.util.UpdaterUserInterface;
import net.imagej.updater.util.UpdaterUtil;
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 +66,6 @@
import org.scijava.plugin.Plugin;
import org.scijava.util.AppUtils;

import javax.swing.*;

/**
* The Updater. As a command.
*
Expand All @@ -69,8 +74,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 +91,7 @@ public class ImageJUpdater implements UpdaterUI {

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

if (errorIfDebian()) return;

Expand All @@ -91,14 +101,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,6 +195,12 @@ 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
{
Expand Down
Loading

0 comments on commit d2c7b61

Please sign in to comment.