Move stuff to integrations-linux

This commit is contained in:
Ralph Plawetzki
2023-04-30 17:08:08 +02:00
parent 97cede12b7
commit 317f3c3458
6 changed files with 7 additions and 147 deletions

View File

@@ -2,7 +2,7 @@
<configuration default="false" name="Cryptomator Linux" type="Application" factoryName="Application">
<option name="MAIN_CLASS_NAME" value="org.cryptomator.launcher.Cryptomator" />
<module name="cryptomator" />
<option name="VM_PARAMETERS" value="-Dcryptomator.settingsPath=&quot;~/.config/Cryptomator/settings.json&quot; -Dcryptomator.p12Path=&quot;~/.config/Cryptomator/key.p12&quot; -Dcryptomator.ipcSocketPath=&quot;~/.config/Cryptomator/ipc.socket&quot; -Dcryptomator.logDir=&quot;~/.local/share/Cryptomator/logs&quot; -Dcryptomator.pluginDir=&quot;~/.local/share/Cryptomator/plugins&quot; -Dcryptomator.mountPointsDir=&quot;~/.local/share/Cryptomator/mnt&quot; -Dcryptomator.showTrayIcon=true -Xss20m -Xmx512m --enable-preview --enable-native-access=org.cryptomator.jfuse.linux.amd64,org.cryptomator.jfuse.linux.aarch64,libappindicator.gtk3.java.minimal" />
<option name="VM_PARAMETERS" value="-Dcryptomator.settingsPath=&quot;~/.config/Cryptomator/settings.json&quot; -Dcryptomator.p12Path=&quot;~/.config/Cryptomator/key.p12&quot; -Dcryptomator.ipcSocketPath=&quot;~/.config/Cryptomator/ipc.socket&quot; -Dcryptomator.logDir=&quot;~/.local/share/Cryptomator/logs&quot; -Dcryptomator.pluginDir=&quot;~/.local/share/Cryptomator/plugins&quot; -Dcryptomator.mountPointsDir=&quot;~/.local/share/Cryptomator/mnt&quot; -Dcryptomator.showTrayIcon=true -Xss20m -Xmx512m --enable-preview --enable-native-access=org.cryptomator.jfuse.linux.amd64,org.cryptomator.jfuse.linux.aarch64,org.purejava.appindicator" />
<method v="2">
<option name="Make" enabled="true" />
</method>

View File

@@ -2,7 +2,7 @@
<configuration default="false" name="Cryptomator Linux Dev" type="Application" factoryName="Application">
<option name="MAIN_CLASS_NAME" value="org.cryptomator.launcher.Cryptomator" />
<module name="cryptomator" />
<option name="VM_PARAMETERS" value="-Dcryptomator.settingsPath=&quot;~/.config/Cryptomator-Dev/settings.json&quot; -Dcryptomator.p12Path=&quot;~/.config/Cryptomator-Dev/key.p12&quot; -Dcryptomator.ipcSocketPath=&quot;~/.config/Cryptomator-Dev/ipc.socket&quot; -Dcryptomator.logDir=&quot;~/.local/share/Cryptomator-Dev/logs&quot; -Dcryptomator.pluginDir=&quot;~/.local/share/Cryptomator-Dev/plugins&quot; -Dcryptomator.mountPointsDir=&quot;~/.local/share/Cryptomator-Dev/mnt&quot; -Dcryptomator.showTrayIcon=true -Dfuse.experimental=&quot;true&quot; -Xss20m -Xmx512m --enable-preview --enable-native-access=org.cryptomator.jfuse.linux.amd64,org.cryptomator.jfuse.linux.aarch64,libappindicator.gtk3.java.minimal" />
<option name="VM_PARAMETERS" value="-Dcryptomator.settingsPath=&quot;~/.config/Cryptomator-Dev/settings.json&quot; -Dcryptomator.p12Path=&quot;~/.config/Cryptomator-Dev/key.p12&quot; -Dcryptomator.ipcSocketPath=&quot;~/.config/Cryptomator-Dev/ipc.socket&quot; -Dcryptomator.logDir=&quot;~/.local/share/Cryptomator-Dev/logs&quot; -Dcryptomator.pluginDir=&quot;~/.local/share/Cryptomator-Dev/plugins&quot; -Dcryptomator.mountPointsDir=&quot;~/.local/share/Cryptomator-Dev/mnt&quot; -Dcryptomator.showTrayIcon=true -Dfuse.experimental=&quot;true&quot; -Xss20m -Xmx512m --enable-preview --enable-native-access=org.cryptomator.jfuse.linux.amd64,org.cryptomator.jfuse.linux.aarch64,org.purejava.appindicator" />
<method v="2">
<option name="Make" enabled="true" />
</method>

