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;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import io.netty.channel.Channel;
import io.netty.channel.group.ChannelGroup;
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.lambdaevents.LambdaManager;
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.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.options.Options;
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.ProxyStopEvent;
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.Client2ProxyHandler;
import net.raphimc.viaproxy.proxy.session.ProxyConnection;
import net.raphimc.viaproxy.saves.SaveManager;
import net.raphimc.viaproxy.tasks.LoaderTask;
import net.raphimc.viaproxy.tasks.UpdateCheckTask;
import net.raphimc.viaproxy.ui.SplashScreen;
import net.raphimc.viaproxy.ui.ViaProxyUI;
import net.raphimc.viaproxy.ui.events.UIInitEvent;
import net.raphimc.viaproxy.util.AddressUtil;
import net.raphimc.viaproxy.util.ClassLoaderPriorityUtil;
import net.raphimc.viaproxy.util.logging.Logger;
@ -61,6 +60,8 @@ import java.awt.*;
import java.io.IOException;
import java.lang.instrument.Instrumentation;
import java.lang.reflect.InvocationTargetException;
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
public class ViaProxy {
@ -134,45 +135,57 @@ public class ViaProxy {
}
}
ConsoleHandler.hookConsole();
ClassLoaderPriorityUtil.loadOverridingJars();
ViaProxy.loadNetty();
Classes.ensureInitialized(ProtocolVersion.class);
Classes.ensureInitialized(LegacyProtocolVersion.class);
Classes.ensureInitialized(AprilFoolsProtocolVersion.class);
Classes.ensureInitialized(BedrockProtocolVersion.class);
final SplashScreen splashScreen;
final Consumer<String> progressConsumer;
if (hasUI) {
final float progressStep = 1F / 7F;
splashScreen = new SplashScreen();
progressConsumer = (text) -> {
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();
progressConsumer.accept("Loading Plugins");
PLUGIN_MANAGER = new PluginManager();
final Thread loaderThread = new Thread(new LoaderTask(), "ViaLoader");
final Thread updateCheckThread = new Thread(new UpdateCheckTask(hasUI), "UpdateCheck");
if (hasUI) {
loaderThread.start();
progressConsumer.accept("Loading GUI");
SwingUtilities.invokeAndWait(() -> {
try {
ui = new ViaProxyUI();
progressConsumer.accept("Done");
splashScreen.dispose();
} catch (Throwable e) {
Logger.LOGGER.fatal("Failed to initialize UI", e);
System.exit(1);
}
});
if (System.getProperty("skipUpdateCheck") == null) {
updateCheckThread.start();
CompletableFuture.runAsync(new UpdateCheckTask(true));
}
loaderThread.join();
ui.eventManager.call(new UIInitEvent());
EVENT_MANAGER.call(new ViaProxyLoadedEvent());
Logger.LOGGER.info("ViaProxy started successfully!");
} else {
Options.parse(args);
if (System.getProperty("skipUpdateCheck") == null) {
updateCheckThread.start();
CompletableFuture.runAsync(new UpdateCheckTask(false));
}
loaderThread.start();
loaderThread.join();
EVENT_MANAGER.call(new ViaProxyLoadedEvent());
Logger.LOGGER.info("ViaProxy started successfully!");
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);
}
public float getProgress() {
return this.progressPanel.progress;
}
public void setProgress(final float progress) {
this.progressPanel.progress = Math.max(0, Math.min(1, progress));
this.progressPanel.repaint();

View File

@ -20,14 +20,12 @@ package net.raphimc.viaproxy.ui;
import com.formdev.flatlaf.FlatDarkLaf;
import com.formdev.flatlaf.extras.FlatInspector;
import com.formdev.flatlaf.extras.FlatUIDefaultsInspector;
import net.lenni0451.lambdaevents.EventHandler;
import net.lenni0451.lambdaevents.LambdaManager;
import net.lenni0451.lambdaevents.generator.LambdaMetaFactoryGenerator;
import net.lenni0451.reflect.JavaBypass;
import net.lenni0451.reflect.stream.RStream;
import net.raphimc.viaproxy.ViaProxy;
import net.raphimc.viaproxy.ui.events.UICloseEvent;
import net.raphimc.viaproxy.ui.events.UIInitEvent;
import net.raphimc.viaproxy.ui.impl.*;
import net.raphimc.viaproxy.util.logging.Logger;
@ -120,16 +118,6 @@ public class ViaProxyUI extends JFrame {
int selectedIndex = contentPane.getSelectedIndex();
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) {

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;
import net.lenni0451.commons.swing.GBC;
import net.lenni0451.lambdaevents.EventHandler;
import net.raphimc.minecraftauth.MinecraftAuth;
import net.raphimc.minecraftauth.step.msa.StepMsaDeviceCode;
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.I18n;
import net.raphimc.viaproxy.ui.ViaProxyUI;
import net.raphimc.viaproxy.ui.events.UIInitEvent;
import net.raphimc.viaproxy.ui.popups.AddAccountPopup;
import net.raphimc.viaproxy.util.TFunction;
@ -204,10 +202,7 @@ public class AccountsTab extends AUITab {
contentPane.setLayout(new BorderLayout());
contentPane.add(body, BorderLayout.CENTER);
}
@EventHandler
private void onInit(final UIInitEvent event) {
ViaProxy.getSaveManager().accountsSave.getAccounts().forEach(this::addAccount);
DefaultListModel<Account> model = (DefaultListModel<Account>) this.accountsList.getModel();
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.ViaProxyUI;
import net.raphimc.viaproxy.ui.events.UICloseEvent;
import net.raphimc.viaproxy.ui.events.UIInitEvent;
import net.raphimc.viaproxy.util.logging.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender;
@ -141,7 +140,6 @@ public class AdvancedTab extends AUITab {
SwingUtilities.invokeLater(() -> this.viaVersionDumpButton.setEnabled(true));
});
});
this.viaVersionDumpButton.setEnabled(false);
footer.add(this.viaVersionDumpButton);
}
{
@ -183,13 +181,6 @@ public class AdvancedTab extends AUITab {
container.add(padding, BorderLayout.SOUTH);
}
@EventHandler
private void onInit(final UIInitEvent event) {
SwingUtilities.invokeLater(() -> {
this.viaVersionDumpButton.setEnabled(true);
});
}
@EventHandler
private void onClose(final UICloseEvent event) {
UISave save = ViaProxy.getSaveManager().uiSave;

View File

@ -17,6 +17,7 @@
*/
package net.raphimc.viaproxy.ui.impl;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import net.lenni0451.commons.swing.GBC;
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.ViaProxyUI;
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.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);
parent.add(footer, BorderLayout.SOUTH);
}
@EventHandler
private void setReady(final UIInitEvent event) {
SwingUtilities.invokeLater(() -> {
this.stateButton.setText(I18n.get("tab.general.state.start"));
this.stateButton.setEnabled(true);
final Timer timer = new Timer(100, null);
timer.addActionListener(event -> {
if (Via.getManager().getProtocolManager().hasLoadedMappings()) {
this.stateButton.setText(I18n.get("tab.general.state.start"));
this.stateButton.setEnabled(true);
timer.stop();
}
});
timer.start();
}
@EventHandler

View File

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