-
Notifications
You must be signed in to change notification settings - Fork 5
Feature/flatpak update portal #117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 14 commits
84fda70
12ee5d2
10c9d25
40d1481
e28d20a
096bacd
7dfa971
746af26
f1d12e8
467a86b
77edc0d
549c46f
a2607d7
4976dde
2aa7b15
08a7742
ffb84d8
f4d2b6b
d20b008
3e8f57e
92a010c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,140 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| package org.cryptomator.linux.update; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.cryptomator.integrations.common.CheckAvailability; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.cryptomator.integrations.common.DisplayName; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.cryptomator.integrations.common.OperatingSystem; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.cryptomator.integrations.common.Priority; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.cryptomator.integrations.update.Progress; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.cryptomator.integrations.update.ProgressListener; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.cryptomator.integrations.update.UpdateFailedException; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.cryptomator.integrations.update.UpdateService; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.freedesktop.dbus.FileDescriptor; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.freedesktop.dbus.exceptions.DBusException; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.freedesktop.dbus.types.UInt32; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.freedesktop.dbus.types.Variant; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.purejava.portal.Flatpak; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.purejava.portal.FlatpakSpawnFlag; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.purejava.portal.UpdatePortal; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.purejava.portal.Util; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.purejava.portal.rest.UpdateCheckerTask; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.slf4j.Logger; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.slf4j.LoggerFactory; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.Collections; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.List; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.Map; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.concurrent.CopyOnWriteArrayList; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Priority(1000) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @CheckAvailability | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @DisplayName("Update via Flatpak update") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @OperatingSystem(OperatingSystem.Value.LINUX) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public class FlatpakUpdater implements UpdateService, AutoCloseable { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private static final Logger LOG = LoggerFactory.getLogger(FlatpakUpdater.class); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private static final String APP_NAME = "org.cryptomator.Cryptomator"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private final List<ProgressListener> progressListeners = new CopyOnWriteArrayList<>(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private final UpdatePortal portal; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private Flatpak.UpdateMonitor updateMonitor; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public FlatpakUpdater() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.portal = new UpdatePortal(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| portal.CreateUpdateMonitor(UpdatePortal.OPTIONS_DUMMY); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public boolean isSupported() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return portal.isAvailable(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public UpdateCheckerTask getLatestReleaseChecker() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| portal.setUpdateCheckerTaskFor(APP_NAME); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return portal.getUpdateCheckerTaskFor(APP_NAME); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public void triggerUpdate() throws UpdateFailedException { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var monitor = getUpdateMonitor(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| portal.updateApp("x11:0", monitor, UpdatePortal.OPTIONS_DUMMY); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public void triggerUpdate() throws UpdateFailedException { | |
| var monitor = getUpdateMonitor(); | |
| portal.updateApp("x11:0", monitor, UpdatePortal.OPTIONS_DUMMY); | |
| } | |
| @Override | |
| public void triggerUpdate() throws UpdateFailedException { | |
| var monitor = getUpdateMonitor(); | |
| String display = System.getenv("DISPLAY"); | |
| if (display == null || display.isEmpty()) { | |
| display = System.getenv("WAYLAND_DISPLAY"); | |
| if (display != null && !display.isEmpty()) { | |
| display = "wayland:" + display; | |
| } else { | |
| display = "x11:0"; // fallback | |
| } | |
| } | |
| portal.updateApp(display, monitor, UpdatePortal.OPTIONS_DUMMY); | |
| } |
🤖 Prompt for AI Agents
In src/main/java/org/cryptomator/linux/update/FlatpakUpdater.java around lines
70 to 73, the display parameter "x11:0" is hardcoded in the portal.updateApp
call, which can cause issues in Wayland or other display environments. Modify
the code to dynamically obtain the display parameter from the environment or
system properties instead of using a fixed string. Replace the hardcoded "x11:0"
with a variable that retrieves the current display setting at runtime.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Improve exception handling in close method.
The current implementation catches a generic Exception and the logging could be more informative.
@Override
public void close() throws Exception {
try {
if (null != updateMonitor) {
portal.cancelUpdateMonitor(updateMonitor);
}
portal.close();
- } catch (Exception e) {
- LOG.error(e.toString(), e.getCause());
+ } catch (DBusException e) {
+ LOG.error("Failed to close DBus connection properly", e);
+ throw e;
+ } catch (Exception e) {
+ LOG.error("Unexpected error during resource cleanup", e);
+ throw e;
}
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| @Override | |
| public void close() throws Exception { | |
| try { | |
| if (null != updateMonitor) { | |
| portal.cancelUpdateMonitor(updateMonitor); | |
| } | |
| portal.close(); | |
| } catch (Exception e) { | |
| LOG.error(e.toString(), e.getCause()); | |
| } | |
| } | |
| @Override | |
| public void close() throws Exception { | |
| try { | |
| if (null != updateMonitor) { | |
| portal.cancelUpdateMonitor(updateMonitor); | |
| } | |
| portal.close(); | |
| } catch (DBusException e) { | |
| LOG.error("Failed to close DBus connection properly", e); | |
| throw e; | |
| } catch (Exception e) { | |
| LOG.error("Unexpected error during resource cleanup", e); | |
| throw e; | |
| } | |
| } |
🤖 Prompt for AI Agents
In src/main/java/org/cryptomator/linux/update/FlatpakUpdater.java around lines
98 to 108, improve the exception handling in the close method by catching more
specific exceptions if possible, and enhance the logging to provide a clearer
and more informative message. Instead of logging e.toString() and e.getCause()
separately, log the full exception with its stack trace to capture complete
context for debugging.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| org.cryptomator.linux.update.FlatpakUpdater |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Remove unnecessary monitor creation in constructor.
The constructor creates an update monitor but doesn't check or use the result. This monitor should be created lazily when first needed via
getUpdateMonitor().public FlatpakUpdater() { this.portal = new UpdatePortal(); - portal.CreateUpdateMonitor(UpdatePortal.OPTIONS_DUMMY); }📝 Committable suggestion
🤖 Prompt for AI Agents