Skip to content

Commit f26d30e

Browse files
author
ntwigg
committed
Better docs.
1 parent c6fa015 commit f26d30e

File tree

1 file changed

+11
-4
lines changed
  • durian-swt.cocoa.macosx.aarch64/src/main/java/com/diffplug/common/swt/widgets

1 file changed

+11
-4
lines changed

durian-swt.cocoa.macosx.aarch64/src/main/java/com/diffplug/common/swt/widgets/MacDeepLink.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package com.diffplug.common.swt.widgets;
1717

1818
import com.diffplug.common.base.Preconditions;
19+
import com.diffplug.common.swt.SwtMisc;
1920
import java.util.ArrayList;
2021
import java.util.concurrent.atomic.AtomicReference;
2122
import java.util.function.Consumer;
@@ -24,34 +25,40 @@
2425
/**
2526
* - immediately on app startup, call `MacDeepLink.startCapturingBeforeSwt()`
2627
* - once SWT has initialized, call `MacDeepLink.swtHasInitializedBeginReceiving(Consumer<String>)`
28+
* - all urls which were captured before SWT initialized will be passed immediately (on the SWT thread)
2729
*
2830
* That's all! Don't do anything else.
2931
*/
3032
public class MacDeepLink {
33+
/**
34+
* state transitions are:
35+
* - `null` on startup
36+
* - `startCapturingBeforeSwt()` transitions to an `ArrayList<String>`, backlog urls get added to it
37+
* - `swtHasInitializedBeginReceiving()` transitions to a `Consumer<String>`, all new urls go there
38+
*/
3139
private static final AtomicReference<@Nullable Object> state = new AtomicReference<>();
3240

33-
static {
34-
// Load the native library - try multiple strategies
41+
public static void startCapturingBeforeSwt() {
3542
String libPath = System.getProperty("durian-swt.library.path");
3643
if (libPath != null) {
3744
System.load(libPath + "/durian-swt-natives/DeepLinkBridge.dylib");
3845
} else {
3946
throw new IllegalArgumentException("You need to set 'durian-swt.library.path'");
4047
}
41-
}
4248

43-
public static void startCapturingBeforeSwt() {
4449
var was = state.getAndSet(new ArrayList<>());
4550
Preconditions.checkArgument(was == null, "`startCapturingBeforeSwt() should be called first`");
4651
nativeBeforeSwt();
4752
}
4853

4954
public static void swtHasInitializedBeginReceiving(Consumer<String> handler) {
55+
SwtMisc.assertUI();
5056
var was = state.getAndSet(handler);
5157
Preconditions.checkArgument(was instanceof ArrayList<?>, "Call `applicationStartBeforeSwt()` first.");
5258

5359
var backlog = (ArrayList<String>) was;
5460
backlog.forEach(handler);
61+
5562
nativeAfterSwt();
5663
}
5764

0 commit comments

Comments
 (0)