mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-11-25 00:50:31 +00:00
Add lock on hibernation option
This commit is contained in:
parent
9ad98e4638
commit
366a6e74e7
17 changed files with 128 additions and 81 deletions
|
@ -2,22 +2,16 @@ package io.xpipe.app.core;
|
|||
|
||||
import io.xpipe.app.comp.AppLayoutComp;
|
||||
import io.xpipe.app.fxcomps.util.PlatformThread;
|
||||
import io.xpipe.app.issue.ErrorEvent;
|
||||
import io.xpipe.app.issue.TrackEvent;
|
||||
import io.xpipe.app.prefs.AppPrefs;
|
||||
import io.xpipe.app.update.XPipeDistributionType;
|
||||
import io.xpipe.app.util.LicenseProvider;
|
||||
import io.xpipe.core.process.OsType;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.beans.binding.Bindings;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.SneakyThrows;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
@Getter
|
||||
public class App extends Application {
|
||||
|
||||
|
@ -35,25 +29,6 @@ public class App extends Application {
|
|||
APP = this;
|
||||
stage = primaryStage;
|
||||
stage.opacityProperty().bind(AppPrefs.get().windowOpacity());
|
||||
|
||||
if (OsType.getLocal().equals(OsType.MACOS)) {
|
||||
Desktop.getDesktop().setPreferencesHandler(e -> {
|
||||
AppLayoutModel.get().selectSettings();
|
||||
});
|
||||
}
|
||||
|
||||
if (OsType.getLocal().equals(OsType.LINUX)) {
|
||||
try {
|
||||
Toolkit xToolkit = Toolkit.getDefaultToolkit();
|
||||
java.lang.reflect.Field awtAppClassNameField =
|
||||
xToolkit.getClass().getDeclaredField("awtAppClassName");
|
||||
awtAppClassNameField.setAccessible(true);
|
||||
awtAppClassNameField.set(xToolkit, "XPipe");
|
||||
} catch (Exception e) {
|
||||
ErrorEvent.fromThrowable(e).omit().handle();
|
||||
}
|
||||
}
|
||||
|
||||
AppWindowHelper.addIcons(stage);
|
||||
}
|
||||
|
||||
|
|
89
app/src/main/java/io/xpipe/app/core/AppIntegration.java
Normal file
89
app/src/main/java/io/xpipe/app/core/AppIntegration.java
Normal file
|
@ -0,0 +1,89 @@
|
|||
package io.xpipe.app.core;
|
||||
|
||||
import io.xpipe.app.Main;
|
||||
import io.xpipe.app.core.mode.OperationMode;
|
||||
import io.xpipe.app.issue.ErrorEvent;
|
||||
import io.xpipe.app.launcher.LauncherInput;
|
||||
import io.xpipe.app.prefs.AppPrefs;
|
||||
import io.xpipe.core.process.OsType;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
import java.awt.desktop.*;
|
||||
import java.util.List;
|
||||
|
||||
public class AppIntegration {
|
||||
|
||||
|
||||
public static void setupDesktopIntegrations() {
|
||||
try {
|
||||
Desktop.getDesktop().addAppEventListener(new SystemSleepListener() {
|
||||
@Override
|
||||
public void systemAboutToSleep(SystemSleepEvent e) {
|
||||
if (AppPrefs.get() != null && AppPrefs.get().lockVaultOnHibernation().get()) {
|
||||
OperationMode.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void systemAwoke(SystemSleepEvent e) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
// This will initialize the toolkit on macos and create the dock icon
|
||||
// macOS does not like applications that run fully in the background, so always do it
|
||||
if (OsType.getLocal().equals(OsType.MACOS)) {
|
||||
Desktop.getDesktop().setPreferencesHandler(e -> {
|
||||
AppLayoutModel.get().selectSettings();
|
||||
});
|
||||
|
||||
// URL open operations have to be handled in a special way on macOS!
|
||||
Desktop.getDesktop().setOpenURIHandler(e -> {
|
||||
LauncherInput.handle(List.of(e.getURI().toString()));
|
||||
});
|
||||
|
||||
// Do it this way to prevent IDE inspections from complaining
|
||||
var c = Class.forName(
|
||||
ModuleLayer.boot().findModule("java.desktop").orElseThrow(), "com.apple.eawt.Application");
|
||||
var m = c.getDeclaredMethod("addAppEventListener", SystemEventListener.class);
|
||||
m.invoke(c.getMethod("getApplication").invoke(null), new AppReopenedListener() {
|
||||
@Override
|
||||
public void appReopened(AppReopenedEvent e) {
|
||||
OperationMode.switchToAsync(OperationMode.GUI);
|
||||
}
|
||||
});
|
||||
|
||||
// Set dock icon explicitly on mac
|
||||
// This is necessary in case XPipe was started through a script as it will have no icon otherwise
|
||||
if (AppProperties.get().isDeveloperMode() && AppLogs.get().isWriteToSysout()) {
|
||||
try {
|
||||
var iconUrl = Main.class.getResourceAsStream("resources/img/logo/padded/logo_128x128.png");
|
||||
if (iconUrl != null) {
|
||||
var awtIcon = ImageIO.read(iconUrl);
|
||||
Taskbar.getTaskbar().setIconImage(awtIcon);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ErrorEvent.fromThrowable(ex).omitted(true).build().handle();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (OsType.getLocal().equals(OsType.LINUX)) {
|
||||
try {
|
||||
Toolkit xToolkit = Toolkit.getDefaultToolkit();
|
||||
java.lang.reflect.Field awtAppClassNameField =
|
||||
xToolkit.getClass().getDeclaredField("awtAppClassName");
|
||||
awtAppClassNameField.setAccessible(true);
|
||||
awtAppClassNameField.set(xToolkit, "XPipe");
|
||||
} catch (Exception e) {
|
||||
ErrorEvent.fromThrowable(e).omit().handle();
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Throwable ex) {
|
||||
ErrorEvent.fromThrowable(ex).term().handle();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,37 +1,24 @@
|
|||
package io.xpipe.app.core.mode;
|
||||
|
||||
import io.xpipe.app.Main;
|
||||
import io.xpipe.app.core.App;
|
||||
import io.xpipe.app.core.AppLogs;
|
||||
import io.xpipe.app.core.AppProperties;
|
||||
import io.xpipe.app.core.AppState;
|
||||
import io.xpipe.app.core.*;
|
||||
import io.xpipe.app.core.check.AppDebugModeCheck;
|
||||
import io.xpipe.app.core.check.AppTempCheck;
|
||||
import io.xpipe.app.core.check.AppUserDirectoryCheck;
|
||||
import io.xpipe.app.issue.*;
|
||||
import io.xpipe.app.launcher.LauncherCommand;
|
||||
import io.xpipe.app.launcher.LauncherInput;
|
||||
import io.xpipe.app.util.LocalShell;
|
||||
import io.xpipe.app.util.PlatformState;
|
||||
import io.xpipe.app.util.ThreadHelper;
|
||||
import io.xpipe.app.util.XPipeSession;
|
||||
import io.xpipe.core.process.OsType;
|
||||
import io.xpipe.core.util.FailableRunnable;
|
||||
import io.xpipe.core.util.XPipeDaemonMode;
|
||||
import io.xpipe.core.util.XPipeInstallation;
|
||||
|
||||
import javafx.application.Platform;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.desktop.AppReopenedEvent;
|
||||
import java.awt.desktop.AppReopenedListener;
|
||||
import java.awt.desktop.SystemEventListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
public abstract class OperationMode {
|
||||
|
||||
|
@ -132,47 +119,7 @@ public abstract class OperationMode {
|
|||
setup(args);
|
||||
LauncherCommand.runLauncher(usedArgs);
|
||||
inStartup = false;
|
||||
postInit(args);
|
||||
}
|
||||
|
||||
public static void postInit(String[] args) {
|
||||
try {
|
||||
// This will initialize the toolkit on macos and create the dock icon
|
||||
// macOS does not like applications that run fully in the background, so always do it
|
||||
if (OsType.getLocal().equals(OsType.MACOS)) {
|
||||
// URL open operations have to be handled in a special way on macOS!
|
||||
Desktop.getDesktop().setOpenURIHandler(e -> {
|
||||
LauncherInput.handle(List.of(e.getURI().toString()));
|
||||
});
|
||||
|
||||
// Do it this way to prevent IDE inspections from complaining
|
||||
var c = Class.forName(
|
||||
ModuleLayer.boot().findModule("java.desktop").orElseThrow(), "com.apple.eawt.Application");
|
||||
var m = c.getDeclaredMethod("addAppEventListener", SystemEventListener.class);
|
||||
m.invoke(c.getMethod("getApplication").invoke(null), new AppReopenedListener() {
|
||||
@Override
|
||||
public void appReopened(AppReopenedEvent e) {
|
||||
OperationMode.switchToAsync(OperationMode.GUI);
|
||||
}
|
||||
});
|
||||
|
||||
// Set dock icon explicitly on mac
|
||||
// This is necessary in case XPipe was started through a script as it will have no icon otherwise
|
||||
if (AppProperties.get().isDeveloperMode() && AppLogs.get().isWriteToSysout()) {
|
||||
try {
|
||||
var iconUrl = Main.class.getResourceAsStream("resources/img/logo/padded/logo_128x128.png");
|
||||
if (iconUrl != null) {
|
||||
var awtIcon = ImageIO.read(iconUrl);
|
||||
Taskbar.getTaskbar().setIconImage(awtIcon);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ErrorEvent.fromThrowable(ex).omitted(true).build().handle();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Throwable ex) {
|
||||
ErrorEvent.fromThrowable(ex).term().handle();
|
||||
}
|
||||
AppIntegration.setupDesktopIntegrations();
|
||||
}
|
||||
|
||||
public static void switchToAsync(OperationMode newMode) {
|
||||
|
|
|
@ -96,6 +96,8 @@ public class AppPrefs {
|
|||
map(new SimpleBooleanProperty(false), "condenseConnectionDisplay", Boolean.class);
|
||||
final BooleanProperty showChildCategoriesInParentCategory =
|
||||
map(new SimpleBooleanProperty(true), "showChildrenConnectionsInParentCategory", Boolean.class);
|
||||
final BooleanProperty lockVaultOnHibernation =
|
||||
map(new SimpleBooleanProperty(false), "lockVaultOnHibernation", Boolean.class);
|
||||
final BooleanProperty openConnectionSearchWindowOnConnectionCreation =
|
||||
map(new SimpleBooleanProperty(true), "openConnectionSearchWindowOnConnectionCreation", Boolean.class);
|
||||
final ObjectProperty<Path> storageDirectory =
|
||||
|
@ -263,6 +265,10 @@ public class AppPrefs {
|
|||
return disableTerminalRemotePasswordPreparation;
|
||||
}
|
||||
|
||||
public ObservableBooleanValue lockVaultOnHibernation() {
|
||||
return lockVaultOnHibernation;
|
||||
}
|
||||
|
||||
public ObservableValue<Boolean> alwaysConfirmElevation() {
|
||||
return alwaysConfirmElevation;
|
||||
}
|
||||
|
|
|
@ -52,7 +52,11 @@ public class VaultCategory extends AppPrefsCategory {
|
|||
},
|
||||
prefs.getLockCrypt()),
|
||||
LockChangeAlert::show),
|
||||
prefs.getLockCrypt()));
|
||||
prefs.getLockCrypt())
|
||||
.nameAndDescription("lockVaultOnHibernation")
|
||||
.addToggle(prefs.lockVaultOnHibernation)
|
||||
.hide(prefs.getLockCrypt().isNull().or(prefs.getLockCrypt().isEmpty()))
|
||||
);
|
||||
return builder.buildComp();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -443,3 +443,5 @@ retryAll=Prøv igen alle
|
|||
replace=Erstat
|
||||
replaceAll=Udskift alle
|
||||
copyPassword=copyPassword
|
||||
lockVaultOnHibernation=Lås hvælving på computer i dvale
|
||||
lockVaultOnHibernationDescription=Når denne funktion er aktiveret, låses boksen automatisk, når computeren sættes i dvale. Når du vågner, skal du indtaste din vault-passphrase igen.
|
||||
|
|
|
@ -444,3 +444,5 @@ retryAll=Alle Versuche wiederholen
|
|||
replace=Ersetzen
|
||||
replaceAll=Ersetze alles
|
||||
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.
|
||||
|
|
|
@ -447,3 +447,7 @@ retryAll=Retry all
|
|||
replace=Replace
|
||||
replaceAll=Replace all
|
||||
copyPassword=copyPassword
|
||||
#force
|
||||
#context: when computer sleeps
|
||||
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.
|
||||
|
|
|
@ -431,3 +431,5 @@ retryAll=Reintentar todo
|
|||
replace=Sustituye
|
||||
replaceAll=Sustituir todo
|
||||
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.
|
||||
|
|
|
@ -431,3 +431,5 @@ retryAll=Réessayer tout
|
|||
replace=Remplacer
|
||||
replaceAll=Remplacer tout
|
||||
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.
|
||||
|
|
|
@ -431,3 +431,5 @@ retryAll=Riprova tutti
|
|||
replace=Sostituire
|
||||
replaceAll=Sostituisci tutto
|
||||
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.
|
||||
|
|
|
@ -431,3 +431,5 @@ retryAll=すべて再試行する
|
|||
replace=置き換える
|
||||
replaceAll=すべて置き換える
|
||||
copyPassword=コピーパスワード
|
||||
lockVaultOnHibernation=コンピュータのハイバネーション時に保管庫をロックする
|
||||
lockVaultOnHibernationDescription=有効にすると、コンピュータが休止状態/スリープ状態になると、保管庫は自動的にロックされる。スリープ解除後、保管庫のパスフレーズを再度入力する必要がある。
|
||||
|
|
|
@ -431,3 +431,5 @@ retryAll=Alles opnieuw proberen
|
|||
replace=Vervangen
|
||||
replaceAll=Alles vervangen
|
||||
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.
|
||||
|
|
|
@ -431,3 +431,5 @@ retryAll=Repetir tudo
|
|||
replace=Substitui
|
||||
replaceAll=Substitui tudo
|
||||
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.
|
||||
|
|
|
@ -431,3 +431,5 @@ retryAll=Повторите все попытки
|
|||
replace=Замените
|
||||
replaceAll=Заменить все
|
||||
copyPassword=copyPassword
|
||||
lockVaultOnHibernation=Блокировка хранилища при спящем режиме компьютера
|
||||
lockVaultOnHibernationDescription=Если эта функция включена, хранилище будет автоматически блокироваться, как только компьютер перейдет в спящий режим. После пробуждения тебе придется снова ввести кодовую фразу хранилища.
|
||||
|
|
|
@ -432,3 +432,5 @@ retryAll=Tümünü yeniden dene
|
|||
replace=Değiştirin
|
||||
replaceAll=Tümünü değiştirin
|
||||
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.
|
||||
|
|
|
@ -431,3 +431,5 @@ retryAll=全部重试
|
|||
replace=替换
|
||||
replaceAll=全部替换
|
||||
copyPassword=复制密码
|
||||
lockVaultOnHibernation=电脑休眠时锁定保险库
|
||||
lockVaultOnHibernationDescription=启用后,一旦电脑进入休眠/睡眠状态,保管库就会自动锁定。唤醒后,您必须再次输入保险库密码。
|
||||
|
|
Loading…
Reference in a new issue