mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-11-21 15:10: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;
|
||||
|
||||
import io.xpipe.app.terminal.TerminalView;
|
||||
import io.xpipe.app.util.AskpassAlert;
|
||||
import io.xpipe.app.util.SecretManager;
|
||||
import io.xpipe.app.util.SecretQueryState;
|
||||
|
@ -8,6 +9,8 @@ import io.xpipe.beacon.api.AskpassExchange;
|
|||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class AskpassExchangeImpl extends AskpassExchange {
|
||||
|
||||
@Override
|
||||
|
@ -34,9 +37,28 @@ public class AskpassExchangeImpl extends AskpassExchange {
|
|||
if (p.getState() != SecretQueryState.NORMAL) {
|
||||
throw new BeaconClientException(SecretQueryState.toErrorMessage(p.getState()));
|
||||
}
|
||||
focusTerminalIfNeeded(msg.getPid());
|
||||
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
|
||||
public boolean requiresEnabledApi() {
|
||||
return false;
|
||||
|
|
|
@ -6,6 +6,7 @@ import io.xpipe.app.prefs.AppPrefs;
|
|||
import io.xpipe.app.util.ThreadHelper;
|
||||
import io.xpipe.core.process.OsType;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Value;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -41,6 +42,14 @@ public class TerminalView {
|
|||
private final List<TerminalViewInstance> terminalInstances = 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) {
|
||||
this.listeners.add(listener);
|
||||
}
|
||||
|
@ -49,10 +58,6 @@ public class TerminalView {
|
|||
this.listeners.remove(listener);
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return isSupported();
|
||||
}
|
||||
|
||||
public synchronized void open(UUID request, long pid) {
|
||||
var processHandle = ProcessHandle.of(pid);
|
||||
if (processHandle.isEmpty() || !processHandle.get().isAlive()) {
|
||||
|
@ -88,12 +93,7 @@ public class TerminalView {
|
|||
|
||||
TrackEvent.withTrace("Terminal instance opened")
|
||||
.tag("terminalPid", terminal.get().pid())
|
||||
.tag("viewEnabled", isEnabled())
|
||||
.handle();
|
||||
|
||||
if (!isEnabled()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private Optional<ProcessHandle> getTerminalProcess(ProcessHandle shell) {
|
||||
|
@ -110,6 +110,23 @@ public class TerminalView {
|
|||
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() {
|
||||
for (Session session : new ArrayList<>(sessions)) {
|
||||
var alive = session.shell.isAlive() && session.terminal.isAlive();
|
||||
|
|
|
@ -26,6 +26,8 @@ public class AskpassExchange extends BeaconInterface<AskpassExchange.Request> {
|
|||
@Builder
|
||||
@Value
|
||||
public static class Request {
|
||||
long pid;
|
||||
|
||||
UUID secretId;
|
||||
|
||||
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.
|
||||
#custom
|
||||
overview=Oversigt
|
||||
history=Browsing-historik
|
||||
history=Historie
|
||||
skipAll=Spring alle over
|
||||
notes=Bemærkninger
|
||||
addNotes=Tilføj noter
|
||||
|
|
|
@ -448,7 +448,7 @@ copyPassword=copyPassword
|
|||
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.
|
||||
overview=Übersicht
|
||||
history=Browsing-Verlauf
|
||||
history=Geschichte
|
||||
skipAll=Alles überspringen
|
||||
notes=Anmerkungen
|
||||
addNotes=Notizen hinzufügen
|
||||
|
|
|
@ -451,7 +451,7 @@ copyPassword=copyPassword
|
|||
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.
|
||||
overview=Overview
|
||||
history=Browsing history
|
||||
history=History
|
||||
skipAll=Skip all
|
||||
notes=Notes
|
||||
addNotes=Add notes
|
||||
|
|
|
@ -435,7 +435,7 @@ copyPassword=copiarContraseña
|
|||
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.
|
||||
overview=Visión general
|
||||
history=Historial de navegación
|
||||
history=Historia
|
||||
skipAll=Saltar todo
|
||||
notes=Notas
|
||||
addNotes=Añadir notas
|
||||
|
|
|
@ -435,7 +435,7 @@ copyPassword=copierMotdepasse
|
|||
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.
|
||||
overview=Vue d'ensemble
|
||||
history=Historique de navigation
|
||||
history=Histoire
|
||||
skipAll=Sauter tout
|
||||
notes=Notes
|
||||
addNotes=Ajouter des notes
|
||||
|
|
|
@ -435,7 +435,7 @@ copyPassword=copiaPassword
|
|||
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.
|
||||
overview=Panoramica
|
||||
history=Cronologia di navigazione
|
||||
history=La storia
|
||||
skipAll=Salta tutto
|
||||
notes=Note
|
||||
addNotes=Aggiungi note
|
||||
|
|
|
@ -435,7 +435,7 @@ copyPassword=コピーパスワード
|
|||
lockVaultOnHibernation=コンピュータのハイバネーション時に保管庫をロックする
|
||||
lockVaultOnHibernationDescription=有効にすると、コンピュータが休止状態/スリープ状態になると、保管庫は自動的にロックされる。スリープ解除後、保管庫のパスフレーズを再度入力する必要がある。
|
||||
overview=概要
|
||||
history=閲覧履歴
|
||||
history=歴史
|
||||
skipAll=すべてスキップする
|
||||
notes=備考
|
||||
addNotes=メモを追加する
|
||||
|
|
|
@ -435,7 +435,7 @@ copyPassword=kopieerwachtwoord
|
|||
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.
|
||||
overview=Overzicht
|
||||
history=Browsegeschiedenis
|
||||
history=Geschiedenis
|
||||
skipAll=Alles overslaan
|
||||
notes=Opmerkingen
|
||||
addNotes=Opmerkingen toevoegen
|
||||
|
|
|
@ -435,7 +435,7 @@ copyPassword=copia a palavra-passe
|
|||
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.
|
||||
overview=Resumo
|
||||
history=Histórico de navegação
|
||||
history=História
|
||||
skipAll=Salta tudo
|
||||
notes=Nota
|
||||
addNotes=Adiciona notas
|
||||
|
|
|
@ -435,7 +435,7 @@ copyPassword=copyPassword
|
|||
lockVaultOnHibernation=Блокировка хранилища при спящем режиме компьютера
|
||||
lockVaultOnHibernationDescription=Если эта функция включена, хранилище будет автоматически блокироваться, как только компьютер перейдет в спящий режим. После пробуждения тебе придется снова ввести кодовую фразу хранилища.
|
||||
overview=Обзор
|
||||
history=История просмотров
|
||||
history=История
|
||||
skipAll=Пропустить все
|
||||
notes=Заметки
|
||||
addNotes=Добавляй заметки
|
||||
|
|
|
@ -436,7 +436,7 @@ copyPassword=copyPassword
|
|||
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.
|
||||
overview=Genel Bakış
|
||||
history=Tarama geçmişi
|
||||
history=Tarih
|
||||
skipAll=Tümünü atla
|
||||
notes=Notlar
|
||||
addNotes=Notlar ekleyin
|
||||
|
|
|
@ -435,7 +435,7 @@ copyPassword=复制密码
|
|||
lockVaultOnHibernation=电脑休眠时锁定保险库
|
||||
lockVaultOnHibernationDescription=启用后,一旦电脑进入休眠/睡眠状态,保管库就会自动锁定。唤醒后,您必须再次输入保险库密码。
|
||||
overview=概述
|
||||
history=浏览历史
|
||||
history=历史
|
||||
skipAll=全部跳过
|
||||
notes=说明
|
||||
addNotes=添加注释
|
||||
|
|
Loading…
Reference in a new issue