mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-11-21 23:20:23 +00:00
Implement terminal kill recognition
This commit is contained in:
parent
454380f593
commit
43951b913a
7 changed files with 59 additions and 8 deletions
|
@ -11,8 +11,8 @@ import com.sun.net.httpserver.HttpExchange;
|
|||
public class TerminalWaitExchangeImpl extends TerminalWaitExchange {
|
||||
@Override
|
||||
public Object handle(HttpExchange exchange, Request msg) throws BeaconClientException, BeaconServerException {
|
||||
TerminalLauncherManager.waitExchange(msg.getRequest());
|
||||
TerminalView.get().open(msg.getRequest(), msg.getPid());
|
||||
TerminalLauncherManager.waitExchange(msg.getRequest());
|
||||
return Response.builder().build();
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ import io.xpipe.app.resources.AppResources;
|
|||
import io.xpipe.app.resources.SystemIcons;
|
||||
import io.xpipe.app.storage.DataStorage;
|
||||
import io.xpipe.app.storage.DataStorageSyncHandler;
|
||||
import io.xpipe.app.terminal.TerminalLauncherManager;
|
||||
import io.xpipe.app.terminal.TerminalView;
|
||||
import io.xpipe.app.update.XPipeDistributionType;
|
||||
import io.xpipe.app.util.*;
|
||||
|
@ -70,6 +71,7 @@ public class BaseMode extends OperationMode {
|
|||
BlobManager.init();
|
||||
ActionProvider.initProviders();
|
||||
TerminalView.init();
|
||||
TerminalLauncherManager.init();
|
||||
TrackEvent.info("Finished base components initialization");
|
||||
initialized = true;
|
||||
}
|
||||
|
|
|
@ -30,6 +30,8 @@ public class TerminalLaunchRequest {
|
|||
@NonFinal
|
||||
boolean setupCompleted;
|
||||
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
|
||||
public Path waitForCompletion() throws BeaconServerException {
|
||||
while (true) {
|
||||
if (getResult() == null) {
|
||||
|
@ -47,16 +49,18 @@ public class TerminalLaunchRequest {
|
|||
}
|
||||
}
|
||||
|
||||
public CountDownLatch setupRequestAsync() {
|
||||
var latch = new CountDownLatch(1);
|
||||
public void setupRequestAsync() {
|
||||
ThreadHelper.runAsync(() -> {
|
||||
setupRequest();
|
||||
latch.countDown();
|
||||
});
|
||||
return latch;
|
||||
}
|
||||
|
||||
public void setupRequest() {
|
||||
public void abort() {
|
||||
latch.countDown();
|
||||
}
|
||||
|
||||
private void setupRequest() {
|
||||
var wd = new WorkingDirectoryFunction() {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package io.xpipe.app.terminal;
|
||||
|
||||
import io.xpipe.app.browser.BrowserFullSessionModel;
|
||||
import io.xpipe.app.browser.file.BrowserTerminalDockTabModel;
|
||||
import io.xpipe.app.prefs.AppPrefs;
|
||||
import io.xpipe.beacon.BeaconClientException;
|
||||
import io.xpipe.beacon.BeaconServerException;
|
||||
|
@ -7,6 +9,7 @@ import io.xpipe.core.process.ProcessControl;
|
|||
import io.xpipe.core.process.TerminalInitScriptConfig;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.SequencedMap;
|
||||
import java.util.UUID;
|
||||
|
@ -16,6 +19,39 @@ public class TerminalLauncherManager {
|
|||
|
||||
private static final SequencedMap<UUID, TerminalLaunchRequest> entries = new LinkedHashMap<>();
|
||||
|
||||
public static void init() {
|
||||
if (!TerminalView.isSupported()) {
|
||||
return;
|
||||
}
|
||||
|
||||
TerminalView.get().addListener(new TerminalView.Listener() {
|
||||
@Override
|
||||
public void onSessionOpened(TerminalView.Session session) {}
|
||||
|
||||
@Override
|
||||
public void onSessionClosed(TerminalView.Session session) {
|
||||
var affectedEntry = entries.values().stream().filter(terminalLaunchRequest -> {
|
||||
return terminalLaunchRequest.getRequest().equals(session.getRequest());
|
||||
}).findFirst();
|
||||
if (affectedEntry.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
affectedEntry.get().abort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTerminalOpened(TerminalViewInstance instance) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTerminalClosed(TerminalViewInstance instance) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static CountDownLatch submitAsync(
|
||||
UUID request, ProcessControl processControl, TerminalInitScriptConfig config, String directory)
|
||||
throws BeaconClientException {
|
||||
|
@ -28,7 +64,8 @@ public class TerminalLauncherManager {
|
|||
req.setResult(null);
|
||||
}
|
||||
|
||||
return req.setupRequestAsync();
|
||||
req.setupRequestAsync();
|
||||
return req.getLatch();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -111,7 +111,14 @@ public class TerminalView {
|
|||
}
|
||||
|
||||
public synchronized void tick() {
|
||||
sessions.removeIf(session -> !session.shell.isAlive() || !session.terminal.isAlive());
|
||||
for (Session session : new ArrayList<>(sessions)) {
|
||||
var alive = session.shell.isAlive() && session.terminal.isAlive();
|
||||
if (!alive) {
|
||||
sessions.remove(session);
|
||||
listeners.forEach(listener -> listener.onSessionClosed(session));
|
||||
}
|
||||
}
|
||||
|
||||
for (TerminalViewInstance terminalInstance : new ArrayList<>(terminalInstances)) {
|
||||
var alive = terminalInstance.getTerminalProcess().isAlive();
|
||||
if (!alive) {
|
||||
|
|
|
@ -130,7 +130,7 @@
|
|||
.store-header-bar .filter-bar {
|
||||
-fx-background-radius: 3px;
|
||||
-fx-background-color: -color-bg-default;
|
||||
-fx-border-color: -color-fg-default;
|
||||
-fx-border-color: -color-fg-muted;
|
||||
-fx-border-width: 1;
|
||||
-fx-border-radius: 3px;
|
||||
}
|
||||
|
|
1
dist/changelogs/13.0.md
vendored
1
dist/changelogs/13.0.md
vendored
|
@ -26,6 +26,7 @@ There's now a new mechanism in place for checking for security updates separatel
|
|||
- The application style has been reworked
|
||||
- The settings menu now shows a restart button when a setting has been change that requires a restart to apply
|
||||
- There is now an intro to scripts to provide some more information before using scripts
|
||||
- Add ability to enable agent forwarding when using the SSH-Agent for identities
|
||||
|
||||
## Fixes
|
||||
|
||||
|
|
Loading…
Reference in a new issue