GTK: Fix launching
ci/woodpecker/push/docs Pipeline was successful Details
ci/woodpecker/push/woodpecker Pipeline was successful Details

This commit is contained in:
Johannes Frohnmeyer 2023-01-28 14:15:17 +01:00
parent a93f2c8411
commit 08bb13f994
Signed by: Johannes
GPG Key ID: E76429612C2929F4
10 changed files with 111 additions and 47 deletions

View File

@ -1,5 +1,7 @@
package io.gitlab.jfronny.inceptum.gtk;
import io.gitlab.jfronny.inceptum.gtk.window.dialog.MicrosoftLoginDialog;
import io.gitlab.jfronny.inceptum.gtk.window.dialog.StringInputDialog;
import org.gtk.gtk.*;
import io.gitlab.jfronny.commons.StringFormatter;
import io.gitlab.jfronny.inceptum.common.Utils;
@ -40,29 +42,28 @@ public enum GtkEnvBackend implements LauncherEnv.EnvBackend { //TODO test
@Override
public void getInput(String prompt, String details, String defaultValue, Consumer<String> ok, Runnable cancel) {
//TODO spacing
//TODO run on main thread
GtkMain.schedule(() -> {
Dialog dialog = new Dialog();
if (dialogParent != null) dialog.transientFor = dialogParent;
dialog.modal = true;
if (dialogParent != null) dialog.destroyWithParent = true;
DialogFlags flags = DialogFlags.DESTROY_WITH_PARENT;
if (dialogParent != null) flags = flags.or(DialogFlags.MODAL);
StringInputDialog dialog = new StringInputDialog(
dialogParent,
flags,
MessageType.QUESTION,
ButtonsType.OK_CANCEL,
details,
defaultValue
);
dialog.title = prompt;
Box box = dialog.contentArea;
box.append(new Label(details));
Entry entry = new Entry();
entry.text = defaultValue;
box.append(entry);
dialog.addButton(I18n.get("ok"), ResponseType.OK.getValue());
dialog.addButton(I18n.get("cancel"), ResponseType.CANCEL.getValue());
dialog.onResponse(processResponses(dialog, () -> ok.accept(entry.text), cancel));
dialog.onResponse(processResponses(dialog, () -> ok.accept(dialog.input), cancel));
dialog.show();
});
}
@Override
public void showLoginRefreshPrompt(MicrosoftAccount account) {
//TODO
GtkMain.schedule(() -> {
new MicrosoftLoginDialog(dialogParent, account).show();
});
}
private void simpleDialog(String markup, String title, MessageType type, ButtonsType buttons, Runnable ok, Runnable cancel) {

View File

@ -85,13 +85,11 @@ public class GtkMenubar {
Utils.LOGGER.error("Could not fetch instance, trying to start anyways", e);
}
if (!cancel.get()) {
if (launchType == LaunchType.Client) InstanceLauncher.launchClient(instance);
else {
try {
InstanceLauncher.launch(instance, launchType, false, AccountManager.NULL_AUTH);
} catch (LaunchException | IOException e) {
LauncherEnv.showError("Could not start instance", e);
}
try {
if (launchType == LaunchType.Client) InstanceLauncher.launchClient(instance);
else InstanceLauncher.launch(instance, launchType, false, AccountManager.NULL_AUTH);
} catch (Throwable e) {
LauncherEnv.showError("Could not start instance", e);
}
}
},

View File

@ -6,21 +6,13 @@ import java.util.function.Consumer;
public class ISEntry extends Entry {
public ISEntry(String content) {
setContent(content);
this.text = content;
hexpand = true;
halign = Align.FILL;
valign = Align.CENTER;
}
public String getContent() {
return buffer.text;
}
public void setContent(String content) {
buffer = EntryBuffer.builder().setText(content).build();
}
public void onChanged(Consumer<String> s) {
super.onChanged(() -> s.accept(buffer.text));
super.onChanged(() -> s.accept(text));
}
}

View File

@ -18,6 +18,7 @@ import org.gnome.adw.HeaderBar;
import org.gnome.adw.*;
import org.gtk.gobject.BindingFlags;
import org.gtk.gtk.Application;
import org.gtk.gtk.MessageDialog;
import org.gtk.gtk.Window;
import org.gtk.gtk.*;
@ -76,7 +77,7 @@ public class InstanceSettingsWindow extends Window {
apply.valign = Align.CENTER;
apply.onClicked(() -> {
try {
Path newPath = MetaHolder.INSTANCE_DIR.resolve(InstanceNameTool.getNextValid(entry.content));
Path newPath = MetaHolder.INSTANCE_DIR.resolve(InstanceNameTool.getNextValid(entry.text));
Files.move(instance.path, newPath);
close();
new InstanceSettingsWindow(application, InstanceList.read(newPath)).show();
@ -230,17 +231,16 @@ public class InstanceSettingsWindow extends Window {
cancel -> {
exporter.generate(state, instance, path);
GtkMain.schedule(() -> {
Dialog success = Dialog.newWithButtons(
I18n.get("instance.settings.export.dialog.success.title"),
MessageDialog success = new MessageDialog(
this,
DialogFlags.MODAL.or(DialogFlags.DESTROY_WITH_PARENT),
I18n.get("show"),
ResponseType.OK,
I18n.get("ok"),
ResponseType.CANCEL,
null
MessageType.INFO,
ButtonsType.NONE,
I18n.get("instance.settings.export.dialog.success", instance.name, path.toString())
);
success.contentArea.append(new ILabel("instance.settings.export.dialog.success", instance.name, path.toString()));
success.title = I18n.get("instance.settings.export.dialog.success.title");
success.addButton(I18n.get("show"), ResponseType.OK.value);
success.addButton(I18n.get("ok"), ResponseType.CANCEL.value);
success.onResponse(responseId1 -> {
switch (ResponseType.of(responseId1)) {
case OK -> {

View File

@ -0,0 +1,46 @@
package io.gitlab.jfronny.inceptum.gtk.window.dialog;
import io.gitlab.jfronny.inceptum.common.Utils;
import io.gitlab.jfronny.inceptum.gtk.util.I18n;
import io.gitlab.jfronny.inceptum.launcher.api.account.*;
import org.gtk.gtk.*;
import org.jetbrains.annotations.Nullable;
import java.net.URI;
import java.net.URISyntaxException;
public class MicrosoftLoginDialog extends MessageDialog {
private static DialogFlags flags(boolean modal) {
DialogFlags flags = DialogFlags.DESTROY_WITH_PARENT;
if (modal) flags = flags.or(DialogFlags.MODAL);
return flags;
}
public MicrosoftLoginDialog(@Nullable Window parent, MicrosoftAccount account) {
super(
parent,
flags(parent != null),
MessageType.QUESTION,
ButtonsType.CLOSE,
I18n.get("auth.description")
);
title = I18n.get("auth.title");
var btn = Button.newWithLabel(I18n.get("auth.open-browser"));
((Box) messageArea).append(btn);
btn.onClicked(() -> {
try {
Utils.openWebBrowser(new URI(MicrosoftAuthAPI.MICROSOFT_LOGIN_URL));
} catch (URISyntaxException e) {
Utils.LOGGER.error("Could not open browser", e);
}
});
var server = new MicrosoftAuthServer(account);
try {
server.start();
} catch (Exception e) {
Utils.LOGGER.error("Could not start mc login server", e);
}
onClose(server::close);
}
}

View File

@ -2,6 +2,7 @@ package io.gitlab.jfronny.inceptum.gtk.window.dialog;
import io.gitlab.jfronny.commons.throwable.ThrowingConsumer;
import io.gitlab.jfronny.inceptum.gtk.GtkMain;
import io.gitlab.jfronny.inceptum.gtk.util.I18n;
import io.gitlab.jfronny.inceptum.launcher.LauncherEnv;
import io.gitlab.jfronny.inceptum.launcher.util.ProcessState;
import org.gtk.glib.GLib;
@ -24,11 +25,11 @@ public class ProcessStateWatcherDialog extends MessageDialog {
}
public ProcessStateWatcherDialog(Window parent, String title, String errorMessage, ProcessState state, ThrowingConsumer<AtomicBoolean, ?> executor, @Nullable Runnable cancel) {
super(parent, DialogFlags.MODAL.or(DialogFlags.DESTROY_WITH_PARENT), MessageType.INFO, ButtonsType.CANCEL, null);
super(parent, DialogFlags.MODAL.or(DialogFlags.DESTROY_WITH_PARENT), MessageType.INFO, ButtonsType.NONE, null);
this.state = state;
this.cancel = cancel;
this.title = title;
if (cancel != null) addButton("Cancel", ResponseType.CANCEL.value);
if (cancel != null) addButton(I18n.get("cancel"), ResponseType.CANCEL.value);
onResponse(responseId -> {
if (responseId == ResponseType.CANCEL.value) {
canceled.set(true);
@ -46,7 +47,7 @@ public class ProcessStateWatcherDialog extends MessageDialog {
if (canceled.get() && cancel != null) cancel.run();
});
var progress = new ProgressBar();
contentArea.append(progress);
((Box) messageArea).append(progress);
addTickCallback((widget, clock) -> {
if (finished.get()) return GLib.SOURCE_REMOVE;
var nc = new State(state);

View File

@ -0,0 +1,18 @@
package io.gitlab.jfronny.inceptum.gtk.window.dialog;
import org.gtk.gtk.*;
import org.jetbrains.annotations.Nullable;
public class StringInputDialog extends MessageDialog {
private final Entry entry = new Entry();
public StringInputDialog(@Nullable Window parent, DialogFlags flags, MessageType type, ButtonsType buttons, @Nullable String message, String value) {
super(parent, flags, type, buttons, message);
((Box) messageArea).append(entry);
entry.text = value;
}
public String getInput() {
return entry.text;
}
}

View File

@ -64,4 +64,8 @@ instance.settings.export.dialog.success.title=Sucessfully exported
instance.settings.export.dialog.error=Could not export %1$s
instance.launch.error=Could not start instance
instance.launch.title=Starting instance
show=Show
show=Show
auth.title=Microsoft Login
auth.description=This feature uses modified ATLauncher code, so the login prompt will ask you to log in to ATLauncher.\
Click the button below to begin!
auth.open-browser=Open in Browser

View File

@ -64,4 +64,8 @@ instance.settings.export.dialog.success.title=Erfolgreich exportiert
instance.settings.export.dialog.error=Konnte %1$s nicht exportieren
instance.launch.error=Konnte Instanz nicht starten
instance.launch.title=Starting instance
show=Anzeigen
show=Anzeigen
auth.title=Microsoft-Anmeldung
auth.description=Diese Funktion nutzt Code des ATLauncher, weshalb der Anmeldebildschirm nach einer Anmeldung für ATLauncher fragen wird.\
Klicken Sie auf die Schaltfläche unten, um zu beginnen!<
auth.open-browser=Im Browser öffnen

View File

@ -64,6 +64,6 @@ public class McApi {
}
public static void downloadAsset(AssetIndex.Asset asset, Path path) throws IOException, URISyntaxException {
Net.downloadFile("http://resources.download.minecraft.net/" + asset.hash.substring(0, 2) + "/" + asset.hash, asset.hash, path);
Net.downloadFile("https://resources.download.minecraft.net/" + asset.hash.substring(0, 2) + "/" + asset.hash, asset.hash, path);
}
}