[skip ci] impl draft

Signed-off-by: Armin Schrenk <armin.schrenk@skymatic.de>
This commit is contained in:
Armin Schrenk
2025-11-28 14:30:15 +01:00
parent f4f093bb42
commit 3d679c73e7
9 changed files with 151 additions and 3 deletions

View File

@@ -34,7 +34,7 @@
<!-- cryptomator dependencies -->
<cryptomator.cryptofs.version>2.9.0</cryptomator.cryptofs.version>
<cryptomator.integrations.version>1.8.0-beta1</cryptomator.integrations.version>
<cryptomator.integrations.version>1.8.0-SNAPSHOT</cryptomator.integrations.version>
<cryptomator.integrations.win.version>1.5.1</cryptomator.integrations.win.version>
<cryptomator.integrations.mac.version>1.5.0-beta1</cryptomator.integrations.mac.version>
<cryptomator.integrations.linux.version>1.7.0-beta1</cryptomator.integrations.linux.version>

View File

@@ -1,4 +1,6 @@
import ch.qos.logback.classic.spi.Configurator;
import org.cryptomator.integrations.notify.NotifyService2;
import org.cryptomator.integrationsbase.JavaFXNotifyService;
import org.cryptomator.networking.SSLContextWithPKCS12TrustStore;
import org.cryptomator.common.locationpresets.DropboxLinuxLocationPresetsProvider;
import org.cryptomator.common.locationpresets.DropboxMacLocationPresetsProvider;
@@ -64,6 +66,7 @@ open module org.cryptomator.desktop {
provides TrayMenuController with AwtTrayMenuController;
provides Configurator with LogbackConfiguratorFactory;
provides SSLContextProvider with SSLContextWithWindowsCertStore, SSLContextWithMacKeychain, SSLContextWithPKCS12TrustStore;
provides NotifyService2 with JavaFXNotifyService;
provides LocationPresetsProvider with //
DropboxWindowsLocationPresetsProvider, DropboxMacLocationPresetsProvider, DropboxLinuxLocationPresetsProvider, //
GoogleDriveMacLocationPresetsProvider, GoogleDriveWindowsLocationPresetsProvider, //

View File

@@ -0,0 +1,30 @@
package org.cryptomator.integrationsbase;
import org.cryptomator.integrations.common.DisplayName;
import org.cryptomator.integrations.common.Priority;
import org.cryptomator.integrations.notify.NotifyService;
import org.cryptomator.integrations.notify.NotifyService2;
import org.cryptomator.integrations.notify.NotifyServiceException;
import java.util.ArrayList;
@Priority(Priority.FALLBACK)
//@LocalizedDisplayName(bundle = "strings", key ="")
@DisplayName("Cryptomator App Window")
public class JavaFXNotifyService implements NotifyService2 {
//TODO: ipcMessageFile!
@Override
public void sendNotification(String header, String description, NotifyService2.Action... actions) throws NotifyServiceException {
var argList = new ArrayList<String>();
argList.add(header);
argList.add(description);
for(var action: actions) {
argList.add(action.label());
argList.add(action.returnMessage());
}
NotificationApp.main(argList.toArray(new String[] {}));
}
}

View File

@@ -0,0 +1,52 @@
package org.cryptomator.integrationsbase;
import org.apache.commons.lang3.SystemUtils;
import org.cryptomator.ui.common.FxmlLoaderFactory;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyCodeCombination;
import javafx.scene.input.KeyCombination;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.util.BuilderFactory;
import java.io.IOException;
import java.util.ResourceBundle;
public class NotificationApp extends Application {
private static final KeyCodeCombination ALT_F4 = new KeyCodeCombination(KeyCode.F4, KeyCombination.ALT_DOWN);
private static final KeyCodeCombination SHORTCUT_W = new KeyCodeCombination(KeyCode.W, KeyCombination.SHORTCUT_DOWN);
@Override
public void start(Stage stage) throws IOException {
var args = getParameters();
String javaVersion = System.getProperty("java.version");
var url = getClass().getResource("/fxml/notification_window.fxml");
var root = FXMLLoader.<AnchorPane>load(url, ResourceBundle.getBundle("i18n.strings"));
var scene = new Scene(root);
stage.setScene(scene);
setupDefaultAccelerators(scene, stage);
stage.show();
stage.requestFocus();
}
public static void main(String[] args) {
//assert args.length >= 2;
launch(args);
}
private void setupDefaultAccelerators(Scene scene, Stage stage) {
if (SystemUtils.IS_OS_WINDOWS) {
scene.getAccelerators().put(ALT_F4, stage::close);
} else {
scene.getAccelerators().put(SHORTCUT_W, stage::close);
}
}
}

View File

@@ -0,0 +1,20 @@
package org.cryptomator.integrationsbase;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
public class NotificationWindowController {
public NotificationWindowController() {
}
@FXML
public void initialize() {
System.out.println("Hello");
}
public void handleButtonAction(ActionEvent actionEvent) {
System.out.println("OKAY");
}
}

View File

@@ -0,0 +1,22 @@
package org.cryptomator.ipc;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
record HandleNotificationCallbackMessage(String content) implements IpcMessage {
@Override
public MessageType getMessageType() {
return MessageType.HANDLE_NOTIFICATION_CALLBACK;
}
@Override
public ByteBuffer encodePayload() {
return ByteBuffer.wrap(content.getBytes(StandardCharsets.UTF_8));
}
public static IpcMessage decode(ByteBuffer byteBuffer) {
var content = StandardCharsets.UTF_8.decode(byteBuffer).toString();
return new HandleNotificationCallbackMessage(content);
}
}

View File

@@ -10,11 +10,12 @@ import java.nio.channels.WritableByteChannel;
import java.util.function.Function;
//TODO can the enum be removed?
sealed interface IpcMessage permits HandleLaunchArgsMessage, RevealRunningAppMessage {
sealed interface IpcMessage permits HandleLaunchArgsMessage, RevealRunningAppMessage, HandleNotificationCallbackMessage {
enum MessageType {
REVEAL_RUNNING_APP(RevealRunningAppMessage::decode),
HANDLE_LAUNCH_ARGS(HandleLaunchArgsMessage::decode);
HANDLE_LAUNCH_ARGS(HandleLaunchArgsMessage::decode),
HANDLE_NOTIFICATION_CALLBACK(HandleNotificationCallbackMessage::decode);
private final Function<ByteBuffer, IpcMessage> decoder;

View File

@@ -8,6 +8,7 @@ public interface IpcMessageListener {
switch (message) {
case RevealRunningAppMessage m -> revealRunningApp(); // TODO: rename to _ with JEP 443
case HandleLaunchArgsMessage m -> handleLaunchArgs(m.args());
case HandleNotificationCallbackMessage m -> handleNotificationCallback(m.content());
}
}
@@ -15,4 +16,6 @@ public interface IpcMessageListener {
void handleLaunchArgs(List<String> args);
void handleNotificationCallback(String content);
}

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:controller="org.cryptomator.integrationsbase.NotificationWindowController"
prefHeight="400.0" prefWidth="600.0">
<children>
<Button layoutX="126" layoutY="90" onAction="#handleButtonAction" text="Click Me!" />
<Label fx:id="label" layoutX="126" layoutY="120" minHeight="16" minWidth="69" />
</children>
</AnchorPane>