2023-05-17 20:05:33 +00:00
|
|
|
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
2022-06-09 17:24:02 +00:00
|
|
|
# SPDX-License-Identifier: Unlicense
|
|
|
|
|
2023-05-17 20:05:33 +00:00
|
|
|
import std/[asyncdispatch, sequtils, os]
|
2022-06-09 17:24:02 +00:00
|
|
|
import preserves, syndicate, syndicate/capabilities
|
|
|
|
|
2023-05-18 11:41:37 +00:00
|
|
|
proc unixSocketPath: Unix =
|
|
|
|
result.path = getEnv("SYNDICATE_SOCK")
|
|
|
|
if result.path == "":
|
|
|
|
result.path = getEnv("XDG_RUNTIME_DIR", "/run/user/1000") / "dataspace"
|
2022-06-09 17:24:02 +00:00
|
|
|
|
2023-05-18 17:08:59 +00:00
|
|
|
proc envStep: Preserve[Ref] =
|
|
|
|
var s = getEnv("SYNDICATE_STEP")
|
|
|
|
if s != "": parsePreserves(s, Ref)
|
|
|
|
else: capabilities.mint().toPreserve(Ref)
|
|
|
|
|
2023-05-17 20:05:33 +00:00
|
|
|
proc main =
|
2022-06-09 17:24:02 +00:00
|
|
|
let label = getAppFilename().extractFilename
|
2023-07-01 14:59:18 +00:00
|
|
|
discard bootDataspace(label) do (root: Ref; turn: var Turn):
|
2023-07-26 10:45:41 +00:00
|
|
|
let step = envStep()
|
|
|
|
connect(turn, unixSocketPath(), step) do (turn: var Turn; ds: Ref):
|
2023-05-17 20:05:33 +00:00
|
|
|
message(turn, ds, initRecord(label, map(commandLineParams(), parsePreserves)))
|
2022-06-09 17:24:02 +00:00
|
|
|
|
2023-07-26 10:45:41 +00:00
|
|
|
for _ in 1..4: poll()
|
|
|
|
quit()
|
2023-05-17 20:05:33 +00:00
|
|
|
|
|
|
|
main()
|