Skip to content

Commit ffb84d8

Browse files
adjust to API changes
1 parent 08a7742 commit ffb84d8

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

src/main/java/org/cryptomator/linux/update/FlatpakUpdater.java

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import org.cryptomator.integrations.common.Priority;
77
import org.cryptomator.integrations.update.UpdateFailedException;
88
import org.cryptomator.integrations.update.UpdateMechanism;
9-
import org.cryptomator.integrations.update.UpdateProcess;
9+
import org.cryptomator.integrations.update.UpdateStep;
1010
import org.freedesktop.dbus.FileDescriptor;
1111
import org.freedesktop.dbus.exceptions.DBusException;
1212
import org.freedesktop.dbus.types.UInt32;
@@ -22,7 +22,6 @@
2222
import java.util.Collections;
2323
import java.util.List;
2424
import java.util.Map;
25-
import java.util.concurrent.CopyOnWriteArrayList;
2625
import java.util.concurrent.CountDownLatch;
2726
import java.util.concurrent.TimeUnit;
2827
import java.util.concurrent.atomic.AtomicBoolean;
@@ -73,29 +72,34 @@ public boolean isUpdateAvailable(String installedVersion) {
7372
}
7473

7574
@Override
76-
public UpdateProcess prepareUpdate() throws UpdateFailedException {
75+
public UpdateStep firstStep() throws UpdateFailedException {
7776
var monitorPath = portal.CreateUpdateMonitor(UpdatePortal.OPTIONS_DUMMY);
7877
if (monitorPath == null) {
7978
throw new UpdateFailedException("Failed to create UpdateMonitor on DBus");
8079
}
8180

82-
return new FlatpakUpdateProcess(portal.getUpdateMonitor(monitorPath.toString()));
81+
return new FlatpakUpdateStep(portal.getUpdateMonitor(monitorPath.toString()));
8382
}
8483

85-
private class FlatpakUpdateProcess implements UpdateProcess {
84+
private class FlatpakUpdateStep implements UpdateStep {
8685

8786
private final CountDownLatch latch = new CountDownLatch(1);
8887
private final Flatpak.UpdateMonitor monitor;
8988
private volatile double progress = 0.0;
9089
private volatile UpdateFailedException error;
9190
private AutoCloseable signalHandler;
9291

93-
private FlatpakUpdateProcess(Flatpak.UpdateMonitor monitor) {
92+
private FlatpakUpdateStep(Flatpak.UpdateMonitor monitor) {
9493
this.monitor = monitor;
95-
startUpdate();
9694
}
9795

98-
private void startUpdate() {
96+
@Override
97+
public String description() {
98+
return "Updating via Flatpak... %1.0f%%".formatted(preparationProgress() * 100);
99+
}
100+
101+
@Override
102+
public void start() {
99103
try {
100104
this.signalHandler = portal.getDBusConnection().addSigHandler(Flatpak.UpdateMonitor.Progress.class, this::handleProgressSignal);
101105
} catch (DBusException e) {
@@ -167,7 +171,8 @@ public boolean await(long timeout, TimeUnit unit) throws InterruptedException {
167171
return latch.await(timeout, unit);
168172
}
169173

170-
private boolean isDone() {
174+
@Override
175+
public boolean isDone() {
171176
try {
172177
return latch.await(0, TimeUnit.MILLISECONDS);
173178
} catch (InterruptedException e) {
@@ -177,7 +182,11 @@ private boolean isDone() {
177182
}
178183

179184
@Override
180-
public ProcessHandle applyUpdate() throws IllegalStateException, IOException {
185+
public UpdateStep nextStep() throws IllegalStateException, IOException {
186+
return UpdateStep.of("Restarting application", this::applyUpdate);
187+
}
188+
189+
public UpdateStep applyUpdate() throws IllegalStateException, IOException {
181190
if (!isDone()) {
182191
throw new IllegalStateException("Update preparation is not complete");
183192
}
@@ -195,7 +204,8 @@ public ProcessHandle applyUpdate() throws IllegalStateException, IOException {
195204
UInt32 flags = new UInt32(FlatpakSpawnFlag.LATEST_VERSION.getValue());
196205
Map<String, Variant<?>> options = UpdatePortal.OPTIONS_DUMMY;
197206
var pid = portal.Spawn(cwdPath, argv, fds, envs, flags, options).longValue();
198-
return ProcessHandle.of(pid).orElseThrow();
207+
LOG.info("Spawned updated Cryptomator process with PID {}", pid);
208+
return null;
199209
}
200210
}
201211

0 commit comments

Comments
 (0)