dal-code 1.0.28 → 1.0.30
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/CHANGELOG.md +13 -0
- package/dal-docs/README.md +1 -1
- package/dist/bundle/chunks/anthropic-messages-AZKHNVAG.js +5 -0
- package/dist/bundle/chunks/anthropic.js +74 -0
- package/dist/bundle/chunks/azure-openai-responses-LA3FYF3J.js +1 -0
- package/dist/bundle/chunks/bedrock-converse-stream.js +82 -0
- package/dist/bundle/chunks/chunk-4HEMJ3PG.js +1140 -0
- package/dist/bundle/chunks/chunk-4L3WN2XY.js +1 -0
- package/dist/bundle/chunks/chunk-4UTLMBZZ.js +13 -0
- package/dist/bundle/chunks/chunk-4XT6IQQ6.js +1 -0
- package/dist/bundle/chunks/chunk-5M7W2EDY.js +3 -0
- package/dist/bundle/chunks/chunk-5ULSWE2O.js +43 -0
- package/dist/bundle/chunks/chunk-6CYCI3EJ.js +11 -0
- package/dist/bundle/chunks/chunk-7ZC4UXSL.js +1 -0
- package/dist/bundle/chunks/chunk-ABVPQ2YN.js +14 -0
- package/dist/bundle/chunks/chunk-DRQDKNXA.js +1 -0
- package/dist/bundle/chunks/chunk-F5ZABL6Z.js +19 -0
- package/dist/bundle/chunks/chunk-GYI2XXNW.js +10 -0
- package/dist/bundle/chunks/chunk-H3QXYIF7.js +30 -0
- package/dist/bundle/chunks/chunk-HC56T2OZ.js +134 -0
- package/dist/bundle/chunks/chunk-HMFU7ZIF.js +1 -0
- package/dist/bundle/chunks/chunk-JEMNLK2O.js +10 -0
- package/dist/bundle/chunks/chunk-L2ZPNLYD.js +1 -0
- package/dist/bundle/chunks/chunk-LPXNMA2W.js +1 -0
- package/dist/bundle/chunks/chunk-PGXDEOVV.js +1 -0
- package/dist/bundle/chunks/chunk-PJACZCIR.js +1 -0
- package/dist/bundle/chunks/chunk-PMRZO46Y.js +1 -0
- package/dist/bundle/chunks/chunk-PRRNXB7S.js +1 -0
- package/dist/bundle/chunks/chunk-PRXLTI3Y.js +81 -0
- package/dist/bundle/chunks/chunk-Q6IMZXWD.js +129 -0
- package/dist/bundle/chunks/chunk-R4YWRKK4.js +7 -0
- package/dist/bundle/chunks/chunk-RDZVAGPR.js +1 -0
- package/dist/bundle/chunks/chunk-S3GGRYIO.js +5 -0
- package/dist/bundle/chunks/chunk-TEPMHNKQ.js +1 -0
- package/dist/bundle/chunks/chunk-TRDNDS6A.js +3 -0
- package/dist/bundle/chunks/chunk-USJZMAIR.js +1 -0
- package/dist/bundle/chunks/chunk-UTB4DTYQ.js +1 -0
- package/dist/bundle/chunks/chunk-WXULTH2D.js +1 -0
- package/dist/bundle/chunks/chunk-YKF7PQCJ.js +1 -0
- package/dist/bundle/chunks/chunk-YTERFI73.js +1 -0
- package/dist/bundle/chunks/chunk-ZBURYEWF.js +1 -0
- package/dist/bundle/chunks/chunk-ZKDITC7J.js +35 -0
- package/dist/bundle/chunks/cli-2LJMKSUZ.js +50 -0
- package/dist/bundle/chunks/cloudflare-workers-ai-system-one-6WEJUIW2.js +1 -0
- package/dist/bundle/chunks/codemode-worker.js +470 -0
- package/dist/bundle/chunks/dist-37IE4EWG.js +10 -0
- package/dist/bundle/chunks/easter-egg-3d-GHWWTBZN.js +1 -0
- package/dist/bundle/chunks/execute-JU22LJZT.js +489 -0
- package/dist/bundle/chunks/github-copilot.js +1 -0
- package/dist/bundle/chunks/google-generative-ai-RFPHNE43.js +1 -0
- package/dist/bundle/chunks/google-vertex-QDNCMHLE.js +1 -0
- package/dist/bundle/chunks/http-proxy-6TR4MP55.js +1 -0
- package/dist/bundle/chunks/https-proxy-agent-2VXB7436.js +12 -0
- package/dist/bundle/chunks/image-resize-worker.js +1 -0
- package/dist/bundle/chunks/jiti-loader-C3NU2SDH.js +20 -0
- package/dist/bundle/chunks/jiti-static-loader-E6ANQD5T.js +1 -0
- package/dist/bundle/chunks/kimi-coding.js +1 -0
- package/dist/bundle/chunks/lib-TEDK3E5I.js +8 -0
- package/dist/bundle/chunks/llama-cpp-classify-FYN623RH.js +21 -0
- package/dist/bundle/chunks/meta.js +1 -0
- package/dist/bundle/chunks/mistral-conversations-YHX5TRKG.js +4 -0
- package/dist/bundle/chunks/multipart-parser-SQ6GDJL7.js +2 -0
- package/dist/bundle/chunks/node-N5BSDOA5.js +15 -0
- package/dist/bundle/chunks/node-TWVVAGPO.js +1 -0
- package/dist/bundle/chunks/openai-chatgpt.js +74 -0
- package/dist/bundle/chunks/openai-codex-responses-UZEMMAYZ.js +9 -0
- package/dist/bundle/chunks/openai-codex.js +74 -0
- package/dist/bundle/chunks/openai-completions-H6WMELZZ.js +6 -0
- package/dist/bundle/chunks/openai-decisions-URHWCZPN.js +4 -0
- package/dist/bundle/chunks/openai-responses-7X65PCAB.js +2 -0
- package/dist/bundle/chunks/openrouter-images-DUPG5DZO.js +1 -0
- package/dist/bundle/chunks/openrouter.js +74 -0
- package/dist/bundle/chunks/pi-messages-YHKPQIHC.js +7 -0
- package/dist/bundle/chunks/radius.js +74 -0
- package/dist/bundle/chunks/runtime-LLITCT4N.js +1 -0
- package/dist/bundle/chunks/src-UK77SYZE.js +3 -0
- package/dist/bundle/chunks/typesafe-system-one-N7PKHI2N.js +1 -0
- package/dist/bundle/chunks/virtual-modules-H32OTUCD.js +1 -0
- package/dist/bundle/chunks/xai.js +1 -0
- package/dist/bundle/cli-runtime.js +2 -0
- package/dist/bundle/cli.js +2 -0
- package/dist/bundle/index.js +1 -0
- package/dist/bundle/rpc-entry.js +2 -0
- package/dist/core/key-id-schema.js +1 -0
- package/dist/core/keybindings-schema.js +1 -0
- package/dist/core/settings-defaults.js +1 -0
- package/dist/core/settings-schema.js +1 -0
- package/dist/core/system-prompt.js +9 -9
- package/dist/modes/interactive/components/daxnuts.js +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts +3 -0
- package/dist/modes/interactive/interactive-mode.js +31 -31
- package/dist/modes/interactive/theme/theme-schema.js +12 -0
- package/dist/modes/interactive/theme/theme-tokens.js +1 -0
- package/dist/node_modules/@dalcode/dal-bridge/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-gateway/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-guard/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-guard/src/index.js +1 -1
- package/dist/node_modules/@dalcode/dal-guard/src/mode.js +2 -0
- package/dist/node_modules/@dalcode/dal-halo/package.json +1 -1
- package/dist/node_modules/@dalcode/dal-interactive/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-lang/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-lsp/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-mcp/package.json +5 -5
- package/dist/node_modules/@dalcode/dal-office/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-pi-kit/dist/i18n.js +1 -1
- package/dist/node_modules/@dalcode/dal-pi-kit/package.json +1 -1
- package/dist/node_modules/@dalcode/dal-pi-kit/src/i18n.js +1 -1
- package/dist/node_modules/@dalcode/dal-plugins/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-review/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-rewind/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-router/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-skills/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-subagent/package.json +5 -5
- package/dist/node_modules/@dalcode/dal-telemetry/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-terminal/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-tool-catalog/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-web/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-workflow/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-workflow/src/check-in.js +2 -0
- package/dist/node_modules/@dalcode/dal-workflow/src/index.js +4 -4
- package/dist/node_modules/@dalcode/dal-workflow/src/todo.js +2 -2
- package/dist/node_modules/@dalcode/deepailab/package.json +3 -3
- package/dist/node_modules/@earendil-works/chord/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-agent-core/package.json +2 -2
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/compat-schema.js +1 -0
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/huggingface.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/model-schema.js +1 -0
- package/dist/node_modules/@earendil-works/pi-ai/package.json +2 -2
- package/dist/node_modules/@earendil-works/pi-client/package.json +3 -3
- package/dist/node_modules/@earendil-works/pi-codemode/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-coding-agent/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-mcp/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-protocol/package.json +2 -2
- package/dist/node_modules/@earendil-works/pi-server/package.json +3 -3
- package/dist/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/native/darwin/prebuilds/darwin-arm64/darwin-platform.node +0 -0
- package/dist/node_modules/@earendil-works/pi-tui/native/darwin/prebuilds/darwin-x64/darwin-platform.node +0 -0
- package/dist/node_modules/@earendil-works/pi-tui/native/darwin/src/darwin-platform.m +132 -0
- package/dist/node_modules/@earendil-works/pi-tui/native/linux/prebuilds/linux-arm64/linux-platform-x11.node +0 -0
- package/dist/node_modules/@earendil-works/pi-tui/native/linux/prebuilds/linux-x64/linux-platform-x11.node +0 -0
- package/dist/node_modules/@earendil-works/pi-tui/native/linux/src/clipboard-worker.h +70 -0
- package/dist/node_modules/@earendil-works/pi-tui/native/linux/src/linux-platform-x11.c +274 -0
- package/dist/node_modules/@earendil-works/pi-tui/native/win32/prebuilds/win32-arm64/win32-platform.node +0 -0
- package/dist/node_modules/@earendil-works/pi-tui/native/win32/prebuilds/win32-x64/win32-platform.node +0 -0
- package/dist/node_modules/@earendil-works/pi-tui/native/win32/src/win32-platform.c +241 -0
- package/dist/node_modules/@earendil-works/pi-tui/package.json +1 -1
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var m=Object.defineProperty;var o=(t,r)=>m(t,"name",{value:r,configurable:!0});import{Type as e}from"typebox";const n=["minimal","low","medium","high","xhigh","max"],a=["off",...n],c=["text","image"],p=["none","short","long"],l=["short","long"],M=e.Enum(n),u=e.Enum(a),I=e.Enum(c),S=e.Enum(p),h=e.Union([e.String(),e.Null()]),E=e.Partial(e.Record(u,h)),b=e.Partial(e.Record(e.Enum(l),e.Number({exclusiveMinimum:0})),{description:"Best-effort prompt cache lifetime in seconds for each retention tier. A missing tier means the lifetime is unknown, so Pi does not warm it."}),i={input:e.Number({description:"Input cost in USD per million tokens."}),output:e.Number({description:"Output cost in USD per million tokens."}),cacheRead:e.Number({description:"Cache-read cost in USD per million tokens."}),cacheWrite:e.Number({description:"Cache-write cost in USD per million tokens."})},T=e.Object(i),d=e.Object({inputTokensAbove:e.Number({description:"Use this tier when total request input exceeds this token count."}),...i}),N=e.Object({...i,tiers:e.Optional(e.Array(d,{description:"Request-wide pricing tiers. The highest matching input threshold applies to the full request."}))});function s(t){return e.Object({maxWidth:e.Optional(e.Integer({minimum:1})),maxHeight:e.Optional(e.Integer({minimum:1})),maxBytes:e.Optional(e.Integer({minimum:1,description:"Maximum base64-encoded payload size in bytes."})),jpegQuality:e.Optional(e.Integer({minimum:1,maximum:100}))},t)}o(s,"modelImageResizeOptions");const L=s(),x=e.Object({resize:e.Optional(s({description:"Cache-safe resize profile applied before a new image enters conversation history."})),maxPerMessage:e.Optional(e.Integer({minimum:1,description:"Maximum images accepted in one provider message."})),maxPerRequest:e.Optional(e.Integer({minimum:1,description:"Maximum images accepted across one provider request."}))}),R=e.Object({maxRequestBytes:e.Optional(e.Integer({minimum:1,description:"Maximum serialized provider request size in bytes."})),images:e.Optional(x)});export{p as CACHE_RETENTIONS,S as CacheRetentionSchema,c as MODEL_INPUT_MODALITIES,l as MODEL_PROMPT_CACHE_RETENTIONS,a as MODEL_THINKING_LEVELS,T as ModelCostRatesSchema,N as ModelCostSchema,d as ModelCostTierSchema,x as ModelImageInputLimitsSchema,L as ModelImageResizeOptionsSchema,R as ModelInputLimitsSchema,I as ModelInputModalitySchema,b as ModelPromptCacheSchema,u as ModelThinkingLevelSchema,n as THINKING_LEVELS,E as ThinkingLevelMapSchema,M as ThinkingLevelSchema};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@earendil-works/pi-ai",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.30",
|
|
4
4
|
"description": "Unified LLM API with automatic model discovery and provider configuration",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"@anthropic-ai/sdk": "0.129.0",
|
|
60
60
|
"@aws-sdk/client-bedrock-runtime": "3.1127.0",
|
|
61
|
-
"@earendil-works/pi-telemetry": "^1.0.
|
|
61
|
+
"@earendil-works/pi-telemetry": "^1.0.30",
|
|
62
62
|
"@google/genai": "2.21.0",
|
|
63
63
|
"@opentelemetry/api": "1.9.0",
|
|
64
64
|
"@smithy/node-http-handler": "4.12.1",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@earendil-works/pi-client",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.30",
|
|
4
4
|
"description": "Transport-neutral client for remote pi sessions over framed CBOR bytes",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"node": ">=22.19.0"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@earendil-works/chord": "^1.0.
|
|
44
|
-
"@earendil-works/pi-protocol": "^1.0.
|
|
43
|
+
"@earendil-works/chord": "^1.0.30",
|
|
44
|
+
"@earendil-works/pi-protocol": "^1.0.30"
|
|
45
45
|
}
|
|
46
46
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@earendil-works/pi-protocol",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.30",
|
|
4
4
|
"description": "Transport-neutral CBOR protocol for remote pi sessions",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"node": ">=22.19.0"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@earendil-works/chord": "^1.0.
|
|
36
|
+
"@earendil-works/chord": "^1.0.30",
|
|
37
37
|
"typebox": "1.3.27"
|
|
38
38
|
}
|
|
39
39
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@earendil-works/pi-server",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.30",
|
|
4
4
|
"description": "experimental server package for pi",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"node": ">=22.19.0"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@earendil-works/chord": "^1.0.
|
|
43
|
-
"@earendil-works/pi-protocol": "^1.0.
|
|
42
|
+
"@earendil-works/chord": "^1.0.30",
|
|
43
|
+
"@earendil-works/pi-protocol": "^1.0.30"
|
|
44
44
|
}
|
|
45
45
|
}
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
#import <AppKit/AppKit.h>
|
|
2
|
+
#import <CoreGraphics/CoreGraphics.h>
|
|
3
|
+
#import <Foundation/Foundation.h>
|
|
4
|
+
#include <stdlib.h>
|
|
5
|
+
#include <string.h>
|
|
6
|
+
#define PI_CLIPBOARD_WRITE
|
|
7
|
+
#include "../../clipboard.h"
|
|
8
|
+
|
|
9
|
+
static CGEventFlags modifier_mask_for_name(const char* name) {
|
|
10
|
+
if (strcmp(name, "shift") == 0) return kCGEventFlagMaskShift;
|
|
11
|
+
if (strcmp(name, "command") == 0) return kCGEventFlagMaskCommand;
|
|
12
|
+
if (strcmp(name, "control") == 0) return kCGEventFlagMaskControl;
|
|
13
|
+
if (strcmp(name, "option") == 0) return kCGEventFlagMaskAlternate;
|
|
14
|
+
return 0;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
static napi_value is_modifier_pressed(napi_env env, napi_callback_info info) {
|
|
18
|
+
napi_get_cb_info_fn napi_get_cb_info = (napi_get_cb_info_fn)node_symbol("napi_get_cb_info");
|
|
19
|
+
napi_get_value_string_utf8_fn napi_get_value_string_utf8 =
|
|
20
|
+
(napi_get_value_string_utf8_fn)node_symbol("napi_get_value_string_utf8");
|
|
21
|
+
napi_get_boolean_fn napi_get_boolean = (napi_get_boolean_fn)node_symbol("napi_get_boolean");
|
|
22
|
+
|
|
23
|
+
bool pressed = false;
|
|
24
|
+
if (napi_get_cb_info && napi_get_value_string_utf8) {
|
|
25
|
+
size_t argc = 1;
|
|
26
|
+
napi_value args[1] = {0};
|
|
27
|
+
if (napi_get_cb_info(env, info, &argc, args, 0, 0) == 0 && argc >= 1 && args[0]) {
|
|
28
|
+
char name[16] = {0};
|
|
29
|
+
size_t copied = 0;
|
|
30
|
+
if (napi_get_value_string_utf8(env, args[0], name, sizeof(name), &copied) == 0) {
|
|
31
|
+
CGEventFlags mask = modifier_mask_for_name(name);
|
|
32
|
+
if (mask != 0) {
|
|
33
|
+
CGEventFlags flags = CGEventSourceFlagsState(kCGEventSourceStateCombinedSessionState);
|
|
34
|
+
pressed = (flags & mask) != 0;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
napi_value result = 0;
|
|
41
|
+
if (!napi_get_boolean || napi_get_boolean(env, pressed, &result) != 0) {
|
|
42
|
+
return fail(env, "Could not inspect modifier state");
|
|
43
|
+
}
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
static void clipboard_execute(clipboard_job* job) {
|
|
48
|
+
@autoreleasepool {
|
|
49
|
+
NSPasteboard* pasteboard = [NSPasteboard generalPasteboard];
|
|
50
|
+
if (!pasteboard) {
|
|
51
|
+
job->error = "Could not open clipboard";
|
|
52
|
+
} else if (job->operation == CLIPBOARD_WRITE) {
|
|
53
|
+
NSString* text = [[NSString alloc] initWithBytes:job->data length:job->length encoding:NSUTF8StringEncoding];
|
|
54
|
+
if (!text) {
|
|
55
|
+
job->error = "Clipboard text is not valid UTF-8";
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
[pasteboard clearContents];
|
|
59
|
+
if (![pasteboard setString:text forType:NSPasteboardTypeString]) job->error = "Could not set clipboard text";
|
|
60
|
+
} else if (job->operation == CLIPBOARD_TEXT) {
|
|
61
|
+
NSString* text = [pasteboard stringForType:NSPasteboardTypeString];
|
|
62
|
+
if (!text) {
|
|
63
|
+
job->format = CLIPBOARD_EMPTY;
|
|
64
|
+
} else if (!text.UTF8String) {
|
|
65
|
+
job->error = "Could not encode clipboard text";
|
|
66
|
+
} else {
|
|
67
|
+
clipboard_copy(job, text.UTF8String, [text lengthOfBytesUsingEncoding:NSUTF8StringEncoding], CLIPBOARD_UTF8);
|
|
68
|
+
}
|
|
69
|
+
} else if (job->operation == CLIPBOARD_FILES) {
|
|
70
|
+
NSArray* urls = [pasteboard readObjectsForClasses:@[[NSURL class]]
|
|
71
|
+
options:@{NSPasteboardURLReadingFileURLsOnlyKey: @YES}];
|
|
72
|
+
size_t total = 0;
|
|
73
|
+
for (NSURL* url in urls) {
|
|
74
|
+
const char* path = url.fileSystemRepresentation;
|
|
75
|
+
if (!path) continue;
|
|
76
|
+
size_t length = strlen(path);
|
|
77
|
+
if (length == SIZE_MAX || total > SIZE_MAX - length - 1) {
|
|
78
|
+
job->error = "Clipboard file paths are too large";
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
total += length + 1;
|
|
82
|
+
}
|
|
83
|
+
if (total == 0) {
|
|
84
|
+
job->format = CLIPBOARD_EMPTY;
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
char* paths = clipboard_alloc(total);
|
|
88
|
+
if (!paths) {
|
|
89
|
+
job->error = "Out of memory";
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
char* cursor = paths;
|
|
93
|
+
for (NSURL* url in urls) {
|
|
94
|
+
const char* path = url.fileSystemRepresentation;
|
|
95
|
+
if (!path) continue;
|
|
96
|
+
size_t length = strlen(path);
|
|
97
|
+
memcpy(cursor, path, length + 1);
|
|
98
|
+
cursor += length + 1;
|
|
99
|
+
}
|
|
100
|
+
job->data = paths;
|
|
101
|
+
job->length = total;
|
|
102
|
+
job->format = CLIPBOARD_PATHS;
|
|
103
|
+
} else {
|
|
104
|
+
if (![pasteboard availableTypeFromArray:@[ NSPasteboardTypePNG, NSPasteboardTypeTIFF ]]) {
|
|
105
|
+
job->format = CLIPBOARD_EMPTY;
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
NSData* png = [pasteboard dataForType:NSPasteboardTypePNG];
|
|
109
|
+
if (!png) {
|
|
110
|
+
NSImage* image = [[NSImage alloc] initWithPasteboard:pasteboard];
|
|
111
|
+
NSData* tiff = image.TIFFRepresentation;
|
|
112
|
+
NSBitmapImageRep* bitmap = tiff ? [NSBitmapImageRep imageRepWithData:tiff] : nil;
|
|
113
|
+
png = bitmap ? [bitmap representationUsingType:NSBitmapImageFileTypePNG properties:@{}] : nil;
|
|
114
|
+
}
|
|
115
|
+
if (png) clipboard_copy(job, png.bytes, png.length, CLIPBOARD_BUFFER);
|
|
116
|
+
else job->error = "Clipboard does not contain an image";
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
static napi_value PI_NAPI_CALL get_clipboard_file_paths(napi_env env, napi_callback_info info) {
|
|
122
|
+
return queue_clipboard(env, info, CLIPBOARD_FILES);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
PI_NAPI_EXPORT napi_value napi_register_module_v1(napi_env env, napi_value exports) {
|
|
126
|
+
set_function_export(env, exports, "isModifierPressed", is_modifier_pressed);
|
|
127
|
+
set_function_export(env, exports, "getText", get_clipboard_text);
|
|
128
|
+
set_function_export(env, exports, "setText", set_clipboard_text);
|
|
129
|
+
set_function_export(env, exports, "getImage", get_clipboard_image);
|
|
130
|
+
set_function_export(env, exports, "getFilePaths", get_clipboard_file_paths);
|
|
131
|
+
return exports;
|
|
132
|
+
}
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
#include <pthread.h>
|
|
2
|
+
#include <time.h>
|
|
3
|
+
#include "../../clipboard.h"
|
|
4
|
+
|
|
5
|
+
static void read_clipboard(clipboard_job* job);
|
|
6
|
+
static pthread_mutex_t worker_mutex = PTHREAD_MUTEX_INITIALIZER;
|
|
7
|
+
static pthread_once_t worker_once = PTHREAD_ONCE_INIT;
|
|
8
|
+
static pthread_cond_t worker_changed;
|
|
9
|
+
static bool worker_ready, worker_busy, worker_waiting, worker_finished;
|
|
10
|
+
static clipboard_job worker_result;
|
|
11
|
+
static int (*signal_worker)(pthread_cond_t*);
|
|
12
|
+
static int (*wait_for_worker)(pthread_cond_t*, pthread_mutex_t*, const struct timespec*);
|
|
13
|
+
|
|
14
|
+
static void initialize_worker_condition(void) {
|
|
15
|
+
// Unversioned ELF imports otherwise bind obsolete condition variables on glibc x64.
|
|
16
|
+
int (*initialize)(pthread_cond_t*, const pthread_condattr_t*) = node_symbol("pthread_cond_init");
|
|
17
|
+
signal_worker = node_symbol("pthread_cond_signal");
|
|
18
|
+
wait_for_worker = node_symbol("pthread_cond_timedwait");
|
|
19
|
+
if (!initialize || !signal_worker || !wait_for_worker) return;
|
|
20
|
+
pthread_condattr_t attributes;
|
|
21
|
+
if (pthread_condattr_init(&attributes) != 0) return;
|
|
22
|
+
worker_ready = pthread_condattr_setclock(&attributes, CLOCK_MONOTONIC) == 0 &&
|
|
23
|
+
initialize(&worker_changed, &attributes) == 0;
|
|
24
|
+
pthread_condattr_destroy(&attributes);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static void* read_on_private_thread(void* unused) {
|
|
28
|
+
(void)unused;
|
|
29
|
+
read_clipboard(&worker_result);
|
|
30
|
+
pthread_mutex_lock(&worker_mutex);
|
|
31
|
+
worker_finished = true;
|
|
32
|
+
if (!worker_waiting) {
|
|
33
|
+
free(worker_result.data); // The caller timed out; discard the late result.
|
|
34
|
+
worker_busy = false;
|
|
35
|
+
}
|
|
36
|
+
signal_worker(&worker_changed);
|
|
37
|
+
pthread_mutex_unlock(&worker_mutex);
|
|
38
|
+
return 0;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static void clipboard_execute(clipboard_job* job) {
|
|
42
|
+
pthread_once(&worker_once, initialize_worker_condition);
|
|
43
|
+
if (!worker_ready) return;
|
|
44
|
+
pthread_mutex_lock(&worker_mutex);
|
|
45
|
+
if (!worker_busy) {
|
|
46
|
+
worker_busy = worker_waiting = true;
|
|
47
|
+
worker_finished = false;
|
|
48
|
+
worker_result = (clipboard_job){.operation = job->operation};
|
|
49
|
+
struct timespec deadline;
|
|
50
|
+
clock_gettime(CLOCK_MONOTONIC, &deadline);
|
|
51
|
+
deadline.tv_sec += 3; // Allow the two-second transfer deadline to report its own error first.
|
|
52
|
+
pthread_t thread;
|
|
53
|
+
if (pthread_create(&thread, 0, read_on_private_thread, 0) == 0) {
|
|
54
|
+
pthread_detach(thread);
|
|
55
|
+
// Only this bounded wait occupies libuv. Other callers return unavailable.
|
|
56
|
+
while (!worker_finished && wait_for_worker(&worker_changed, &worker_mutex, &deadline) == 0) {}
|
|
57
|
+
if (worker_finished) {
|
|
58
|
+
job->data = worker_result.data;
|
|
59
|
+
job->length = worker_result.length;
|
|
60
|
+
job->format = worker_result.format;
|
|
61
|
+
job->error = worker_result.error;
|
|
62
|
+
worker_busy = false;
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
worker_busy = false;
|
|
66
|
+
}
|
|
67
|
+
worker_waiting = false;
|
|
68
|
+
}
|
|
69
|
+
pthread_mutex_unlock(&worker_mutex);
|
|
70
|
+
}
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
#include <xcb/xcb.h>
|
|
2
|
+
#include <string.h>
|
|
3
|
+
#include <xcb/xcbext.h>
|
|
4
|
+
#include <errno.h>
|
|
5
|
+
#include <poll.h>
|
|
6
|
+
#include <time.h>
|
|
7
|
+
#include "clipboard-worker.h"
|
|
8
|
+
|
|
9
|
+
#define MAX_CLIPBOARD_BYTES (50u * 1024u * 1024u)
|
|
10
|
+
#define CLIPBOARD_TIMEOUT_MS 2000
|
|
11
|
+
|
|
12
|
+
static const char* const text_types[] = {
|
|
13
|
+
"text/plain;charset=utf-8", "text/plain;charset=UTF-8", "UTF8_STRING", "text/plain", "STRING",
|
|
14
|
+
};
|
|
15
|
+
static const char* const image_types[] = {
|
|
16
|
+
"image/png", "image/jpeg", "image/webp", "image/gif", "image/bmp", "image/tiff",
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
static int64_t monotonic_ms(void) {
|
|
20
|
+
struct timespec now;
|
|
21
|
+
clock_gettime(CLOCK_MONOTONIC, &now);
|
|
22
|
+
return (int64_t)now.tv_sec * 1000 + now.tv_nsec / 1000000;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
typedef struct {
|
|
26
|
+
unsigned char* data;
|
|
27
|
+
size_t length;
|
|
28
|
+
uint32_t items;
|
|
29
|
+
uint8_t format;
|
|
30
|
+
xcb_atom_t type;
|
|
31
|
+
} property_data;
|
|
32
|
+
|
|
33
|
+
typedef struct {
|
|
34
|
+
xcb_connection_t* connection;
|
|
35
|
+
xcb_window_t window;
|
|
36
|
+
xcb_atom_t clipboard;
|
|
37
|
+
xcb_atom_t property;
|
|
38
|
+
xcb_atom_t targets;
|
|
39
|
+
xcb_atom_t incr;
|
|
40
|
+
int64_t deadline;
|
|
41
|
+
} x11_clipboard;
|
|
42
|
+
|
|
43
|
+
static bool append_bytes(property_data* result, const unsigned char* bytes, size_t length) {
|
|
44
|
+
if (length > MAX_CLIPBOARD_BYTES - result->length) return false;
|
|
45
|
+
unsigned char* data = realloc(result->data, result->length + length + 1);
|
|
46
|
+
if (!data) return false;
|
|
47
|
+
memcpy(data + result->length, bytes, length);
|
|
48
|
+
result->length += length;
|
|
49
|
+
data[result->length] = 0;
|
|
50
|
+
result->data = data;
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Share one deadline across discovery, replies, and incremental chunks.
|
|
55
|
+
// Connection setup and flushing are libxcb calls on the private thread.
|
|
56
|
+
static bool wait_for_input(x11_clipboard* clipboard) {
|
|
57
|
+
for (;;) {
|
|
58
|
+
int64_t remaining = clipboard->deadline - monotonic_ms();
|
|
59
|
+
if (remaining <= 0 || xcb_connection_has_error(clipboard->connection)) return false;
|
|
60
|
+
struct pollfd descriptor = {xcb_get_file_descriptor(clipboard->connection), POLLIN, 0};
|
|
61
|
+
int ready = poll(&descriptor, 1, (int)remaining);
|
|
62
|
+
if (ready >= 0) return ready && (descriptor.revents & POLLIN);
|
|
63
|
+
if (errno != EINTR) return false;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
static void* wait_for_reply(x11_clipboard* clipboard, unsigned sequence) {
|
|
68
|
+
if (xcb_flush(clipboard->connection) <= 0) return 0;
|
|
69
|
+
while (monotonic_ms() < clipboard->deadline) {
|
|
70
|
+
void* reply = 0;
|
|
71
|
+
xcb_generic_error_t* error = 0;
|
|
72
|
+
if (xcb_poll_for_reply(clipboard->connection, sequence, &reply, &error)) {
|
|
73
|
+
free(error);
|
|
74
|
+
return reply;
|
|
75
|
+
}
|
|
76
|
+
if (!wait_for_input(clipboard)) break;
|
|
77
|
+
}
|
|
78
|
+
xcb_discard_reply(clipboard->connection, sequence);
|
|
79
|
+
return 0;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
static xcb_generic_event_t* wait_for_event(x11_clipboard* clipboard, uint8_t type) {
|
|
83
|
+
if (xcb_flush(clipboard->connection) <= 0) return 0;
|
|
84
|
+
while (monotonic_ms() < clipboard->deadline) {
|
|
85
|
+
xcb_generic_event_t* event = xcb_poll_for_event(clipboard->connection);
|
|
86
|
+
if (event) {
|
|
87
|
+
if ((event->response_type & 0x7f) == type) return event;
|
|
88
|
+
free(event);
|
|
89
|
+
} else if (!wait_for_input(clipboard)) {
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return 0;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
static bool read_property(x11_clipboard* clipboard, bool remove, property_data* result) {
|
|
97
|
+
xcb_get_property_cookie_t cookie = xcb_get_property(
|
|
98
|
+
clipboard->connection, remove, clipboard->window, clipboard->property,
|
|
99
|
+
XCB_GET_PROPERTY_TYPE_ANY, 0, MAX_CLIPBOARD_BYTES / 4
|
|
100
|
+
);
|
|
101
|
+
xcb_get_property_reply_t* reply = wait_for_reply(clipboard, cookie.sequence);
|
|
102
|
+
if (!reply) return false;
|
|
103
|
+
bool copied = false;
|
|
104
|
+
bool valid_format = reply->format == 8 || reply->format == 16 || reply->format == 32;
|
|
105
|
+
uint64_t length = (uint64_t)reply->value_len * (reply->format / 8);
|
|
106
|
+
if (reply->bytes_after == 0 && reply->type != XCB_NONE && valid_format &&
|
|
107
|
+
length <= MAX_CLIPBOARD_BYTES && length <= (uint64_t)reply->length * 4) {
|
|
108
|
+
result->type = reply->type;
|
|
109
|
+
result->format = reply->format;
|
|
110
|
+
result->items = reply->value_len;
|
|
111
|
+
copied = append_bytes(result, xcb_get_property_value(reply), (size_t)length);
|
|
112
|
+
}
|
|
113
|
+
free(reply);
|
|
114
|
+
return copied;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
static bool append_property(property_data* result, const property_data* chunk) {
|
|
118
|
+
if ((chunk->format != 8 && chunk->format != 16 && chunk->format != 32) ||
|
|
119
|
+
chunk->type == XCB_NONE ||
|
|
120
|
+
(uint64_t)chunk->items * (chunk->format / 8) != chunk->length ||
|
|
121
|
+
(result->type != XCB_NONE && (result->type != chunk->type || result->format != chunk->format)) ||
|
|
122
|
+
chunk->items > UINT32_MAX - result->items) return false;
|
|
123
|
+
if (!append_bytes(result, chunk->data, chunk->length)) return false;
|
|
124
|
+
result->type = chunk->type;
|
|
125
|
+
result->format = chunk->format;
|
|
126
|
+
result->items += chunk->items;
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
static bool request_selection(x11_clipboard* clipboard, xcb_atom_t target, property_data* result) {
|
|
131
|
+
memset(result, 0, sizeof(*result));
|
|
132
|
+
xcb_delete_property(clipboard->connection, clipboard->window, clipboard->property);
|
|
133
|
+
xcb_convert_selection(
|
|
134
|
+
clipboard->connection, clipboard->window, clipboard->clipboard,
|
|
135
|
+
target, clipboard->property, XCB_CURRENT_TIME
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
while (true) {
|
|
139
|
+
xcb_selection_notify_event_t* event = (xcb_selection_notify_event_t*)wait_for_event(clipboard, XCB_SELECTION_NOTIFY);
|
|
140
|
+
if (!event) return false;
|
|
141
|
+
bool matches = event->selection == clipboard->clipboard && event->target == target;
|
|
142
|
+
bool received = event->property != XCB_NONE;
|
|
143
|
+
free(event);
|
|
144
|
+
if (!matches) continue;
|
|
145
|
+
if (!received) return true; // No owner, or the owner does not offer this target.
|
|
146
|
+
if (!read_property(clipboard, false, result)) return false;
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
if (result->type != clipboard->incr) return true;
|
|
150
|
+
|
|
151
|
+
free(result->data);
|
|
152
|
+
memset(result, 0, sizeof(*result));
|
|
153
|
+
xcb_delete_property(clipboard->connection, clipboard->window, clipboard->property);
|
|
154
|
+
|
|
155
|
+
while (true) {
|
|
156
|
+
xcb_property_notify_event_t* event = (xcb_property_notify_event_t*)wait_for_event(clipboard, XCB_PROPERTY_NOTIFY);
|
|
157
|
+
if (!event) return false;
|
|
158
|
+
bool matches = event->atom == clipboard->property && event->state == XCB_PROPERTY_NEW_VALUE;
|
|
159
|
+
free(event);
|
|
160
|
+
if (!matches) continue;
|
|
161
|
+
|
|
162
|
+
property_data chunk = {0};
|
|
163
|
+
if (!read_property(clipboard, true, &chunk)) return false;
|
|
164
|
+
bool appended = append_property(result, &chunk);
|
|
165
|
+
bool finished = chunk.items == 0;
|
|
166
|
+
free(chunk.data);
|
|
167
|
+
if (!appended) return false;
|
|
168
|
+
if (finished) return true;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
static xcb_atom_t intern_atom(x11_clipboard* clipboard, const char* name) {
|
|
173
|
+
xcb_intern_atom_cookie_t cookie = xcb_intern_atom(clipboard->connection, false, strlen(name), name);
|
|
174
|
+
xcb_intern_atom_reply_t* reply = wait_for_reply(clipboard, cookie.sequence);
|
|
175
|
+
if (!reply) return XCB_NONE;
|
|
176
|
+
xcb_atom_t atom = reply->atom;
|
|
177
|
+
free(reply);
|
|
178
|
+
return atom;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
static bool open_clipboard(x11_clipboard* clipboard) {
|
|
182
|
+
memset(clipboard, 0, sizeof(*clipboard));
|
|
183
|
+
clipboard->deadline = monotonic_ms() + CLIPBOARD_TIMEOUT_MS;
|
|
184
|
+
int screen_number = 0;
|
|
185
|
+
clipboard->connection = xcb_connect(0, &screen_number);
|
|
186
|
+
if (xcb_connection_has_error(clipboard->connection)) return false;
|
|
187
|
+
xcb_screen_iterator_t screens = xcb_setup_roots_iterator(xcb_get_setup(clipboard->connection));
|
|
188
|
+
while (screen_number-- > 0 && screens.rem) xcb_screen_next(&screens);
|
|
189
|
+
if (!screens.rem) return false;
|
|
190
|
+
|
|
191
|
+
clipboard->window = xcb_generate_id(clipboard->connection);
|
|
192
|
+
uint32_t mask = XCB_EVENT_MASK_PROPERTY_CHANGE;
|
|
193
|
+
xcb_create_window(
|
|
194
|
+
clipboard->connection, XCB_COPY_FROM_PARENT, clipboard->window,
|
|
195
|
+
screens.data->root, 0, 0, 1, 1, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT,
|
|
196
|
+
XCB_COPY_FROM_PARENT, XCB_CW_EVENT_MASK, &mask
|
|
197
|
+
);
|
|
198
|
+
clipboard->clipboard = intern_atom(clipboard, "CLIPBOARD");
|
|
199
|
+
clipboard->property = intern_atom(clipboard, "PI_CLIPBOARD");
|
|
200
|
+
clipboard->targets = intern_atom(clipboard, "TARGETS");
|
|
201
|
+
clipboard->incr = intern_atom(clipboard, "INCR");
|
|
202
|
+
return clipboard->clipboard && clipboard->property && clipboard->targets && clipboard->incr;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
static void close_clipboard(x11_clipboard* clipboard) {
|
|
206
|
+
if (clipboard->connection) xcb_disconnect(clipboard->connection);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
static bool preferred_target(x11_clipboard* clipboard, bool image, xcb_atom_t* target) {
|
|
210
|
+
const char* const* types = image ? image_types : text_types;
|
|
211
|
+
size_t type_count = image ? 6 : 5;
|
|
212
|
+
xcb_atom_t wanted[6];
|
|
213
|
+
for (size_t index = 0; index < type_count; index++) {
|
|
214
|
+
wanted[index] = intern_atom(clipboard, types[index]);
|
|
215
|
+
if (wanted[index] == XCB_NONE) return false;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
property_data targets = {0};
|
|
219
|
+
bool received = request_selection(clipboard, clipboard->targets, &targets);
|
|
220
|
+
bool valid = targets.type == XCB_ATOM_ATOM && targets.format == 32 &&
|
|
221
|
+
targets.items == targets.length / sizeof(xcb_atom_t) && targets.length % sizeof(xcb_atom_t) == 0;
|
|
222
|
+
if (received && valid) {
|
|
223
|
+
xcb_atom_t* offered = (xcb_atom_t*)targets.data;
|
|
224
|
+
for (size_t wanted_index = 0; wanted_index < type_count; wanted_index++) {
|
|
225
|
+
for (uint32_t offered_index = 0; offered_index < targets.items; offered_index++) {
|
|
226
|
+
if (offered[offered_index] == wanted[wanted_index]) {
|
|
227
|
+
free(targets.data);
|
|
228
|
+
*target = wanted[wanted_index];
|
|
229
|
+
return true;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
free(targets.data);
|
|
235
|
+
// Some owners refuse TARGETS but still serve text directly.
|
|
236
|
+
if (received && !image && targets.type == XCB_NONE) {
|
|
237
|
+
*target = intern_atom(clipboard, "UTF8_STRING");
|
|
238
|
+
return *target != XCB_NONE;
|
|
239
|
+
}
|
|
240
|
+
return received && (valid || targets.type == XCB_NONE);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
static bool read_selection(x11_clipboard* clipboard, bool image, property_data* result) {
|
|
244
|
+
xcb_atom_t target = XCB_NONE;
|
|
245
|
+
bool received = preferred_target(clipboard, image, &target) &&
|
|
246
|
+
(target == XCB_NONE || request_selection(clipboard, target, result));
|
|
247
|
+
if (!received) {
|
|
248
|
+
free(result->data);
|
|
249
|
+
memset(result, 0, sizeof(*result));
|
|
250
|
+
}
|
|
251
|
+
return received;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
static void read_clipboard(clipboard_job* job) {
|
|
255
|
+
x11_clipboard clipboard;
|
|
256
|
+
if (open_clipboard(&clipboard)) {
|
|
257
|
+
property_data contents = {0};
|
|
258
|
+
if (!read_selection(&clipboard, job->operation == CLIPBOARD_IMAGE, &contents)) {
|
|
259
|
+
job->error = "Could not read X11 clipboard";
|
|
260
|
+
} else {
|
|
261
|
+
job->data = contents.data;
|
|
262
|
+
job->length = contents.length;
|
|
263
|
+
job->format = !contents.data ? CLIPBOARD_EMPTY : job->operation == CLIPBOARD_IMAGE
|
|
264
|
+
? CLIPBOARD_BUFFER : contents.type == XCB_ATOM_STRING ? CLIPBOARD_LATIN1 : CLIPBOARD_UTF8;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
close_clipboard(&clipboard);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
PI_NAPI_EXPORT napi_value napi_register_module_v1(napi_env env, napi_value exports) {
|
|
271
|
+
set_function_export(env, exports, "getText", get_clipboard_text);
|
|
272
|
+
set_function_export(env, exports, "getImage", get_clipboard_image);
|
|
273
|
+
return exports;
|
|
274
|
+
}
|
|
Binary file
|