mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-11-21 23:20:23 +00:00
Focus terminal after askpass
This commit is contained in:
parent
43951b913a
commit
18409aa646
15 changed files with 62 additions and 21 deletions
|
@ -1,5 +1,6 @@
|
||||||
package io.xpipe.app.beacon.impl;
|
package io.xpipe.app.beacon.impl;
|
||||||
|
|
||||||
|
import io.xpipe.app.terminal.TerminalView;
|
||||||
import io.xpipe.app.util.AskpassAlert;
|
import io.xpipe.app.util.AskpassAlert;
|
||||||
import io.xpipe.app.util.SecretManager;
|
import io.xpipe.app.util.SecretManager;
|
||||||
import io.xpipe.app.util.SecretQueryState;
|
import io.xpipe.app.util.SecretQueryState;
|
||||||
|
@ -8,6 +9,8 @@ import io.xpipe.beacon.api.AskpassExchange;
|
||||||
|
|
||||||
import com.sun.net.httpserver.HttpExchange;
|
import com.sun.net.httpserver.HttpExchange;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class AskpassExchangeImpl extends AskpassExchange {
|
public class AskpassExchangeImpl extends AskpassExchange {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -34,9 +37,28 @@ public class AskpassExchangeImpl extends AskpassExchange {
|
||||||
if (p.getState() != SecretQueryState.NORMAL) {
|
if (p.getState() != SecretQueryState.NORMAL) {
|
||||||
throw new BeaconClientException(SecretQueryState.toErrorMessage(p.getState()));
|
throw new BeaconClientException(SecretQueryState.toErrorMessage(p.getState()));
|
||||||
}
|
}
|
||||||
|
focusTerminalIfNeeded(msg.getPid());
|
||||||
return Response.builder().value(secret.inPlace()).build();
|
return Response.builder().value(secret.inPlace()).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void focusTerminalIfNeeded(long pid) {
|
||||||
|
if (!TerminalView.isSupported()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var found = TerminalView.get().findSession(pid);
|
||||||
|
if (found.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var term = TerminalView.get().getTerminalInstances().stream().filter(instance -> instance.getTerminalProcess().equals(found.get().getTerminal())).findFirst();
|
||||||
|
if (term.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
term.get().frontOfMainWindow();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean requiresEnabledApi() {
|
public boolean requiresEnabledApi() {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -6,6 +6,7 @@ import io.xpipe.app.prefs.AppPrefs;
|
||||||
import io.xpipe.app.util.ThreadHelper;
|
import io.xpipe.app.util.ThreadHelper;
|
||||||
import io.xpipe.core.process.OsType;
|
import io.xpipe.core.process.OsType;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
import lombok.Value;
|
import lombok.Value;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -41,6 +42,14 @@ public class TerminalView {
|
||||||
private final List<TerminalViewInstance> terminalInstances = new ArrayList<>();
|
private final List<TerminalViewInstance> terminalInstances = new ArrayList<>();
|
||||||
private final List<Listener> listeners = new ArrayList<>();
|
private final List<Listener> listeners = new ArrayList<>();
|
||||||
|
|
||||||
|
public synchronized List<Session> getSessions() {
|
||||||
|
return new ArrayList<>(sessions);
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized List<TerminalViewInstance> getTerminalInstances() {
|
||||||
|
return new ArrayList<>(terminalInstances);
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized void addListener(Listener listener) {
|
public synchronized void addListener(Listener listener) {
|
||||||
this.listeners.add(listener);
|
this.listeners.add(listener);
|
||||||
}
|
}
|
||||||
|
@ -49,10 +58,6 @@ public class TerminalView {
|
||||||
this.listeners.remove(listener);
|
this.listeners.remove(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEnabled() {
|
|
||||||
return isSupported();
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized void open(UUID request, long pid) {
|
public synchronized void open(UUID request, long pid) {
|
||||||
var processHandle = ProcessHandle.of(pid);
|
var processHandle = ProcessHandle.of(pid);
|
||||||
if (processHandle.isEmpty() || !processHandle.get().isAlive()) {
|
if (processHandle.isEmpty() || !processHandle.get().isAlive()) {
|
||||||
|
@ -88,12 +93,7 @@ public class TerminalView {
|
||||||
|
|
||||||
TrackEvent.withTrace("Terminal instance opened")
|
TrackEvent.withTrace("Terminal instance opened")
|
||||||
.tag("terminalPid", terminal.get().pid())
|
.tag("terminalPid", terminal.get().pid())
|
||||||
.tag("viewEnabled", isEnabled())
|
|
||||||
.handle();
|
.handle();
|
||||||
|
|
||||||
if (!isEnabled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Optional<ProcessHandle> getTerminalProcess(ProcessHandle shell) {
|
private Optional<ProcessHandle> getTerminalProcess(ProcessHandle shell) {
|
||||||
|
@ -110,6 +110,23 @@ public class TerminalView {
|
||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public synchronized Optional<Session> findSession(long pid) {
|
||||||
|
var proc = ProcessHandle.of(pid);
|
||||||
|
while (true) {
|
||||||
|
if (proc.isEmpty()) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
var finalProc = proc;
|
||||||
|
var found = TerminalView.get().getSessions().stream().filter(session -> session.getShell().equals(finalProc.get())).findFirst();
|
||||||
|
if (found.isPresent()) {
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
|
proc = proc.get().parent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized void tick() {
|
public synchronized void tick() {
|
||||||
for (Session session : new ArrayList<>(sessions)) {
|
for (Session session : new ArrayList<>(sessions)) {
|
||||||
var alive = session.shell.isAlive() && session.terminal.isAlive();
|
var alive = session.shell.isAlive() && session.terminal.isAlive();
|
||||||
|
|
|
@ -26,6 +26,8 @@ public class AskpassExchange extends BeaconInterface<AskpassExchange.Request> {
|
||||||
@Builder
|
@Builder
|
||||||
@Value
|
@Value
|
||||||
public static class Request {
|
public static class Request {
|
||||||
|
long pid;
|
||||||
|
|
||||||
UUID secretId;
|
UUID secretId;
|
||||||
|
|
||||||
UUID request;
|
UUID request;
|
||||||
|
|
|
@ -454,7 +454,7 @@ lockVaultOnHibernation=Lås Vault når computeren går i dvale
|
||||||
lockVaultOnHibernationDescription=Når denne funktion er aktiveret, låses Vaulten automatisk, når computeren sættes i dvale. Når du bruger computeren igen, skal du indtaste din vault-adgangsætning igen.
|
lockVaultOnHibernationDescription=Når denne funktion er aktiveret, låses Vaulten automatisk, når computeren sættes i dvale. Når du bruger computeren igen, skal du indtaste din vault-adgangsætning igen.
|
||||||
#custom
|
#custom
|
||||||
overview=Oversigt
|
overview=Oversigt
|
||||||
history=Browsing-historik
|
history=Historie
|
||||||
skipAll=Spring alle over
|
skipAll=Spring alle over
|
||||||
notes=Bemærkninger
|
notes=Bemærkninger
|
||||||
addNotes=Tilføj noter
|
addNotes=Tilføj noter
|
||||||
|
|
|
@ -448,7 +448,7 @@ copyPassword=copyPassword
|
||||||
lockVaultOnHibernation=Tresor im Ruhezustand des Computers sperren
|
lockVaultOnHibernation=Tresor im Ruhezustand des Computers sperren
|
||||||
lockVaultOnHibernationDescription=Wenn diese Funktion aktiviert ist, wird der Tresor automatisch gesperrt, sobald dein Computer in den Ruhezustand versetzt wird. Nach dem Aufwachen musst du deine Tresor-Passphrase erneut eingeben.
|
lockVaultOnHibernationDescription=Wenn diese Funktion aktiviert ist, wird der Tresor automatisch gesperrt, sobald dein Computer in den Ruhezustand versetzt wird. Nach dem Aufwachen musst du deine Tresor-Passphrase erneut eingeben.
|
||||||
overview=Übersicht
|
overview=Übersicht
|
||||||
history=Browsing-Verlauf
|
history=Geschichte
|
||||||
skipAll=Alles überspringen
|
skipAll=Alles überspringen
|
||||||
notes=Anmerkungen
|
notes=Anmerkungen
|
||||||
addNotes=Notizen hinzufügen
|
addNotes=Notizen hinzufügen
|
||||||
|
|
|
@ -451,7 +451,7 @@ copyPassword=copyPassword
|
||||||
lockVaultOnHibernation=Lock vault on computer hibernation
|
lockVaultOnHibernation=Lock vault on computer hibernation
|
||||||
lockVaultOnHibernationDescription=When enabled, the vault will automatically be locked once your computer is put into hibernation/to sleep. Upon wake up, you will have to enter your vault passphrase again.
|
lockVaultOnHibernationDescription=When enabled, the vault will automatically be locked once your computer is put into hibernation/to sleep. Upon wake up, you will have to enter your vault passphrase again.
|
||||||
overview=Overview
|
overview=Overview
|
||||||
history=Browsing history
|
history=History
|
||||||
skipAll=Skip all
|
skipAll=Skip all
|
||||||
notes=Notes
|
notes=Notes
|
||||||
addNotes=Add notes
|
addNotes=Add notes
|
||||||
|
|
|
@ -435,7 +435,7 @@ copyPassword=copiarContraseña
|
||||||
lockVaultOnHibernation=Bloquear la bóveda al hibernar el ordenador
|
lockVaultOnHibernation=Bloquear la bóveda al hibernar el ordenador
|
||||||
lockVaultOnHibernationDescription=Si está activada, el almacén se bloqueará automáticamente cuando tu ordenador entre en hibernación/reposo. Al despertarte, tendrás que volver a introducir la contraseña de tu bóveda.
|
lockVaultOnHibernationDescription=Si está activada, el almacén se bloqueará automáticamente cuando tu ordenador entre en hibernación/reposo. Al despertarte, tendrás que volver a introducir la contraseña de tu bóveda.
|
||||||
overview=Visión general
|
overview=Visión general
|
||||||
history=Historial de navegación
|
history=Historia
|
||||||
skipAll=Saltar todo
|
skipAll=Saltar todo
|
||||||
notes=Notas
|
notes=Notas
|
||||||
addNotes=Añadir notas
|
addNotes=Añadir notas
|
||||||
|
|
|
@ -435,7 +435,7 @@ copyPassword=copierMotdepasse
|
||||||
lockVaultOnHibernation=Verrouille le coffre-fort lors de l'hibernation de l'ordinateur
|
lockVaultOnHibernation=Verrouille le coffre-fort lors de l'hibernation de l'ordinateur
|
||||||
lockVaultOnHibernationDescription=Lorsque cette option est activée, le coffre-fort sera automatiquement verrouillé une fois que ton ordinateur sera mis en hibernation/en veille. Au réveil, tu devras saisir à nouveau la phrase de passe de ton coffre-fort.
|
lockVaultOnHibernationDescription=Lorsque cette option est activée, le coffre-fort sera automatiquement verrouillé une fois que ton ordinateur sera mis en hibernation/en veille. Au réveil, tu devras saisir à nouveau la phrase de passe de ton coffre-fort.
|
||||||
overview=Vue d'ensemble
|
overview=Vue d'ensemble
|
||||||
history=Historique de navigation
|
history=Histoire
|
||||||
skipAll=Sauter tout
|
skipAll=Sauter tout
|
||||||
notes=Notes
|
notes=Notes
|
||||||
addNotes=Ajouter des notes
|
addNotes=Ajouter des notes
|
||||||
|
|
|
@ -435,7 +435,7 @@ copyPassword=copiaPassword
|
||||||
lockVaultOnHibernation=Blocca il caveau durante l'ibernazione del computer
|
lockVaultOnHibernation=Blocca il caveau durante l'ibernazione del computer
|
||||||
lockVaultOnHibernationDescription=Se abilitato, il vault si blocca automaticamente quando il computer viene messo in ibernazione o a riposo. Al risveglio, dovrai inserire nuovamente la passphrase del vault.
|
lockVaultOnHibernationDescription=Se abilitato, il vault si blocca automaticamente quando il computer viene messo in ibernazione o a riposo. Al risveglio, dovrai inserire nuovamente la passphrase del vault.
|
||||||
overview=Panoramica
|
overview=Panoramica
|
||||||
history=Cronologia di navigazione
|
history=La storia
|
||||||
skipAll=Salta tutto
|
skipAll=Salta tutto
|
||||||
notes=Note
|
notes=Note
|
||||||
addNotes=Aggiungi note
|
addNotes=Aggiungi note
|
||||||
|
|
|
@ -435,7 +435,7 @@ copyPassword=コピーパスワード
|
||||||
lockVaultOnHibernation=コンピュータのハイバネーション時に保管庫をロックする
|
lockVaultOnHibernation=コンピュータのハイバネーション時に保管庫をロックする
|
||||||
lockVaultOnHibernationDescription=有効にすると、コンピュータが休止状態/スリープ状態になると、保管庫は自動的にロックされる。スリープ解除後、保管庫のパスフレーズを再度入力する必要がある。
|
lockVaultOnHibernationDescription=有効にすると、コンピュータが休止状態/スリープ状態になると、保管庫は自動的にロックされる。スリープ解除後、保管庫のパスフレーズを再度入力する必要がある。
|
||||||
overview=概要
|
overview=概要
|
||||||
history=閲覧履歴
|
history=歴史
|
||||||
skipAll=すべてスキップする
|
skipAll=すべてスキップする
|
||||||
notes=備考
|
notes=備考
|
||||||
addNotes=メモを追加する
|
addNotes=メモを追加する
|
||||||
|
|
|
@ -435,7 +435,7 @@ copyPassword=kopieerwachtwoord
|
||||||
lockVaultOnHibernation=Kluis op computer in slaapstand
|
lockVaultOnHibernation=Kluis op computer in slaapstand
|
||||||
lockVaultOnHibernationDescription=Als deze optie is ingeschakeld, wordt de kluis automatisch vergrendeld zodra je computer in de slaapstand wordt gezet. Als je wakker wordt, moet je je wachtwoordzin voor de kluis opnieuw invoeren.
|
lockVaultOnHibernationDescription=Als deze optie is ingeschakeld, wordt de kluis automatisch vergrendeld zodra je computer in de slaapstand wordt gezet. Als je wakker wordt, moet je je wachtwoordzin voor de kluis opnieuw invoeren.
|
||||||
overview=Overzicht
|
overview=Overzicht
|
||||||
history=Browsegeschiedenis
|
history=Geschiedenis
|
||||||
skipAll=Alles overslaan
|
skipAll=Alles overslaan
|
||||||
notes=Opmerkingen
|
notes=Opmerkingen
|
||||||
addNotes=Opmerkingen toevoegen
|
addNotes=Opmerkingen toevoegen
|
||||||
|
|
|
@ -435,7 +435,7 @@ copyPassword=copia a palavra-passe
|
||||||
lockVaultOnHibernation=Bloqueia o cofre na hibernação do computador
|
lockVaultOnHibernation=Bloqueia o cofre na hibernação do computador
|
||||||
lockVaultOnHibernationDescription=Quando ativado, a abóbada é automaticamente bloqueada quando o computador é colocado em hibernação/sono. Quando acordares, terás de introduzir novamente a frase-chave do cofre.
|
lockVaultOnHibernationDescription=Quando ativado, a abóbada é automaticamente bloqueada quando o computador é colocado em hibernação/sono. Quando acordares, terás de introduzir novamente a frase-chave do cofre.
|
||||||
overview=Resumo
|
overview=Resumo
|
||||||
history=Histórico de navegação
|
history=História
|
||||||
skipAll=Salta tudo
|
skipAll=Salta tudo
|
||||||
notes=Nota
|
notes=Nota
|
||||||
addNotes=Adiciona notas
|
addNotes=Adiciona notas
|
||||||
|
|
|
@ -435,7 +435,7 @@ copyPassword=copyPassword
|
||||||
lockVaultOnHibernation=Блокировка хранилища при спящем режиме компьютера
|
lockVaultOnHibernation=Блокировка хранилища при спящем режиме компьютера
|
||||||
lockVaultOnHibernationDescription=Если эта функция включена, хранилище будет автоматически блокироваться, как только компьютер перейдет в спящий режим. После пробуждения тебе придется снова ввести кодовую фразу хранилища.
|
lockVaultOnHibernationDescription=Если эта функция включена, хранилище будет автоматически блокироваться, как только компьютер перейдет в спящий режим. После пробуждения тебе придется снова ввести кодовую фразу хранилища.
|
||||||
overview=Обзор
|
overview=Обзор
|
||||||
history=История просмотров
|
history=История
|
||||||
skipAll=Пропустить все
|
skipAll=Пропустить все
|
||||||
notes=Заметки
|
notes=Заметки
|
||||||
addNotes=Добавляй заметки
|
addNotes=Добавляй заметки
|
||||||
|
|
|
@ -436,7 +436,7 @@ copyPassword=copyPassword
|
||||||
lockVaultOnHibernation=Bilgisayar hazırda bekletme modunda kasayı kilitleme
|
lockVaultOnHibernation=Bilgisayar hazırda bekletme modunda kasayı kilitleme
|
||||||
lockVaultOnHibernationDescription=Etkinleştirildiğinde, bilgisayarınız hazırda bekletme/uyku moduna geçtiğinde kasa otomatik olarak kilitlenecektir. Uyandığınızda, kasa parolanızı tekrar girmeniz gerekecektir.
|
lockVaultOnHibernationDescription=Etkinleştirildiğinde, bilgisayarınız hazırda bekletme/uyku moduna geçtiğinde kasa otomatik olarak kilitlenecektir. Uyandığınızda, kasa parolanızı tekrar girmeniz gerekecektir.
|
||||||
overview=Genel Bakış
|
overview=Genel Bakış
|
||||||
history=Tarama geçmişi
|
history=Tarih
|
||||||
skipAll=Tümünü atla
|
skipAll=Tümünü atla
|
||||||
notes=Notlar
|
notes=Notlar
|
||||||
addNotes=Notlar ekleyin
|
addNotes=Notlar ekleyin
|
||||||
|
|
|
@ -435,7 +435,7 @@ copyPassword=复制密码
|
||||||
lockVaultOnHibernation=电脑休眠时锁定保险库
|
lockVaultOnHibernation=电脑休眠时锁定保险库
|
||||||
lockVaultOnHibernationDescription=启用后,一旦电脑进入休眠/睡眠状态,保管库就会自动锁定。唤醒后,您必须再次输入保险库密码。
|
lockVaultOnHibernationDescription=启用后,一旦电脑进入休眠/睡眠状态,保管库就会自动锁定。唤醒后,您必须再次输入保险库密码。
|
||||||
overview=概述
|
overview=概述
|
||||||
history=浏览历史
|
history=历史
|
||||||
skipAll=全部跳过
|
skipAll=全部跳过
|
||||||
notes=说明
|
notes=说明
|
||||||
addNotes=添加注释
|
addNotes=添加注释
|
||||||
|
|
Loading…
Reference in a new issue