syndicated-open/src/open.nim

28 lines
868 B
Nim
Raw Normal View History

2023-05-18 09:46:17 +00:00
# SPDX-FileCopyrightText: ☭ Emery Hemingway
2022-02-26 23:39:22 +00:00
# SPDX-License-Identifier: Unlicense
import std/[asyncdispatch, os, uri]
2023-05-18 09:46:17 +00:00
import preserves, syndicate, syndicate/capabilities
import ./protocol, ./common
2022-02-26 23:39:22 +00:00
2023-05-18 09:46:17 +00:00
proc publishUri(turn: var Turn; ds: Ref) =
for arg in commandLineParams():
if fileExists(arg):
message(turn, ds, Open(uri: protocol.Uri(
scheme: "file", path: arg.absolutePath.toPreserve)))
else:
message(turn, ds, initRecord("open", arg.parseUri.toPreserve))
2023-05-18 09:46:17 +00:00
stop(turn)
proc unixSocketPath: Unix =
result.path = getEnv("SYNDICATE_SOCK")
if result.path == "":
result.path = getEnv("XDG_RUNTIME_DIR", "/run/user/1000") / "dataspace"
2022-02-26 23:39:22 +00:00
discard bootDataspace("open") do (root: Ref; turn: var Turn):
2023-05-18 09:46:17 +00:00
let cap = mint().toPreserve(Ref)
connect(turn, unixSocketPath(), cap, publishUri)
2022-02-26 23:39:22 +00:00
2023-05-18 09:46:17 +00:00
for i in 0..4: poll(20)
2022-02-26 23:39:22 +00:00
# A hack to exit