Skip to content

Commit ae314ff

Browse files
committed
Code improvements continued
Discussion: #18
1 parent 06228d0 commit ae314ff

File tree

2 files changed

+13
-30
lines changed

2 files changed

+13
-30
lines changed

src/main/java/org/cryptomator/linux/tray/ActionItemCallback.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ record ActionItemCallback (ActionItem actionItem) implements GCallback {
1010

1111
@Override
1212
public void apply() {
13-
LOG.debug("Hit tray menu action '{}'", actionItem.title());
13+
LOG.trace("Hit tray menu action '{}'", actionItem.title());
1414
actionItem.action().run();
1515
}
1616
}

src/main/java/org/cryptomator/linux/tray/AppindicatorTrayMenuController.java

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,8 @@
1414
import org.slf4j.Logger;
1515
import org.slf4j.LoggerFactory;
1616

17-
import java.io.File;
1817
import java.lang.foreign.MemorySegment;
1918
import java.lang.foreign.SegmentScope;
20-
import java.net.URI;
21-
import java.net.URISyntaxException;
22-
import java.nio.file.Paths;
2319
import java.util.List;
2420
import java.util.function.Consumer;
2521

@@ -41,22 +37,27 @@ public static boolean isAvailable() {
4137
}
4238

4339
@Override
44-
public void showTrayIcon(URI uri, Runnable runnable, String s) throws TrayMenuException {
45-
indicator = app_indicator_new(MemoryAllocator.ALLOCATE_FOR("org.cryptomator.Cryptomator"),
46-
MemoryAllocator.ALLOCATE_FOR(getAbsolutePath(getPathString(uri))),
47-
APP_INDICATOR_CATEGORY_APPLICATION_STATUS());
40+
public void showTrayIcon(Consumer<TrayIconLoader> iconLoader, Runnable runnable, String s) throws TrayMenuException {
41+
TrayIconLoader.FreedesktopIconName callback = this::showTrayIconWithSVG;
42+
iconLoader.accept(callback);
4843
gtk_widget_show_all(menu);
4944
app_indicator_set_menu(indicator, menu);
5045
app_indicator_set_status(indicator, APP_INDICATOR_STATUS_ACTIVE());
5146
}
5247

48+
private void showTrayIconWithSVG(String s) {
49+
indicator = app_indicator_new(MemoryAllocator.ALLOCATE_FOR("org.cryptomator.Cryptomator"),
50+
MemoryAllocator.ALLOCATE_FOR(s),
51+
APP_INDICATOR_CATEGORY_APPLICATION_STATUS());
52+
}
53+
5354
@Override
5455
public void updateTrayIcon(Consumer<TrayIconLoader> iconLoader) {
55-
TrayIconLoader.FreedesktopIconName callback = this::updateTrayIconCallback;
56-
iconLoader.load(callback);
56+
TrayIconLoader.FreedesktopIconName callback = this::updateTrayIconWithSVG;
57+
iconLoader.accept(callback);
5758
}
5859

59-
private void updateTrayIconCallback(String s) {
60+
private void updateTrayIconWithSVG(String s) {
6061
app_indicator_set_icon(indicator, MemoryAllocator.ALLOCATE_FOR(s));
6162
}
6263

@@ -102,22 +103,4 @@ private void addChildren(MemorySegment menu, List<TrayMenuItem> items) {
102103
gtk_widget_show_all(menu);
103104
}
104105
}
105-
106-
private String getAbsolutePath(String iconName) {
107-
var res = getClass().getClassLoader().getResource(iconName);
108-
if (null == res) {
109-
throw new IllegalArgumentException("Icon '" + iconName + "' cannot be found in resource folder");
110-
}
111-
File file = null;
112-
try {
113-
file = Paths.get(res.toURI()).toFile();
114-
} catch (URISyntaxException e) {
115-
throw new IllegalArgumentException("Icon '" + iconName + "' cannot be converted to file", e);
116-
}
117-
return file.getAbsolutePath();
118-
}
119-
120-
private String getPathString(URI uri) {
121-
return uri.getPath().substring(1);
122-
}
123106
}

0 commit comments

Comments
 (0)