Add syndicate_webextension_native_messager
This commit is contained in:
parent
3a0bd1cd02
commit
fb78a3d3d2
|
@ -425,6 +425,8 @@ Example
|
||||||
$ FS=':' syndump '<Observe ? _>' | awk -F : '/^+/ { print $2 }'
|
$ FS=':' syndump '<Observe ? _>' | awk -F : '/^+/ { print $2 }'
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Webextenstion Native Messager
|
||||||
|
|
||||||
## XSLT processor
|
## XSLT processor
|
||||||
|
|
||||||
Perform XML stylesheet transformations. For a given textual XSLT stylesheet and a textual XML document generate an abstract XML document in Preserves form. Inputs may be XML text or paths to XML files.
|
Perform XML stylesheet transformations. For a given textual XSLT stylesheet and a textual XML document generate an abstract XML document in Preserves form. Inputs may be XML text or paths to XML files.
|
||||||
|
|
12
default.nix
12
default.nix
|
@ -31,4 +31,16 @@ buildNimPackage {
|
||||||
];
|
];
|
||||||
|
|
||||||
lockFile = ./lock.json;
|
lockFile = ./lock.json;
|
||||||
|
|
||||||
|
postInstall = ''
|
||||||
|
substituteInPlace syndicate_native_messager.json \
|
||||||
|
--replace '@path@' $out/bin/syndicate_webextension_native_messager
|
||||||
|
|
||||||
|
install -D -t \
|
||||||
|
$out/etc/chromium/native-messaging-hosts \
|
||||||
|
syndicate_webextension_native_messager.json
|
||||||
|
install -D -t \
|
||||||
|
$out/lib/mozilla/native-messaging-hosts \
|
||||||
|
syndicate_webextension_native_messager.json
|
||||||
|
'';
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,67 @@
|
||||||
|
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
||||||
|
# SPDX-License-Identifier: Unlicense
|
||||||
|
|
||||||
|
## A "native application" for messaging with browser WebExtensions.
|
||||||
|
##
|
||||||
|
## https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Native_messaging
|
||||||
|
##
|
||||||
|
|
||||||
|
import
|
||||||
|
std/[sequtils, streams, os, oserrors, posix, strutils],
|
||||||
|
preserves,
|
||||||
|
pkg/sys/[files, handles, ioqueue],
|
||||||
|
syndicate, syndicate/relays,
|
||||||
|
./schema/json_messages
|
||||||
|
|
||||||
|
proc openAsync(file: syncio.File): AsyncFile =
|
||||||
|
let
|
||||||
|
fd = file.getOsFileHandle
|
||||||
|
flags = fcntl(fd.cint, F_GETFL, 0)
|
||||||
|
if flags < 0: raiseOSError(osLastError())
|
||||||
|
if fcntl(fd.cint, F_SETFL, flags or O_NONBLOCK) < 0:
|
||||||
|
raiseOSError(osLastError())
|
||||||
|
newAsyncFile(FD fd)
|
||||||
|
|
||||||
|
proc inputLoop(app: Cap) {.asyncio.} =
|
||||||
|
## Loop over stdin.
|
||||||
|
let
|
||||||
|
input = stdin.openAsync
|
||||||
|
buf = new(ref string) # are we safe yet?
|
||||||
|
while true:
|
||||||
|
var n: uint32
|
||||||
|
if input.read(cast[ptr UncheckedArray[byte]](n.addr), 4) != 4: break
|
||||||
|
buf[].setLen(n)
|
||||||
|
if input.read(buf) != n.int: break
|
||||||
|
proc recvJson(turn: Turn) =
|
||||||
|
var pr = initRecord("recv", buf[].parsePreserves)
|
||||||
|
message(turn, app, pr)
|
||||||
|
app.relay.run(recvJson)
|
||||||
|
quit()
|
||||||
|
|
||||||
|
runActor("app") do (turn: Turn):
|
||||||
|
let
|
||||||
|
app = turn.newDataspace()
|
||||||
|
buf = newStringStream()
|
||||||
|
|
||||||
|
onMessage(turn, app, ?:SendJson) do (data: Value):
|
||||||
|
# Grab <send …> records and write them to stdout.
|
||||||
|
buf.setPosition 0
|
||||||
|
buf.writeText(data, textJson)
|
||||||
|
buf.data.setLen buf.getPosition
|
||||||
|
var n = buf.data.len.uint32
|
||||||
|
discard stdout.writeBuffer(n.addr, 4)
|
||||||
|
stdout.write buf.data
|
||||||
|
stdout.flushFile()
|
||||||
|
|
||||||
|
resolveEnvironment(turn) do (turn: Turn; remote: Cap):
|
||||||
|
# Publish the "app" dataspace in a record built from the command line.
|
||||||
|
var pr = Value(kind: pkRecord)
|
||||||
|
pr.record.add app.embed
|
||||||
|
for f in commandLineParams():
|
||||||
|
pr.record.add f.toPreserves
|
||||||
|
pr.record.add "webextension".toSymbol
|
||||||
|
publish(turn, remote, pr)
|
||||||
|
|
||||||
|
discard trampoline:
|
||||||
|
# start a thread of continuations
|
||||||
|
whelp inputLoop(app)
|
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"name": "syndicate",
|
||||||
|
"description": "Native messaging Syndicate proxy",
|
||||||
|
"path": "@path@",
|
||||||
|
"type": "stdio",
|
||||||
|
"allowed_extensions": [
|
||||||
|
"syndicate_webextension_native_messager@syndicate-lang.org"
|
||||||
|
]
|
||||||
|
}
|
|
@ -1,12 +1,11 @@
|
||||||
# Package
|
# Package
|
||||||
|
|
||||||
version = "20240509"
|
version = "20240510"
|
||||||
author = "Emery Hemingway"
|
author = "Emery Hemingway"
|
||||||
description = "Utilites for Syndicated Actors and Synit"
|
description = "Utilites for Syndicated Actors and Synit"
|
||||||
license = "unlicense"
|
license = "unlicense"
|
||||||
srcDir = "src"
|
srcDir = "src"
|
||||||
bin = @["http_client", "mintsturdyref", "mount_actor", "msg", "postgre_actor", "preserve_process_environment", "rofi_script_actor", "sqlite_actor", "syndesizer", "syndump", "xslt_actor"]
|
bin = @["http_client", "mintsturdyref", "mount_actor", "msg", "postgre_actor", "preserve_process_environment", "rofi_script_actor", "sqlite_actor", "syndesizer", "syndicate_webextension_native_messager", "syndump", "xslt_actor"]
|
||||||
|
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"name": "syndicate",
|
||||||
|
"description": "Native messaging Syndicate proxy",
|
||||||
|
"path": "@path@",
|
||||||
|
"type": "stdio",
|
||||||
|
"allowed_extensions": [
|
||||||
|
"syndicate_webextension_native_messager@syndicate-lang.org"
|
||||||
|
]
|
||||||
|
}
|
Loading…
Reference in New Issue