syndicated-open/src/xdg_open.nim

29 lines
827 B
Nim
Raw Normal View History

# SPDX-FileCopyrightText: ☭ 2022 Emery Hemingway
2022-02-26 23:39:22 +00:00
# SPDX-License-Identifier: Unlicense
import std/[asyncdispatch, os]
from std/sequtils import map
2022-02-26 23:39:22 +00:00
import syndicate, syndicate/capabilities
import ./protocol
proc unixSocketPath: string =
result = getEnv("SYNDICATE_SOCK")
if result == "":
result = getEnv("XDG_RUNTIME_DIR", "/run/user/1000") / "dataspace"
proc mintCap: SturdyRef =
var key: array[16, byte]
mint(key, "syndicate")
2022-04-23 23:32:43 +00:00
bootDataspace("main") do (root: Ref; turn: var Turn):
connectUnix(turn, unixSocketPath(), mintCap()) do (turn: var Turn; ds: Ref):
var uris = commandLineParams().map do (param: string) -> string:
if fileExists param:
"file://" & absolutePath(param)
else:
param
message(turn, ds, XdgOpen(uris: uris))
2022-02-26 23:39:22 +00:00
for i in 0..7: poll(20)
# A hack to exit