-
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 13 commits
84fda70
12ee5d2
10c9d25
40d1481
e28d20a
096bacd
7dfa971
746af26
f1d12e8
467a86b
77edc0d
549c46f
a2607d7
4976dde
2aa7b15
08a7742
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,231 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
package org.cryptomator.linux.update; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
import org.cryptomator.integrations.common.CheckAvailability; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
import org.cryptomator.integrations.common.DistributionChannel; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.SpawnExitedListener; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
import org.cryptomator.integrations.update.SpawnStartedListener; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
import org.cryptomator.integrations.update.UpdateAvailable; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
import org.cryptomator.integrations.update.UpdateAvailableListener; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
@DistributionChannel(DistributionChannel.Value.LINUX_FLATPAK) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
@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<UpdateAvailableListener> updateAvailableListeners = new CopyOnWriteArrayList<>(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
private final List<ProgressListener> progressListeners = new CopyOnWriteArrayList<>(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
private final List<SpawnStartedListener> spawnStartedListeners = new CopyOnWriteArrayList<>(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
private final List<SpawnExitedListener> spawnExitedListeners = 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(DistributionChannel.Value channel) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (channel != DistributionChannel.Value.LINUX_FLATPAK) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
LOG.error("Wrong channel provided: {}", channel); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
return null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
portal.setUpdateCheckerTaskFor(APP_NAME); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
return portal.getUpdateCheckerTaskFor(APP_NAME); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Throw exception instead of returning null for invalid channel. Returning @Override
public UpdateCheckerTask getLatestReleaseChecker(DistributionChannel.Value channel) {
if (channel != DistributionChannel.Value.LINUX_FLATPAK) {
- LOG.error("Wrong channel provided: {}", channel);
- return null;
+ throw new IllegalArgumentException("Wrong channel provided: " + channel + ". Expected: LINUX_FLATPAK");
}
portal.setUpdateCheckerTaskFor(APP_NAME);
return portal.getUpdateCheckerTaskFor(APP_NAME);
} 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
@Override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
public void triggerUpdate() throws UpdateFailedException { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
var monitor = getUpdateMonitor(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
portal.updateApp("x11:0", monitor, UpdatePortal.OPTIONS_DUMMY); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid hardcoding the display parameter. The hardcoded Consider obtaining the display parameter dynamically: @Override
public void triggerUpdate() throws UpdateFailedException {
var monitor = getUpdateMonitor();
- portal.updateApp("x11:0", monitor, UpdatePortal.OPTIONS_DUMMY);
+ 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);
} 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
@Override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
public long spawnApp() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
var cwdPath = Util.stringToByteList(System.getProperty("user.dir")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
List<List<Byte>> argv = List.of( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Util.stringToByteList(APP_NAME)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Map<UInt32, FileDescriptor> fds = Collections.emptyMap(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Map<String, String> envs = Map.of(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
UInt32 flags = new UInt32(FlatpakSpawnFlag.LATEST_VERSION.getValue()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Map<String, Variant<?>> options = UpdatePortal.OPTIONS_DUMMY; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
return spawnApp(cwdPath, argv, fds, envs, flags, options).longValue(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
@Override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
public boolean doesRequireElevatedPermissions() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
return false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
@Override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
public String getDisplayName() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
return "Update via Flatpak update"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
@Override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
public void close() throws Exception { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (null != updateMonitor) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
portal.cancelUpdateMonitor(updateMonitor); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
portal.close(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} catch (Exception e) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
LOG.error(e.toString(), e.getCause()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 @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
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
private synchronized Flatpak.UpdateMonitor getUpdateMonitor() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (updateMonitor == null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
var updateMonitorPath = portal.CreateUpdateMonitor(UpdatePortal.OPTIONS_DUMMY); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (updateMonitorPath != null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
LOG.debug("UpdateMonitor successful created at {}", updateMonitorPath); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
updateMonitor = portal.getUpdateMonitor(updateMonitorPath.toString()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
portal.getDBusConnection().addSigHandler(Flatpak.UpdateMonitor.UpdateAvailable.class, signal -> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
notifyOnUpdateAvailable(signal); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
portal.getDBusConnection().addSigHandler(Flatpak.UpdateMonitor.Progress.class, signal -> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
notifyOnUpdateProceeds(signal); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} catch (DBusException e) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
LOG.error(e.toString(), e.getCause()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
LOG.error("Failed to create UpdateMonitor on DBus"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
return updateMonitor; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
@Override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
public void addUpdateAvailableListener(UpdateAvailableListener listener) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
updateAvailableListeners.add(listener); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
@Override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
public void removeUpdateAvailableListener(UpdateAvailableListener listener) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
updateAvailableListeners.remove(listener); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
@Override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
public void addProgressListener(ProgressListener listener) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
progressListeners.add(listener); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
@Override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
public void removeProgressListener(ProgressListener listener) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
progressListeners.remove(listener); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
@Override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
public void addSpawnStartedListener(SpawnStartedListener listener) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
spawnStartedListeners.add(listener); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
@Override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
public void removeSpawnStartedListener(SpawnStartedListener listener) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
spawnStartedListeners.remove(listener); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
@Override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
public void addSpawnExitedListener(SpawnExitedListener listener) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
spawnExitedListeners.add(listener); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
@Override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
public void removeSpawnExitedListener(SpawnExitedListener listener) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
spawnExitedListeners.remove(listener); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
private void notifyOnUpdateAvailable(Flatpak.UpdateMonitor.UpdateAvailable signal) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
String remoteCommit = ""; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Variant<?> remoteCommitVariant = signal.update_info.get("remote-commit"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (null != remoteCommitVariant) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
remoteCommit = (String) remoteCommitVariant.getValue(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
String runningCommit = ""; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Variant<?> runningCommitVariant = signal.update_info.get("running-commit"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (null != runningCommitVariant) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
runningCommit = (String) runningCommitVariant.getValue(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
String localCommit = ""; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Variant<?> localCommitVariant = signal.update_info.get("local-commit"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (null != localCommitVariant) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
localCommit = (String) localCommitVariant.getValue(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
UpdateAvailable updateAvailable = new UpdateAvailable(runningCommit, localCommit, remoteCommit); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
for (UpdateAvailableListener listener : updateAvailableListeners) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
listener.onUpdateAvailable(updateAvailable); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
private void notifyOnUpdateProceeds(Flatpak.UpdateMonitor.Progress signal) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
long status = ((UInt32) signal.info.get("status").getValue()).longValue(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
long progress = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Variant<?> progressVariant = signal.info.get("progress"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (null != progressVariant) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
progress = ((UInt32) progressVariant.getValue()).longValue(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
long nOps = -1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Variant<?> nOpsVariant = signal.info.get("n_ops"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (null != nOpsVariant) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
nOps = ((UInt32) nOpsVariant.getValue()).longValue(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
long oP = -1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Variant<?> oPVariant = signal.info.get("op"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (null != oPVariant) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
oP = ((UInt32) oPVariant.getValue()).longValue(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
String error = ""; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Variant<?> errorVariant = signal.info.get("error"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (null != errorVariant) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
error = (String) errorVariant.getValue(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
String errorMessage = ""; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Variant<?> errorMessageVariant = signal.info.get("error_message"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (null != errorMessageVariant) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
errorMessage = (String) errorMessageVariant.getValue(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Progress p = new Progress(nOps, oP, status, progress, error, errorMessage); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
for (ProgressListener listener : progressListeners) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
listener.onProgress(p); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add type safety checks and reduce code duplication. The direct cast without type checking could throw +private long extractLongFromVariant(Map<String, Variant<?>> map, String key, long defaultValue) {
+ Variant<?> variant = map.get(key);
+ if (variant != null && variant.getValue() instanceof UInt32) {
+ return ((UInt32) variant.getValue()).longValue();
+ }
+ return defaultValue;
+}
+
private void notifyOnUpdateProceeds(Flatpak.UpdateMonitor.Progress signal) {
- long status = ((UInt32) signal.info.get("status").getValue()).longValue();
- long progress = 0;
- Variant<?> progressVariant = signal.info.get("progress");
- if (null != progressVariant) {
- progress = ((UInt32) progressVariant.getValue()).longValue();
- }
- long nOps = -1;
- Variant<?> nOpsVariant = signal.info.get("n_ops");
- if (null != nOpsVariant) {
- nOps = ((UInt32) nOpsVariant.getValue()).longValue();
- }
- long oP = -1;
- Variant<?> oPVariant = signal.info.get("op");
- if (null != oPVariant) {
- oP = ((UInt32) oPVariant.getValue()).longValue();
- }
- String error = "";
- Variant<?> errorVariant = signal.info.get("error");
- if (null != errorVariant) {
- error = (String) errorVariant.getValue();
- }
- String errorMessage = "";
- Variant<?> errorMessageVariant = signal.info.get("error_message");
- if (null != errorMessageVariant) {
- errorMessage = (String) errorMessageVariant.getValue();
- }
+ long status = extractLongFromVariant(signal.info, "status", 0);
+ long progress = extractLongFromVariant(signal.info, "progress", 0);
+ long nOps = extractLongFromVariant(signal.info, "n_ops", -1);
+ long oP = extractLongFromVariant(signal.info, "op", -1);
+ String error = extractStringFromVariant(signal.info, "error");
+ String errorMessage = extractStringFromVariant(signal.info, "error_message");
Progress p = new Progress(nOps, oP, status, progress, error, errorMessage);
for (ProgressListener listener : progressListeners) {
listener.onProgress(p);
}
}
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
private UInt32 spawnApp(List<Byte> cwdPath, List<List<Byte>> argv, Map<UInt32, FileDescriptor> fds, Map<String, String> envs, UInt32 flags, Map<String, Variant<?>> options) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
return portal.Spawn(cwdPath, argv, fds, envs, flags, options); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
} |
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