12
pom.xml
View File

@@ -34,10 +34,10 @@
<!-- cryptomator dependencies -->
<cryptomator.cryptofs.version>2.6.2</cryptomator.cryptofs.version>
<cryptomator.integrations.version>2.0.0</cryptomator.integrations.version>
<cryptomator.integrations.version>2.0.0-alpha1</cryptomator.integrations.version>
<cryptomator.integrations.win.version>1.2.0</cryptomator.integrations.win.version>
<cryptomator.integrations.mac.version>1.2.0</cryptomator.integrations.mac.version>
<cryptomator.integrations.linux.version>1.2.0</cryptomator.integrations.linux.version>
<cryptomator.integrations.linux.version>2.0.0-alpha1</cryptomator.integrations.linux.version>
<cryptomator.fuse.version>2.0.5</cryptomator.fuse.version>
<cryptomator.dokany.version>2.0.0</cryptomator.dokany.version>
<cryptomator.webdav.version>2.0.2</cryptomator.webdav.version>
@@ -55,7 +55,6 @@
<slf4j.version>2.0.6</slf4j.version>
<tinyoauth2.version>0.5.1</tinyoauth2.version>
<zxcvbn.version>1.7.0</zxcvbn.version>
<appindicator.version>1.2.0</appindicator.version>
<!-- test dependencies -->
<junit.jupiter.version>5.9.2</junit.jupiter.version>
@@ -251,13 +250,6 @@
<version>${jetbrains.annotations.version}</version>
<scope>provided</scope>
</dependency>
<!-- Java bindings for libappindicator -->
<dependency>
<groupId>org.purejava</groupId>
<artifactId>libappindicator-gtk3-java-minimal</artifactId>
<version>${appindicator.version}</version>
</dependency>
</dependencies>
<build>

View File

