Skip to content

Commit 34619ec

Browse files
committed
Feat: ServerDetailsScreen Isolated Tabs For Desktop Mode.
1 parent fddf78b commit 34619ec

5 files changed

Lines changed: 42 additions & 11 deletions

File tree

RemotelyMod/libs/ReScreen-1.0.jar

133 Bytes
Binary file not shown.
134 Bytes
Binary file not shown.

libs/ReScreen-1.0.jar

133 Bytes
Binary file not shown.

libs/Rebase-1.0-SNAPSHOT.jar

134 Bytes
Binary file not shown.

src/main/java/redxax/oxy/remotely/ui/server/ServerDetailsScreen.java

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ public class ServerDetailsScreen extends InstanceDetailsScreen implements IDebug
7979

8080
private final Map<TabContext, TerminalSession> contextInfos = new HashMap<>();
8181
private ScheduledExecutorService statusScheduler;
82+
private final List<Object> windowTabs = new ArrayList<>();
83+
private int windowActiveTabIndex = -1;
8284

8385
public ServerDetailsScreen(Object parent, RemotelyClient client) {
8486
this(parent, client, null);
@@ -200,18 +202,42 @@ protected void setupTabs() {
200202
.onTabRenamed(this::onTabRenamed)
201203
.build();
202204

203-
for (Object tabInfo : remotelyClient.getMultiTerminalTabs()) {
205+
List<Object> tabStore = getTabStore();
206+
if (tabStore.isEmpty()) {
207+
tabStore.add(UUID.randomUUID().toString());
208+
}
209+
for (Object tabInfo : tabStore) {
204210
createAndAddTab(tabInfo, false);
205211
}
206212

207-
int activeIndex = remotelyClient.getActiveMultiTerminalTabIndex();
213+
int activeIndex = getSavedTabIndex();
208214
if (activeIndex >= 0 && activeIndex < tabs().getTabs().size()) {
209215
tabs().setActiveTab(activeIndex);
210216
} else if (!tabs().getTabs().isEmpty()) {
211217
tabs().setActiveTab(0);
212218
}
213219
}
214220

221+
private boolean useWindowTabs() {
222+
return desktopMode && isDesktopWindow();
223+
}
224+
225+
private List<Object> getTabStore() {
226+
return useWindowTabs() ? windowTabs : remotelyClient.getMultiTerminalTabs();
227+
}
228+
229+
private int getSavedTabIndex() {
230+
return useWindowTabs() ? windowActiveTabIndex : remotelyClient.getActiveMultiTerminalTabIndex();
231+
}
232+
233+
private void setSavedTabIndex(int index) {
234+
if (useWindowTabs()) {
235+
windowActiveTabIndex = index;
236+
} else {
237+
remotelyClient.setActiveMultiTerminalTabIndex(index);
238+
}
239+
}
240+
215241
private void createAndAddTab(Object tabInfo, boolean setActive) {
216242
Instance inst = (tabInfo instanceof Instance) ? (Instance) tabInfo : null;
217243
String localId = (tabInfo instanceof String) ? (String) tabInfo : null;
@@ -458,7 +484,7 @@ protected void onTabSelected(TabsManager.Tab tab) {
458484

459485
}
460486

461-
remotelyClient.setActiveMultiTerminalTabIndex(tabs().getActiveTabIndex());
487+
setSavedTabIndex(tabs().getActiveTabIndex());
462488
int idx = ctx.selectedViewIndex < ctx.views.size() ? ctx.selectedViewIndex : 0;
463489
if (!ctx.views.isEmpty()) {
464490
onViewChanged(ctx, ctx.views.get(idx));
@@ -478,18 +504,18 @@ private void onTabClosed(TabsManager.Tab tab) {
478504

479505
if (ctx.instance != null) {
480506
ctx.instance.removeStateListener(stateListener);
481-
remotelyClient.getMultiTerminalTabs().removeIf(o -> (o instanceof Instance i && i.equals(ctx.instance)));
507+
getTabStore().removeIf(o -> (o instanceof Instance i && i.equals(ctx.instance)));
482508
ctx.instance.getMSMPManager().disconnect();
483509
} else if (info != null && info.getLocalTerminalId() != null) {
484-
remotelyClient.getMultiTerminalTabs().remove(info.getLocalTerminalId());
510+
getTabStore().remove(info.getLocalTerminalId());
485511
}
486512

487513
}
488514
if (tabs().getTabs().isEmpty()) {
489-
remotelyClient.setActiveMultiTerminalTabIndex(-1);
515+
setSavedTabIndex(-1);
490516
closeScreen();
491517
} else {
492-
remotelyClient.setActiveMultiTerminalTabIndex(tabs().getActiveTabIndex());
518+
setSavedTabIndex(tabs().getActiveTabIndex());
493519
}
494520
}
495521

@@ -519,14 +545,15 @@ private void onTabsReordered(List<TabsManager.Tab> newOrder) {
519545
newInstanceOrder.add(info.isLocalTerminalMode() ? info.getLocalTerminalId() : context.instance);
520546
}
521547
}
522-
remotelyClient.getMultiTerminalTabs().clear();
523-
remotelyClient.getMultiTerminalTabs().addAll(newInstanceOrder);
524-
remotelyClient.setActiveMultiTerminalTabIndex(tabs().getActiveTabIndex());
548+
List<Object> tabStore = getTabStore();
549+
tabStore.clear();
550+
tabStore.addAll(newInstanceOrder);
551+
setSavedTabIndex(tabs().getActiveTabIndex());
525552
}
526553

527554
private void addNewTerminalTab() {
528555
String newId = UUID.randomUUID().toString();
529-
remotelyClient.getMultiTerminalTabs().add(newId);
556+
getTabStore().add(newId);
530557
createAndAddTab(newId, true);
531558
}
532559

@@ -537,6 +564,10 @@ public void addInstanceTab(Instance instanceToAdd) {
537564
return;
538565
}
539566
}
567+
List<Object> tabStore = getTabStore();
568+
if (!tabStore.contains(instanceToAdd)) {
569+
tabStore.add(instanceToAdd);
570+
}
540571
createAndAddTab(instanceToAdd, true);
541572
}
542573

0 commit comments

Comments
 (0)