mirror of
https://github.com/packwiz/packwiz-installer.git
synced 2025-04-19 21:16:30 +02:00
Revamp UI system, improve UpdateManager
This commit is contained in:
parent
fd87edd6ca
commit
905630cb2a
10
build.gradle
10
build.gradle
@ -9,6 +9,7 @@ dependencies {
|
||||
implementation 'commons-cli:commons-cli:1.4'
|
||||
implementation 'com.moandjiezana.toml:toml4j:0.7.2'
|
||||
//testImplementation 'junit:junit:4.12'
|
||||
// TODO: add GSON, as toml4j depends on it anyway
|
||||
}
|
||||
|
||||
repositories {
|
||||
@ -34,3 +35,12 @@ shadowJar {
|
||||
exclude(dependency('com.eclipsesource.minimal-json:minimal-json:0.9.5'))
|
||||
}
|
||||
}
|
||||
|
||||
// Used for vscode launch.json
|
||||
task copyJar(type: Copy) {
|
||||
from shadowJar
|
||||
rename "packwiz-installer-(.*)\\.jar", "packwiz-installer.jar"
|
||||
into "build/libs/"
|
||||
}
|
||||
|
||||
build.dependsOn copyJar
|
13
src/main/java/link/infra/packwiz/installer/CLIHandler.java
Normal file
13
src/main/java/link/infra/packwiz/installer/CLIHandler.java
Normal file
@ -0,0 +1,13 @@
|
||||
package link.infra.packwiz.installer;
|
||||
|
||||
public class CLIHandler implements IUserInterface {
|
||||
|
||||
@Override
|
||||
public void handleException(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show() {}
|
||||
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package link.infra.packwiz.installer;
|
||||
|
||||
public interface IUserInterface {
|
||||
|
||||
public void show();
|
||||
|
||||
public void handleException(Exception e);
|
||||
|
||||
public default void handleExceptionAndExit(Exception e) {
|
||||
handleException(e);
|
||||
System.exit(1);
|
||||
};
|
||||
|
||||
public default void setTitle(String title) {};
|
||||
|
||||
}
|
@ -9,6 +9,7 @@ import java.awt.GridBagLayout;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JProgressBar;
|
||||
import javax.swing.UIManager;
|
||||
@ -16,23 +17,19 @@ import javax.swing.border.EmptyBorder;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
public class InstallWindow {
|
||||
|
||||
// TODO: move to seperate file, make usable without GUI
|
||||
public class InstallWindow implements IUserInterface {
|
||||
|
||||
private JFrame frmPackwizlauncher;
|
||||
private UpdateManager updateManager = new UpdateManager();
|
||||
private String title = "Updating modpack...";
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
@Override
|
||||
public void show() {
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
InstallWindow window = new InstallWindow();
|
||||
window.frmPackwizlauncher.setVisible(true);
|
||||
InstallWindow.this.initialize();
|
||||
InstallWindow.this.frmPackwizlauncher.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -40,19 +37,12 @@ public class InstallWindow {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the application.
|
||||
*/
|
||||
public InstallWindow() {
|
||||
initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the contents of the frame.
|
||||
*/
|
||||
private void initialize() {
|
||||
frmPackwizlauncher = new JFrame();
|
||||
frmPackwizlauncher.setTitle("Updating modpack...");
|
||||
frmPackwizlauncher.setTitle(title);
|
||||
frmPackwizlauncher.setBounds(100, 100, 493, 95);
|
||||
frmPackwizlauncher.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frmPackwizlauncher.setLocationRelativeTo(null);
|
||||
@ -85,7 +75,7 @@ public class InstallWindow {
|
||||
JButton btnCancel = new JButton("Cancel");
|
||||
btnCancel.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
updateManager.cleanup();
|
||||
//updateManager.cleanup();
|
||||
frmPackwizlauncher.dispose();
|
||||
}
|
||||
});
|
||||
@ -96,4 +86,21 @@ public class InstallWindow {
|
||||
panel_1.add(btnCancel, gbc_btnCancel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleException(Exception e) {
|
||||
JOptionPane.showMessageDialog(null, e.getMessage(), title, JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
if (frmPackwizlauncher != null) {
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
InstallWindow.this.frmPackwizlauncher.setTitle(title);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -33,12 +33,38 @@ public class Main {
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
System.out.println("Hello World!");
|
||||
IUserInterface ui;
|
||||
if (cmd.hasOption("no-gui")) {
|
||||
ui = new CLIHandler();
|
||||
} else {
|
||||
ui = new InstallWindow();
|
||||
}
|
||||
|
||||
String[] unparsedArgs = cmd.getArgs();
|
||||
if (unparsedArgs.length > 1) {
|
||||
ui.handleExceptionAndExit(new RuntimeException("Too many arguments specified!"));
|
||||
} else if (unparsedArgs.length < 1) {
|
||||
ui.handleExceptionAndExit(new RuntimeException("URI to install from must be specified!"));
|
||||
}
|
||||
|
||||
String title = cmd.getOptionValue("title");
|
||||
if (title != null) {
|
||||
ui.setTitle(title);
|
||||
}
|
||||
|
||||
String side = cmd.getOptionValue("side");
|
||||
if (side == null) {
|
||||
side = "client";
|
||||
}
|
||||
|
||||
ui.show();
|
||||
|
||||
}
|
||||
|
||||
// Called by packwiz-installer-bootstrap to set up the help command
|
||||
public static void addNonBootstrapOptions(Options options) {
|
||||
//options.addOption("w", "welp", false, "Testing options");
|
||||
options.addOption("s", "side", true, "Side to install mods from (client/server, defaults to client)"); // TODO: implement
|
||||
options.addOption(null, "title", true, "Title of the installer window");
|
||||
}
|
||||
|
||||
// TODO: link these somehow so they're only defined once?
|
||||
@ -47,8 +73,8 @@ public class Main {
|
||||
options.addOption(null, "bootstrap-update-token", true, "Github API Access Token, for private repositories");
|
||||
options.addOption(null, "bootstrap-no-update", false, "Don't update packwiz-installer");
|
||||
options.addOption(null, "bootstrap-main-jar", true, "Location of the packwiz-installer JAR file");
|
||||
options.addOption("g", "no-gui", false, "Don't display a GUI to show update progress");
|
||||
options.addOption("h", "help", false, "Display this message");
|
||||
options.addOption("g", "no-gui", false, "Don't display a GUI to show update progress"); // TODO: implement
|
||||
options.addOption("h", "help", false, "Display this message"); // Implemented in packwiz-installer-bootstrap!
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,21 @@
|
||||
package link.infra.packwiz.installer;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
public class UpdateManager {
|
||||
Thread updateThread = new Thread(new UpdateThread());
|
||||
|
||||
public final Options opts;
|
||||
public final IUserInterface ui;
|
||||
|
||||
public static class Options {
|
||||
public URI downloadURI;
|
||||
public String manifestFile = "packwiz.json";
|
||||
}
|
||||
|
||||
public UpdateManager(Options opts, IUserInterface ui) {
|
||||
this.opts = opts;
|
||||
this.ui = ui;
|
||||
}
|
||||
|
||||
public void cleanup() {
|
||||
|
||||
|
@ -1,10 +0,0 @@
|
||||
package link.infra.packwiz.installer;
|
||||
|
||||
public class UpdateThread implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user