Implemented SplashScreen

This commit is contained in:
RaphiMC 2024-02-15 18:48:35 +01:00
parent 520e47b469
commit 78b062098d
No known key found for this signature in database
GPG Key ID: 0F6BB0657A03AC94
9 changed files with 51 additions and 108 deletions

View File

@ -17,7 +17,6 @@
*/ */
package net.raphimc.viaproxy; package net.raphimc.viaproxy;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.group.ChannelGroup; import io.netty.channel.group.ChannelGroup;
import io.netty.channel.group.DefaultChannelGroup; import io.netty.channel.group.DefaultChannelGroup;
@ -31,12 +30,12 @@ import net.lenni0451.classtransform.utils.loader.InjectionClassLoader;
import net.lenni0451.classtransform.utils.tree.IClassProvider; import net.lenni0451.classtransform.utils.tree.IClassProvider;
import net.lenni0451.lambdaevents.LambdaManager; import net.lenni0451.lambdaevents.LambdaManager;
import net.lenni0451.lambdaevents.generator.LambdaMetaFactoryGenerator; import net.lenni0451.lambdaevents.generator.LambdaMetaFactoryGenerator;
import net.lenni0451.reflect.*; import net.lenni0451.reflect.Agents;
import net.lenni0451.reflect.ClassLoaders;
import net.lenni0451.reflect.JavaBypass;
import net.lenni0451.reflect.Methods;
import net.raphimc.netminecraft.constants.MCPipeline; import net.raphimc.netminecraft.constants.MCPipeline;
import net.raphimc.netminecraft.netty.connection.NetServer; import net.raphimc.netminecraft.netty.connection.NetServer;
import net.raphimc.viaaprilfools.api.AprilFoolsProtocolVersion;
import net.raphimc.viabedrock.api.BedrockProtocolVersion;
import net.raphimc.vialegacy.api.LegacyProtocolVersion;
import net.raphimc.viaproxy.cli.ConsoleHandler; import net.raphimc.viaproxy.cli.ConsoleHandler;
import net.raphimc.viaproxy.cli.options.Options; import net.raphimc.viaproxy.cli.options.Options;
import net.raphimc.viaproxy.plugins.PluginManager; import net.raphimc.viaproxy.plugins.PluginManager;
@ -44,14 +43,14 @@ import net.raphimc.viaproxy.plugins.events.Client2ProxyHandlerCreationEvent;
import net.raphimc.viaproxy.plugins.events.ProxyStartEvent; import net.raphimc.viaproxy.plugins.events.ProxyStartEvent;
import net.raphimc.viaproxy.plugins.events.ProxyStopEvent; import net.raphimc.viaproxy.plugins.events.ProxyStopEvent;
import net.raphimc.viaproxy.plugins.events.ViaProxyLoadedEvent; import net.raphimc.viaproxy.plugins.events.ViaProxyLoadedEvent;
import net.raphimc.viaproxy.protocoltranslator.ProtocolTranslator;
import net.raphimc.viaproxy.proxy.client2proxy.Client2ProxyChannelInitializer; import net.raphimc.viaproxy.proxy.client2proxy.Client2ProxyChannelInitializer;
import net.raphimc.viaproxy.proxy.client2proxy.Client2ProxyHandler; import net.raphimc.viaproxy.proxy.client2proxy.Client2ProxyHandler;
import net.raphimc.viaproxy.proxy.session.ProxyConnection; import net.raphimc.viaproxy.proxy.session.ProxyConnection;
import net.raphimc.viaproxy.saves.SaveManager; import net.raphimc.viaproxy.saves.SaveManager;
import net.raphimc.viaproxy.tasks.LoaderTask;
import net.raphimc.viaproxy.tasks.UpdateCheckTask; import net.raphimc.viaproxy.tasks.UpdateCheckTask;
import net.raphimc.viaproxy.ui.SplashScreen;
import net.raphimc.viaproxy.ui.ViaProxyUI; import net.raphimc.viaproxy.ui.ViaProxyUI;
import net.raphimc.viaproxy.ui.events.UIInitEvent;
import net.raphimc.viaproxy.util.AddressUtil; import net.raphimc.viaproxy.util.AddressUtil;
import net.raphimc.viaproxy.util.ClassLoaderPriorityUtil; import net.raphimc.viaproxy.util.ClassLoaderPriorityUtil;
import net.raphimc.viaproxy.util.logging.Logger; import net.raphimc.viaproxy.util.logging.Logger;
@ -61,6 +60,8 @@ import java.awt.*;
import java.io.IOException; import java.io.IOException;
import java.lang.instrument.Instrumentation; import java.lang.instrument.Instrumentation;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
public class ViaProxy { public class ViaProxy {
@ -134,45 +135,57 @@ public class ViaProxy {
} }
} }
ConsoleHandler.hookConsole(); final SplashScreen splashScreen;
ClassLoaderPriorityUtil.loadOverridingJars(); final Consumer<String> progressConsumer;
ViaProxy.loadNetty(); if (hasUI) {
Classes.ensureInitialized(ProtocolVersion.class); final float progressStep = 1F / 7F;
Classes.ensureInitialized(LegacyProtocolVersion.class); splashScreen = new SplashScreen();
Classes.ensureInitialized(AprilFoolsProtocolVersion.class); progressConsumer = (text) -> {
Classes.ensureInitialized(BedrockProtocolVersion.class); splashScreen.setProgress(splashScreen.getProgress() + progressStep);
splashScreen.setText(text);
};
} else {
splashScreen = null;
progressConsumer = text -> {
};
}
progressConsumer.accept("Initializing ViaProxy");
ConsoleHandler.hookConsole();
ViaProxy.loadNetty();
progressConsumer.accept("Loading Overriding Jars");
ClassLoaderPriorityUtil.loadOverridingJars();
progressConsumer.accept("Loading Protocol Translators");
ProtocolTranslator.init();
progressConsumer.accept("Loading Saves");
SAVE_MANAGER = new SaveManager(); SAVE_MANAGER = new SaveManager();
progressConsumer.accept("Loading Plugins");
PLUGIN_MANAGER = new PluginManager(); PLUGIN_MANAGER = new PluginManager();
final Thread loaderThread = new Thread(new LoaderTask(), "ViaLoader");
final Thread updateCheckThread = new Thread(new UpdateCheckTask(hasUI), "UpdateCheck");
if (hasUI) { if (hasUI) {
loaderThread.start(); progressConsumer.accept("Loading GUI");
SwingUtilities.invokeAndWait(() -> { SwingUtilities.invokeAndWait(() -> {
try { try {
ui = new ViaProxyUI(); ui = new ViaProxyUI();
progressConsumer.accept("Done");
splashScreen.dispose();
} catch (Throwable e) { } catch (Throwable e) {
Logger.LOGGER.fatal("Failed to initialize UI", e); Logger.LOGGER.fatal("Failed to initialize UI", e);
System.exit(1); System.exit(1);
} }
}); });
if (System.getProperty("skipUpdateCheck") == null) { if (System.getProperty("skipUpdateCheck") == null) {
updateCheckThread.start(); CompletableFuture.runAsync(new UpdateCheckTask(true));
} }
loaderThread.join();
ui.eventManager.call(new UIInitEvent());
EVENT_MANAGER.call(new ViaProxyLoadedEvent()); EVENT_MANAGER.call(new ViaProxyLoadedEvent());
Logger.LOGGER.info("ViaProxy started successfully!"); Logger.LOGGER.info("ViaProxy started successfully!");
} else { } else {
Options.parse(args); Options.parse(args);
if (System.getProperty("skipUpdateCheck") == null) { if (System.getProperty("skipUpdateCheck") == null) {
updateCheckThread.start(); CompletableFuture.runAsync(new UpdateCheckTask(false));
} }
loaderThread.start();
loaderThread.join();
EVENT_MANAGER.call(new ViaProxyLoadedEvent()); EVENT_MANAGER.call(new ViaProxyLoadedEvent());
Logger.LOGGER.info("ViaProxy started successfully!"); Logger.LOGGER.info("ViaProxy started successfully!");
startProxy(); startProxy();

View File

@ -1,29 +0,0 @@
/*
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
* Copyright (C) 2021-2024 RK_01/RaphiMC and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.raphimc.viaproxy.tasks;
import net.raphimc.viaproxy.protocoltranslator.ProtocolTranslator;
public class LoaderTask implements Runnable {
@Override
public void run() {
ProtocolTranslator.init();
}
}

View File

@ -49,6 +49,10 @@ public class SplashScreen extends JFrame {
this.setContentPane(contentPane); this.setContentPane(contentPane);
} }
public float getProgress() {
return this.progressPanel.progress;
}
public void setProgress(final float progress) { public void setProgress(final float progress) {
this.progressPanel.progress = Math.max(0, Math.min(1, progress)); this.progressPanel.progress = Math.max(0, Math.min(1, progress));
this.progressPanel.repaint(); this.progressPanel.repaint();

View File

@ -20,14 +20,12 @@ package net.raphimc.viaproxy.ui;
import com.formdev.flatlaf.FlatDarkLaf; import com.formdev.flatlaf.FlatDarkLaf;
import com.formdev.flatlaf.extras.FlatInspector; import com.formdev.flatlaf.extras.FlatInspector;
import com.formdev.flatlaf.extras.FlatUIDefaultsInspector; import com.formdev.flatlaf.extras.FlatUIDefaultsInspector;
import net.lenni0451.lambdaevents.EventHandler;
import net.lenni0451.lambdaevents.LambdaManager; import net.lenni0451.lambdaevents.LambdaManager;
import net.lenni0451.lambdaevents.generator.LambdaMetaFactoryGenerator; import net.lenni0451.lambdaevents.generator.LambdaMetaFactoryGenerator;
import net.lenni0451.reflect.JavaBypass; import net.lenni0451.reflect.JavaBypass;
import net.lenni0451.reflect.stream.RStream; import net.lenni0451.reflect.stream.RStream;
import net.raphimc.viaproxy.ViaProxy; import net.raphimc.viaproxy.ViaProxy;
import net.raphimc.viaproxy.ui.events.UICloseEvent; import net.raphimc.viaproxy.ui.events.UICloseEvent;
import net.raphimc.viaproxy.ui.events.UIInitEvent;
import net.raphimc.viaproxy.ui.impl.*; import net.raphimc.viaproxy.ui.impl.*;
import net.raphimc.viaproxy.util.logging.Logger; import net.raphimc.viaproxy.util.logging.Logger;
@ -120,16 +118,6 @@ public class ViaProxyUI extends JFrame {
int selectedIndex = contentPane.getSelectedIndex(); int selectedIndex = contentPane.getSelectedIndex();
if (selectedIndex >= 0 && selectedIndex < ViaProxyUI.this.tabs.size()) ViaProxyUI.this.tabs.get(selectedIndex).onTabOpened(); if (selectedIndex >= 0 && selectedIndex < ViaProxyUI.this.tabs.size()) ViaProxyUI.this.tabs.get(selectedIndex).onTabOpened();
}); });
this.contentPane.setEnabledAt(this.contentPane.indexOfTab(this.accountsTab.getName()), false);
this.contentPane.setEnabledAt(this.contentPane.indexOfTab(this.realmsTab.getName()), false);
}
@EventHandler
private void onInit(final UIInitEvent event) {
for (int i = 0; i < this.contentPane.getTabCount(); i++) {
this.contentPane.setEnabledAt(i, true);
}
} }
public void openURL(final String url) { public void openURL(final String url) {

View File

@ -1,21 +0,0 @@
/*
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
* Copyright (C) 2021-2024 RK_01/RaphiMC and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.raphimc.viaproxy.ui.events;
public class UIInitEvent {
}

View File

@ -18,7 +18,6 @@
package net.raphimc.viaproxy.ui.impl; package net.raphimc.viaproxy.ui.impl;
import net.lenni0451.commons.swing.GBC; import net.lenni0451.commons.swing.GBC;
import net.lenni0451.lambdaevents.EventHandler;
import net.raphimc.minecraftauth.MinecraftAuth; import net.raphimc.minecraftauth.MinecraftAuth;
import net.raphimc.minecraftauth.step.msa.StepMsaDeviceCode; import net.raphimc.minecraftauth.step.msa.StepMsaDeviceCode;
import net.raphimc.viaproxy.ViaProxy; import net.raphimc.viaproxy.ViaProxy;
@ -29,7 +28,6 @@ import net.raphimc.viaproxy.saves.impl.accounts.MicrosoftAccount;
import net.raphimc.viaproxy.ui.AUITab; import net.raphimc.viaproxy.ui.AUITab;
import net.raphimc.viaproxy.ui.I18n; import net.raphimc.viaproxy.ui.I18n;
import net.raphimc.viaproxy.ui.ViaProxyUI; import net.raphimc.viaproxy.ui.ViaProxyUI;
import net.raphimc.viaproxy.ui.events.UIInitEvent;
import net.raphimc.viaproxy.ui.popups.AddAccountPopup; import net.raphimc.viaproxy.ui.popups.AddAccountPopup;
import net.raphimc.viaproxy.util.TFunction; import net.raphimc.viaproxy.util.TFunction;
@ -204,10 +202,7 @@ public class AccountsTab extends AUITab {
contentPane.setLayout(new BorderLayout()); contentPane.setLayout(new BorderLayout());
contentPane.add(body, BorderLayout.CENTER); contentPane.add(body, BorderLayout.CENTER);
}
@EventHandler
private void onInit(final UIInitEvent event) {
ViaProxy.getSaveManager().accountsSave.getAccounts().forEach(this::addAccount); ViaProxy.getSaveManager().accountsSave.getAccounts().forEach(this::addAccount);
DefaultListModel<Account> model = (DefaultListModel<Account>) this.accountsList.getModel(); DefaultListModel<Account> model = (DefaultListModel<Account>) this.accountsList.getModel();
if (!model.isEmpty()) this.markSelected(0); if (!model.isEmpty()) this.markSelected(0);

View File

@ -28,7 +28,6 @@ import net.raphimc.viaproxy.ui.AUITab;
import net.raphimc.viaproxy.ui.I18n; import net.raphimc.viaproxy.ui.I18n;
import net.raphimc.viaproxy.ui.ViaProxyUI; import net.raphimc.viaproxy.ui.ViaProxyUI;
import net.raphimc.viaproxy.ui.events.UICloseEvent; import net.raphimc.viaproxy.ui.events.UICloseEvent;
import net.raphimc.viaproxy.ui.events.UIInitEvent;
import net.raphimc.viaproxy.util.logging.Logger; import net.raphimc.viaproxy.util.logging.Logger;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender; import org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender;
@ -141,7 +140,6 @@ public class AdvancedTab extends AUITab {
SwingUtilities.invokeLater(() -> this.viaVersionDumpButton.setEnabled(true)); SwingUtilities.invokeLater(() -> this.viaVersionDumpButton.setEnabled(true));
}); });
}); });
this.viaVersionDumpButton.setEnabled(false);
footer.add(this.viaVersionDumpButton); footer.add(this.viaVersionDumpButton);
} }
{ {
@ -183,13 +181,6 @@ public class AdvancedTab extends AUITab {
container.add(padding, BorderLayout.SOUTH); container.add(padding, BorderLayout.SOUTH);
} }
@EventHandler
private void onInit(final UIInitEvent event) {
SwingUtilities.invokeLater(() -> {
this.viaVersionDumpButton.setEnabled(true);
});
}
@EventHandler @EventHandler
private void onClose(final UICloseEvent event) { private void onClose(final UICloseEvent event) {
UISave save = ViaProxy.getSaveManager().uiSave; UISave save = ViaProxy.getSaveManager().uiSave;

View File

@ -17,6 +17,7 @@
*/ */
package net.raphimc.viaproxy.ui.impl; package net.raphimc.viaproxy.ui.impl;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import net.lenni0451.commons.swing.GBC; import net.lenni0451.commons.swing.GBC;
import net.lenni0451.lambdaevents.EventHandler; import net.lenni0451.lambdaevents.EventHandler;
@ -31,7 +32,6 @@ import net.raphimc.viaproxy.ui.AUITab;
import net.raphimc.viaproxy.ui.I18n; import net.raphimc.viaproxy.ui.I18n;
import net.raphimc.viaproxy.ui.ViaProxyUI; import net.raphimc.viaproxy.ui.ViaProxyUI;
import net.raphimc.viaproxy.ui.events.UICloseEvent; import net.raphimc.viaproxy.ui.events.UICloseEvent;
import net.raphimc.viaproxy.ui.events.UIInitEvent;
import net.raphimc.viaproxy.util.AddressUtil; import net.raphimc.viaproxy.util.AddressUtil;
import net.raphimc.viaproxy.util.logging.Logger; import net.raphimc.viaproxy.util.logging.Logger;
@ -180,14 +180,16 @@ public class GeneralTab extends AUITab {
GBC.create(footer).grid(0, 1).weightx(1).insets(0, BORDER_PADDING, BORDER_PADDING, BORDER_PADDING).anchor(GBC.WEST).fill(GBC.HORIZONTAL).add(this.stateButton); GBC.create(footer).grid(0, 1).weightx(1).insets(0, BORDER_PADDING, BORDER_PADDING, BORDER_PADDING).anchor(GBC.WEST).fill(GBC.HORIZONTAL).add(this.stateButton);
parent.add(footer, BorderLayout.SOUTH); parent.add(footer, BorderLayout.SOUTH);
}
@EventHandler final Timer timer = new Timer(100, null);
private void setReady(final UIInitEvent event) { timer.addActionListener(event -> {
SwingUtilities.invokeLater(() -> { if (Via.getManager().getProtocolManager().hasLoadedMappings()) {
this.stateButton.setText(I18n.get("tab.general.state.start")); this.stateButton.setText(I18n.get("tab.general.state.start"));
this.stateButton.setEnabled(true); this.stateButton.setEnabled(true);
timer.stop();
}
}); });
timer.start();
} }
@EventHandler @EventHandler

View File

@ -69,7 +69,7 @@ public class RealmsTab extends AUITab {
LATEST_JAVA_SNAPSHOT = latestSnapshotVersion; LATEST_JAVA_SNAPSHOT = latestSnapshotVersion;
} }
private Account currentAccount = Options.MC_ACCOUNT; private Account currentAccount = null;
private ProtocolVersion currentSelectedJavaVersion = LATEST_JAVA_RELEASE; private ProtocolVersion currentSelectedJavaVersion = LATEST_JAVA_RELEASE;
public RealmsTab(final ViaProxyUI frame) { public RealmsTab(final ViaProxyUI frame) {