@macify/xpc 0.0.1
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/build/index.cjs +60 -0
- package/package.json +32 -0
package/build/index.cjs
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
let expo_modules_core = require("expo-modules-core");
|
|
3
|
+
|
|
4
|
+
//#region src/MacifyXPCModule.ts
|
|
5
|
+
var MacifyXPCModule_default = (0, expo_modules_core.requireNativeModule)("MacifyXPC");
|
|
6
|
+
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region src/index.ts
|
|
9
|
+
const emitter = new expo_modules_core.EventEmitter(MacifyXPCModule_default);
|
|
10
|
+
const subscriptionsByType = /* @__PURE__ */ new Map();
|
|
11
|
+
function trackSubscription(type, sub) {
|
|
12
|
+
let subs = subscriptionsByType.get(type);
|
|
13
|
+
if (!subs) {
|
|
14
|
+
subs = /* @__PURE__ */ new Set();
|
|
15
|
+
subscriptionsByType.set(type, subs);
|
|
16
|
+
}
|
|
17
|
+
subs.add(sub);
|
|
18
|
+
}
|
|
19
|
+
function untrackSubscription(type, sub) {
|
|
20
|
+
const subs = subscriptionsByType.get(type);
|
|
21
|
+
if (subs) {
|
|
22
|
+
subs.delete(sub);
|
|
23
|
+
if (subs.size === 0) subscriptionsByType.delete(type);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Client API for communicating with the XPC service.
|
|
28
|
+
*/
|
|
29
|
+
const macx = {
|
|
30
|
+
async call(type, payload = {}) {
|
|
31
|
+
const payloadJSON = JSON.stringify(payload);
|
|
32
|
+
const responseJSON = await MacifyXPCModule_default.call(type, payloadJSON);
|
|
33
|
+
return JSON.parse(responseJSON);
|
|
34
|
+
},
|
|
35
|
+
on(type, handler) {
|
|
36
|
+
const nativeEvent = type === "connectionLost" || type === "connectionRestored" ? "onXPCConnectionState" : "onXPCEvent";
|
|
37
|
+
const subscription = emitter.addListener(nativeEvent, (event) => {
|
|
38
|
+
if (event.type === type) try {
|
|
39
|
+
handler(event.payload ? JSON.parse(event.payload) : {});
|
|
40
|
+
} catch {
|
|
41
|
+
handler({});
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
trackSubscription(type, subscription);
|
|
45
|
+
return () => {
|
|
46
|
+
subscription.remove();
|
|
47
|
+
untrackSubscription(type, subscription);
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
off(type) {
|
|
51
|
+
const subs = subscriptionsByType.get(type);
|
|
52
|
+
if (subs) {
|
|
53
|
+
for (const sub of subs) sub.remove();
|
|
54
|
+
subscriptionsByType.delete(type);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
//#endregion
|
|
60
|
+
exports.macx = macx;
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@macify/xpc",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "XPC service support for Mac Catalyst Expo apps",
|
|
5
|
+
"main": "build/index.cjs",
|
|
6
|
+
"types": "build/index.d.cts",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsdown"
|
|
10
|
+
},
|
|
11
|
+
"devDependencies": {
|
|
12
|
+
"@expo/config-plugins": "*",
|
|
13
|
+
"@macify/xcode-types": "workspace:*",
|
|
14
|
+
"tsdown": "*"
|
|
15
|
+
},
|
|
16
|
+
"peerDependencies": {
|
|
17
|
+
"expo-modules-core": "*",
|
|
18
|
+
"react": "*",
|
|
19
|
+
"react-native": "*"
|
|
20
|
+
},
|
|
21
|
+
"peerDependenciesMeta": {
|
|
22
|
+
"expo-modules-core": {
|
|
23
|
+
"optional": true
|
|
24
|
+
},
|
|
25
|
+
"react": {
|
|
26
|
+
"optional": true
|
|
27
|
+
},
|
|
28
|
+
"react-native": {
|
|
29
|
+
"optional": true
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|