@@ -1,7 +1,6 @@
import ch.qos.logback.classic.spi.Configurator;
import org.cryptomator.integrations.tray.TrayMenuController;
import org.cryptomator.logging.LogbackConfiguratorFactory;
import org.cryptomator.ui.traymenu.AppindicatorTrayMenuController;
import org.cryptomator.ui.traymenu.AwtTrayMenuController;
open module org.cryptomator.desktop {
@@ -32,13 +31,13 @@ open module org.cryptomator.desktop {
requires com.tobiasdiez.easybind;
requires dagger;
requires io.github.coffeelibs.tinyoauth2client;
requires libappindicator.gtk3.java.minimal;
requires org.slf4j;
requires org.apache.commons.lang3;
/* TODO: filename-based modules: */
requires static javax.inject; /* ugly dagger/guava crap */
requires static javax.inject;
requires org.cryptomator.integrations.linux; /* ugly dagger/guava crap */
provides TrayMenuController with AwtTrayMenuController, AppindicatorTrayMenuController;
provides TrayMenuController with AwtTrayMenuController;
provides Configurator with LogbackConfiguratorFactory;
}

View File

@@ -1,21 +0,0 @@
package org.cryptomator.ui.traymenu;
import org.cryptomator.integrations.tray.ActionItem;
import org.purejava.linux.GCallback;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ActionItemCallback implements GCallback {
private static final Logger LOG = LoggerFactory.getLogger(ActionItemCallback.class);
private ActionItem actionItem;
public ActionItemCallback(ActionItem actionItem) {
this.actionItem = actionItem;
}
@Override
public void apply() {
LOG.debug("Hit tray menu action '{}'", actionItem.title());
actionItem.action().run();
}
}

View File

@@ -1,110 +0,0 @@
package org.cryptomator.ui.traymenu;
import org.apache.commons.lang3.SystemUtils;
import org.cryptomator.integrations.common.CheckAvailability;
import org.cryptomator.integrations.tray.ActionItem;
import org.cryptomator.integrations.tray.SeparatorItem;
import org.cryptomator.integrations.tray.SubMenuItem;
import org.cryptomator.integrations.tray.TrayMenuController;
import org.cryptomator.integrations.tray.TrayMenuException;
import org.cryptomator.integrations.tray.TrayMenuItem;
import org.purejava.linux.MemoryAllocator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.SegmentScope;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Paths;
import java.util.List;
import static org.purejava.linux.app_indicator_h.*;
@CheckAvailability
public class AppindicatorTrayMenuController implements TrayMenuController {
private static final Logger LOG = LoggerFactory.getLogger(AppindicatorTrayMenuController.class);
private final SegmentScope scope = SegmentScope.auto();
private MemorySegment indicator;
private MemorySegment menu = gtk_menu_new();
@CheckAvailability
public static boolean isAvailable() {
return SystemUtils.IS_OS_LINUX && MemoryAllocator.isLoadedNativeLib();
}
@Override
public void showTrayIcon(URI uri, Runnable runnable, String s) throws TrayMenuException {
indicator = app_indicator_new(MemoryAllocator.ALLOCATE_FOR("org.cryptomator.Cryptomator"),
MemoryAllocator.ALLOCATE_FOR(getAbsolutePath(getPathString(uri))),
APP_INDICATOR_CATEGORY_APPLICATION_STATUS());
gtk_widget_show_all(menu);
app_indicator_set_menu(indicator, menu);
app_indicator_set_status(indicator, APP_INDICATOR_STATUS_ACTIVE());
}
@Override
public void updateTrayIcon(URI uri) {
app_indicator_set_icon(indicator, MemoryAllocator.ALLOCATE_FOR(getAbsolutePath(getPathString(uri))));
}
@Override
public void updateTrayMenu(List<TrayMenuItem> items) throws TrayMenuException {
menu = gtk_menu_new();
addChildren(menu, items);
gtk_widget_show_all(menu);
app_indicator_set_menu(indicator, menu);
}
@Override
public void onBeforeOpenMenu(Runnable runnable) {
}
private void addChildren(MemorySegment menu, List<TrayMenuItem> items) {
for (var item : items) {
// TODO: use Pattern Matching for switch, once available
if (item instanceof ActionItem a) {
var gtkMenuItem = gtk_menu_item_new();
gtk_menu_item_set_label(gtkMenuItem, MemoryAllocator.ALLOCATE_FOR(a.title()));
g_signal_connect_object(gtkMenuItem,
MemoryAllocator.ALLOCATE_FOR("activate"),
MemoryAllocator.ALLOCATE_CALLBACK_FOR(new ActionItemCallback(a), scope),
menu,
0);
gtk_menu_shell_append(menu, gtkMenuItem);
} else if (item instanceof SeparatorItem) {
var gtkSeparator = gtk_menu_item_new();
gtk_menu_shell_append(menu, gtkSeparator);
} else if (item instanceof SubMenuItem s) {
var gtkMenuItem = gtk_menu_item_new();
var gtkSubmenu = gtk_menu_new();
gtk_menu_item_set_label(gtkMenuItem, MemoryAllocator.ALLOCATE_FOR(s.title()));
addChildren(gtkSubmenu, s.items());
gtk_menu_item_set_submenu(gtkMenuItem, gtkSubmenu);
gtk_menu_shell_append(menu, gtkMenuItem);
}
gtk_widget_show_all(menu);
}
}
private String getAbsolutePath(String iconName) {
var res = getClass().getClassLoader().getResource(iconName);
if (null == res) {
throw new IllegalArgumentException("Icon '" + iconName + "' cannot be found in resource folder");
}
File file = null;
try {
file = Paths.get(res.toURI()).toFile();
} catch (URISyntaxException e) {
throw new IllegalArgumentException("Icon '" + iconName + "' cannot be converted to file", e);
}
return file.getAbsolutePath();
}
private String getPathString(URI uri) {
return uri.getPath().substring(1);
}
}