22
33import org .lwjgl .glfw .GLFW ;
44import redxax .oxy .remotely .RemotelyClient ;
5+ import redxax .oxy .remotely .config .Config ;
56import redxax .oxy .remotely .config .RemotelyConfigManager ;
67import redxax .oxy .remotely .config .SettingsScreenFactory ;
78import redxax .oxy .remotely .ui .widgets .DesktopIconWidget ;
8- import restudio .rebase .api .unified .InstanceApi ;
9- import restudio .rebase .instance .InstanceState ;
9+ import restudio .rebase .restudio .AuthStateListener ;
10+ import restudio .rebase .restudio .ReStudio ;
11+ import restudio .rebase .ui .screens .auth .ReStudioLoginScreen ;
1012import restudio .rebase .ui .worldmap .WorldMapScreen ;
1113import restudio .rebase .Rebase ;
1214import restudio .rebase .hosting .RemoteHost ;
2830import restudio .rescreen .ui .widgets .*;
2931import restudio .rescreen .util .Notification ;
3032import restudio .rescreen .util .Sound ;
31- import restudio .rescreen .util .ImageUtils ;
3233
3334import javax .imageio .ImageIO ;
3435import java .awt .image .BufferedImage ;
4041import static redxax .oxy .remotely .config .Config .remotelyDir ;
4142import static redxax .oxy .remotely .util .DevUtil .devPrint ;
4243import static redxax .oxy .remotely .util .ImageUtil .loadResourceIcon ;
43- import static restudio .rescreen .render .Render .drawOuterBorder ;
4444import static restudio .rescreen .util .SoundUtils .playSound ;
4545
46- public class ServerManagerScreen extends ReScreen {
46+ public class ServerManagerScreen extends ReScreen implements AuthStateListener {
4747 private final RemotelyClient remotelyClient ;
4848 private Instance instanceForDeletion ;
4949 private PopupWidget addServerPopup ;
@@ -57,6 +57,7 @@ public class ServerManagerScreen extends ReScreen {
5757 private AnimatedButton remoteHostConfirmButton ;
5858 private AnimatedButton remoteHostDeleteButton ;
5959 private final Object parent ;
60+ private IconButton userButton ;
6061 int bx1 = 0 , by1 = 0 , bx2 = 0 , by2 = 0 ;
6162
6263 private static BufferedImage unknown , serverIcon , paper , vanilla , fabric , forge , neoforge , waterfall , velocity , leaf , quilt , spigot , bukkit , purpur ;
@@ -75,16 +76,36 @@ public void init() {
7576 reloadInstancesSmartly ();
7677 loadIcons ();
7778 createPopups ();
79+ ReStudio .getInstance ().addListener (this );
7880
7981 int taskbarHeight = 28 ;
82+ String displayName = ReStudio .getInstance ().getDisplayName ();
83+ if (displayName == null || displayName .isBlank ()) displayName = ReStudio .getInstance ().getEmail ();
84+ if (displayName == null ) displayName = "Account" ;
85+
86+ userButton = new IconButton .Builder ()
87+ .imagePath ("steve.png" )
88+ .label (displayName )
89+ .onClick (this ::showUserMenu )
90+ .size (18 , 18 )
91+ .autoWidthOnTextChange (true )
92+ .build ();
93+
94+ ReStudio .getInstance ().loadAvatar ().thenAccept (img -> ScreenManager .getInstance ().execute (() -> {
95+ if (img != null && userButton != null ) {
96+ userButton .setIcon (img );
97+ }
98+ }));
99+
80100 header ().position (HeaderBuilder .Position .BOTTOM ).size (taskbarHeight )
81101 .addLeft ("terminal.png" , () -> remotelyClient .openMultiTerminal (this ), "Terminal" )
82102 .addLeft ("explorer.png" , this ::openFileExplorer , "File Explorer" )
83103 .addLeft ("remotely.png" , () -> client .setScreen (SettingsScreenFactory .createGlobalSettingsScreen ( this ,(RemotelyConfigManager ) Rebase .get ().getConfigManager ())), "Settings" )
104+ .addLeft (userButton )
84105 .build ();
85106
86107 tabs ().builder ()
87- .position (width / 2 , height - taskbarHeight + 4 )
108+ .position (width / 2 , height - taskbarHeight + 5 )
88109 .size (width / 2 - 5 , 18 )
89110 .rightToLeft (true )
90111 .allowAdd (true )
@@ -102,8 +123,35 @@ public void init() {
102123
103124 setActiveContainer (desktopContainer );
104125 populateHostTabs ();
126+ updatePositions ();
127+ }
128+
129+ private void showUserMenu () {
130+ ContextMenuWidget .Builder builder = new ContextMenuWidget .Builder (this ).addHeaderButton ("close.png" , () -> ReStudio .getInstance ().logout (), "Log Out" , ThemeManager .getAccent ("danger" ));
131+ showContextMenu (userButton .getX (), height - 35 , builder );
132+ }
133+
134+ @ Override
135+ public void onLogin (String email ) {
136+ new Notification .Builder ().message ("Welcome back!" ).description ("Email: " + (Config .showIp ? "" : "§k" ) + email ).type (Notification .Type .SUCCESS ).build ();
105137 }
106138
139+ @ Override
140+ public void onLogout () {
141+ ScreenManager .getInstance ().execute (() -> ScreenManager .getInstance ().setScreen (new ReStudioLoginScreen (null , () -> ScreenManager .getInstance ().setScreen (new ServerManagerScreen (null , RemotelyClient .INSTANCE )))));
142+ new Notification .Builder ().message ("Bye Bye" ).type (Notification .Type .INFO ).build ();
143+
144+ }
145+
146+ @ Override
147+ public void onSessionExpired () {
148+ ScreenManager .getInstance ().execute (() -> {
149+ new Notification ("Session Expired" , "Your session has expired. Please log in again." , Notification .Type .WARN );
150+ onLogout ();
151+ });
152+ }
153+
154+
107155 private void reloadInstancesSmartly () {
108156 Map <String , SSHManager > activeSessions = new HashMap <>();
109157 if (instanceManager != null ) {
@@ -635,6 +683,7 @@ private void openModpackInstallation() {
635683
636684 @ Override
637685 public void removed () {
686+ ReStudio .getInstance ().removeListener (this );
638687 remotelyClient .saveTabIndex (tabs ().getActiveTabIndex ());
639688 super .removed ();
640689 }
@@ -679,7 +728,7 @@ public void onDisplayed() {
679728 @ Override
680729 public void updatePositions () {
681730 super .updatePositions ();
682- tabs ().setPosition (width - tabs ().getWidth (), height - 28 + 4 );
731+ tabs ().setPosition (width - tabs ().getWidth (), height - 28 + 5 );
683732 }
684733
685734 @ Override
0 commit comments