30 lines
868 B
Nim
30 lines
868 B
Nim
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
|
# SPDX-License-Identifier: Unlicense
|
|
|
|
## Facsimile of xdg-open from xdg-utils.
|
|
## https://portland.freedesktop.org/doc/xdg-open.html
|
|
|
|
import std/[asyncdispatch, os]
|
|
import preserves, syndicate, syndicate/capabilities
|
|
import ./protocol
|
|
|
|
proc publishUri(turn: var Turn; ds: Ref) =
|
|
for arg in commandLineParams():
|
|
var xo = XdgOpen(uri: arg)
|
|
if fileExists(xo.uri):
|
|
xo.uri = "file://" & absolutePath(arg)
|
|
message(turn, ds, xo)
|
|
stop(turn)
|
|
|
|
proc unixSocketPath: Unix =
|
|
result.path = getEnv("SYNDICATE_SOCK")
|
|
if result.path == "":
|
|
result.path = getEnv("XDG_RUNTIME_DIR", "/run/user/1000") / "dataspace"
|
|
|
|
discard bootDataspace("xdg-open") do (root: Ref; turn: var Turn):
|
|
let cap = mint().toPreserve(Ref)
|
|
connect(turn, unixSocketPath(), cap, publishUri)
|
|
|
|
for i in 0..4: poll(20)
|
|
# A hack to exit
|