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 cffd01b
Show file tree
Hide file tree
Showing 3 changed files with 535 additions and 12 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
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 cffd01b

Please sign in to comment.