@windowkit/appkit 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +205 -4
- package/binding.gyp +2 -1
- package/package.json +2 -2
- package/prebuilds/darwin-arm64/calayers.node +0 -0
- package/prebuilds/darwin-x64/calayers.node +0 -0
- package/src/addon.mm +570 -224
- package/src/backend.mm +2324 -1106
- package/src/calendars.mm +37 -25
- package/src/channel.h +232 -0
- package/src/notifications.mm +67 -42
- package/src/permissions.mm +22 -10
- package/src/screencolor.mm +29 -18
- package/src/threaded.mm +984 -0
package/src/screencolor.mm
CHANGED
|
@@ -40,6 +40,8 @@
|
|
|
40
40
|
#include <string>
|
|
41
41
|
#include <vector>
|
|
42
42
|
|
|
43
|
+
#include "channel.h" // CALOnUI: the session is the UI thread's; CALCallJS
|
|
44
|
+
|
|
43
45
|
// src/backend.mm — NSApplication set up exactly once, whichever verb comes
|
|
44
46
|
// first. The sampler is AppKit UI like a panel, so it wants an app.
|
|
45
47
|
void BEnsureApp();
|
|
@@ -52,9 +54,9 @@ struct ColorAnswer {
|
|
|
52
54
|
};
|
|
53
55
|
|
|
54
56
|
// The callers of the session that is up, in the order they asked; empty when
|
|
55
|
-
// none is. Touched on the
|
|
56
|
-
//
|
|
57
|
-
// handler
|
|
57
|
+
// none is. Touched on the UI thread only: the verb's own part runs there
|
|
58
|
+
// (inline in pump mode, a command from a worker), and so does AppKit's
|
|
59
|
+
// handler, inside the pump or the run.
|
|
58
60
|
static std::vector<Napi::ThreadSafeFunction> gWaiting;
|
|
59
61
|
|
|
60
62
|
// cb(err) | cb(null, null) | cb(null, { r, g, b }) on the JS thread, then the
|
|
@@ -63,16 +65,21 @@ static void Deliver(Napi::ThreadSafeFunction tsfn, const ColorAnswer& answer) {
|
|
|
63
65
|
ColorAnswer* a = new ColorAnswer(answer);
|
|
64
66
|
napi_status st = tsfn.BlockingCall(
|
|
65
67
|
a, [](Napi::Env env, Napi::Function cb, ColorAnswer* a) {
|
|
68
|
+
// an environment on its way out gets no answer (channel.h)
|
|
69
|
+
if (!CALCanCallIntoJS(env)) {
|
|
70
|
+
delete a;
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
66
73
|
if (!a->error.empty()) {
|
|
67
|
-
cb
|
|
74
|
+
CALCallJS(env, cb, {Napi::Error::New(env, a->error).Value()});
|
|
68
75
|
} else if (a->cancelled) {
|
|
69
|
-
cb
|
|
76
|
+
CALCallJS(env, cb, {env.Null(), env.Null()});
|
|
70
77
|
} else {
|
|
71
78
|
Napi::Object c = Napi::Object::New(env);
|
|
72
79
|
c.Set("r", Napi::Number::New(env, a->r));
|
|
73
80
|
c.Set("g", Napi::Number::New(env, a->g));
|
|
74
81
|
c.Set("b", Napi::Number::New(env, a->b));
|
|
75
|
-
cb
|
|
82
|
+
CALCallJS(env, cb, {env.Null(), c});
|
|
76
83
|
}
|
|
77
84
|
delete a;
|
|
78
85
|
});
|
|
@@ -121,18 +128,22 @@ static Napi::Value SampleScreenColor(const Napi::CallbackInfo& info) {
|
|
|
121
128
|
.ThrowAsJavaScriptException();
|
|
122
129
|
return env.Undefined();
|
|
123
130
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
131
|
+
// made in the caller's environment, which is the one answered
|
|
132
|
+
Napi::ThreadSafeFunction tsfn = Napi::ThreadSafeFunction::New(
|
|
133
|
+
env, info[0].As<Napi::Function>(), "appkit:sampleScreenColor", 0, 1);
|
|
134
|
+
CALOnUI(^{
|
|
135
|
+
@autoreleasepool {
|
|
136
|
+
BEnsureApp();
|
|
137
|
+
bool sessionUp = !gWaiting.empty();
|
|
138
|
+
gWaiting.push_back(tsfn);
|
|
139
|
+
if (sessionUp) return;
|
|
140
|
+
// Nothing here keeps the sampler alive: AppKit retains it for as long
|
|
141
|
+
// as the session lasts, which its header promises in as many words.
|
|
142
|
+
[[NSColorSampler new] showSamplerWithSelectionHandler:^(NSColor* c) {
|
|
143
|
+
FinishSession(c);
|
|
144
|
+
}];
|
|
145
|
+
}
|
|
146
|
+
});
|
|
136
147
|
return env.Undefined();
|
|
137
148
|
}
|
|
138
149
|
|