Fixes for account managing
This commit is contained in:
parent
8c22da0752
commit
b6fb915dd9
|
@ -163,7 +163,7 @@ public class InceptumGui {
|
|||
if (ImGui.begin(window.getName() + "##" + i, window.getOpenState(), window.getFlags()))
|
||||
window.draw();
|
||||
ImGui.end();
|
||||
if (!window.getOpenState().get()) window.close();
|
||||
if (!window.getOpenState().get() && !window.isClosed()) window.close();
|
||||
}
|
||||
}
|
||||
//end frame
|
||||
|
|
|
@ -5,5 +5,6 @@ public class Config {
|
|||
public boolean darkTheme = false;
|
||||
public boolean enforceAccount = true;
|
||||
public String lastAccount;
|
||||
public String offlineAccountLastName = null;
|
||||
public UpdateChannel channel = UpdateChannel.Stable;
|
||||
}
|
||||
|
|
|
@ -31,10 +31,15 @@ public class ClientLauncher {
|
|||
AuthInfo authInfo = AccountManager.getSelectedAccount();
|
||||
if (authInfo.equals(AccountManager.NULL_AUTH)) {
|
||||
try {
|
||||
Inceptum.getInput("User name", "Joe", name -> {
|
||||
String sysUser = System.getProperty("user.name");
|
||||
if (Inceptum.CONFIG.offlineAccountLastName == null)
|
||||
Inceptum.CONFIG.offlineAccountLastName = sysUser;
|
||||
Inceptum.getInput("User name", Inceptum.CONFIG.offlineAccountLastName, name -> {
|
||||
Inceptum.CONFIG.offlineAccountLastName = name.equals(sysUser) ? null : name;
|
||||
Inceptum.saveConfig();
|
||||
AuthInfo infoNew = new AuthInfo(name, authInfo.uuid(), authInfo.accessToken(), authInfo.userType());
|
||||
launchI(path, instance, infoNew);
|
||||
}, () -> launchI(path, instance, authInfo));
|
||||
}, () -> {});
|
||||
} catch (IOException e) {
|
||||
Inceptum.showError("Failed to request input", e);
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ public class AccountManager {
|
|||
public static final AuthInfo NULL_AUTH = new AuthInfo("Joe", "2536abce90e8476a871679918164abc5", "99abe417230342cb8e9e2168ab46297a", "legacy");
|
||||
|
||||
public static AuthInfo getSelectedAccount() {
|
||||
if (accountMissing()) return NULL_AUTH;
|
||||
if (SELECTED_ACCOUNT == null) return NULL_AUTH;
|
||||
else if (SELECTED_ACCOUNT.ensureAccessTokenValid(a -> {})) return new AuthInfo(SELECTED_ACCOUNT);
|
||||
else {
|
||||
Inceptum.LOGGER.error("Couldn't login properly, using offline mode");
|
||||
|
@ -26,13 +26,18 @@ public class AccountManager {
|
|||
}
|
||||
|
||||
public static boolean accountMissing() {
|
||||
return SELECTED_ACCOUNT == null;
|
||||
return ACCOUNTS.isEmpty();
|
||||
}
|
||||
|
||||
public static List<MicrosoftAccount> getAccounts() {
|
||||
return List.copyOf(ACCOUNTS);
|
||||
}
|
||||
|
||||
public static int getSelectedIndex() {
|
||||
if (SELECTED_ACCOUNT == null) return ACCOUNTS.size();
|
||||
return ACCOUNTS.indexOf(SELECTED_ACCOUNT);
|
||||
}
|
||||
|
||||
public static void saveAccounts() {
|
||||
try {
|
||||
Utils.writeObject(Inceptum.ACCOUNTS_PATH, ACCOUNTS);
|
||||
|
@ -56,9 +61,6 @@ public class AccountManager {
|
|||
SELECTED_ACCOUNT = account;
|
||||
}
|
||||
}
|
||||
if (SELECTED_ACCOUNT == null && ACCOUNTS.size() >= 1) {
|
||||
SELECTED_ACCOUNT = ACCOUNTS.get(0);
|
||||
}
|
||||
Inceptum.LOGGER.info("Finished loading accounts");
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ import java.util.function.Predicate;
|
|||
public class MainWindow extends Window {
|
||||
private final ImBoolean darkTheme = new ImBoolean(Inceptum.CONFIG.darkTheme);
|
||||
private final ImBoolean debugTools = new ImBoolean(false);
|
||||
private final ImInt accountIndex = new ImInt(0);
|
||||
private final ImInt accountIndex = new ImInt(AccountManager.getSelectedIndex());
|
||||
public MainWindow() {
|
||||
super("Inceptum");
|
||||
}
|
||||
|
@ -56,7 +56,8 @@ public class MainWindow extends Window {
|
|||
if (ImGui.menuItem("New")) InceptumGui.open(new MicrosoftLoginWindow());
|
||||
AuthInfo selected = AccountManager.getSelectedAccount();
|
||||
List<MicrosoftAccount> accounts = AccountManager.getAccounts();
|
||||
for (int i = 0, accountsSize = accounts.size(); i < accountsSize; i++) {
|
||||
int accountsSize = accounts.size();
|
||||
for (int i = 0; i < accountsSize; i++) {
|
||||
MicrosoftAccount account = accounts.get(i);
|
||||
if (selected.equals(account)) accountIndex.set(i);
|
||||
if (ImGui.radioButton(account.minecraftUsername, accountIndex, i)) {
|
||||
|
@ -65,6 +66,9 @@ public class MainWindow extends Window {
|
|||
ImGui.sameLine();
|
||||
if (ImGui.button("X")) AccountManager.removeAccount(account);
|
||||
}
|
||||
if (ImGui.radioButton("None", accountIndex, accountsSize)) {
|
||||
AccountManager.switchAccount(null);
|
||||
}
|
||||
ImGui.endMenu();
|
||||
}
|
||||
if (ImGui.beginMenu("Settings")) {
|
||||
|
|
|
@ -9,7 +9,7 @@ import java.io.Closeable;
|
|||
public abstract class Window implements Closeable {
|
||||
private final String name;
|
||||
private final ImBoolean openState = new ImBoolean(true);
|
||||
private boolean isNew = true;
|
||||
private State state = State.New;
|
||||
|
||||
public Window(String name) {
|
||||
this.name = name;
|
||||
|
@ -25,18 +25,23 @@ public abstract class Window implements Closeable {
|
|||
|
||||
@Override
|
||||
public void close() {
|
||||
state = State.Closed;
|
||||
openState.set(false);
|
||||
InceptumGui.WINDOWS.remove(this);
|
||||
}
|
||||
|
||||
public boolean isNew() {
|
||||
if (isNew) {
|
||||
isNew = false;
|
||||
if (state == State.New) {
|
||||
state = State.Open;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isClosed() {
|
||||
return state == State.Closed;
|
||||
}
|
||||
|
||||
public int getFlags() {
|
||||
return ImGuiWindowFlags.AlwaysAutoResize;
|
||||
}
|
||||
|
@ -44,4 +49,8 @@ public abstract class Window implements Closeable {
|
|||
public ImBoolean getOpenState() {
|
||||
return openState;
|
||||
}
|
||||
|
||||
public enum State {
|
||||
New, Open, Closed
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ public class AlertWindow extends Window {
|
|||
private final String message;
|
||||
private final Runnable onOk;
|
||||
private final Runnable onCancel;
|
||||
private boolean success = false;
|
||||
|
||||
public AlertWindow(String title, String message) {
|
||||
this(title, message, null, null);
|
||||
|
@ -24,14 +25,14 @@ public class AlertWindow extends Window {
|
|||
public void draw() {
|
||||
ImGui.text(message);
|
||||
if (ImGui.button("OK")) {
|
||||
super.close();
|
||||
if (onOk != null) onOk.run();
|
||||
success = true;
|
||||
close();
|
||||
}
|
||||
if (onOk != null || onCancel != null) {
|
||||
ImGui.sameLine();
|
||||
if (ImGui.button("Cancel")) {
|
||||
super.close();
|
||||
if (onCancel != null) onCancel.run();
|
||||
success = false;
|
||||
close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -44,6 +45,11 @@ public class AlertWindow extends Window {
|
|||
@Override
|
||||
public void close() {
|
||||
super.close();
|
||||
if (onCancel != null) onCancel.run();
|
||||
if (success) {
|
||||
if (onOk != null) onOk.run();
|
||||
}
|
||||
else {
|
||||
if (onCancel != null) onCancel.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ public class TextBoxWindow extends Window {
|
|||
private final Consumer<String> onOk;
|
||||
private final Runnable onCancel;
|
||||
private final ImString selected;
|
||||
private boolean success = false;
|
||||
|
||||
public TextBoxWindow(String name, String message, String defaultValue, Consumer<String> onOk, Runnable onCancel) {
|
||||
super(name);
|
||||
|
@ -25,14 +26,14 @@ public class TextBoxWindow extends Window {
|
|||
ImGui.text(message);
|
||||
ImGui.inputText("##yes", selected);
|
||||
if (ImGui.button("OK")) {
|
||||
super.close();
|
||||
if (onOk != null) onOk.accept(selected.get());
|
||||
success = true;
|
||||
close();
|
||||
}
|
||||
if (onOk != null || onCancel != null) {
|
||||
ImGui.sameLine();
|
||||
if (ImGui.button("Cancel")) {
|
||||
super.close();
|
||||
if (onCancel != null) onCancel.run();
|
||||
success = false;
|
||||
close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -40,6 +41,11 @@ public class TextBoxWindow extends Window {
|
|||
@Override
|
||||
public void close() {
|
||||
super.close();
|
||||
onCancel.run();
|
||||
if (success) {
|
||||
if (onOk != null) onOk.accept(selected.get());
|
||||
}
|
||||
else {
|
||||
if (onCancel != null) onCancel.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ public class ComparableVersion implements Comparable<ComparableVersion> {
|
|||
|
||||
public ComparableVersion(String string) {
|
||||
this.string = string;
|
||||
String[] split = string.split("[^0-9]");
|
||||
String[] split = string.split("[^0-9]+");
|
||||
List<Long> numbersList = new ArrayList<>();
|
||||
for (String s : split) {
|
||||
if (!s.isEmpty())
|
||||
|
|
Loading…
Reference in New Issue