JFLib

plat/instance.rs#

Source: lib/plat/instance.rs

instance -- one running instance per app and user (ui: AppDesc AF_SINGLE_INSTANCE): a later
start hands its working folder and arguments to the running instance and ends

  claim(app) -> Claim        Primary: this process is the app's instance; the requests of
                             later starts arrive on a thread of their own (take(); each one
                             calls wake()); Forwarded: the running instance has the request,
                             end this process; Alone: no instance channel (browser, Android,
                             an error): carry on alone
  take() -> Vec<Request>     the requests that arrived, oldest first
  send(app, cwd, args) -> bool    hand a request to the running instance (claim uses it)
  Request { cwd, args }; Request::paths()   the arguments that are no options, as absolute
                             paths (local file:// URIs as paths, other names with a scheme
                             and URLs as they are)

Channel (control_ipc_win.rs / control_ipc_linux.rs): Windows the pipe
\\.\pipe\jfgui-instance-<user SID>-<app> (current user, local clients, one pipe instance:
the first process that creates it is the instance; the starting process lets it take the
foreground); Linux the abstract socket jfgui-instance-<uid>-<app>.  Both ends make sure the
other runs as the same user (Linux: also in the same mount namespace, so a sandboxed process
of the user -- Flatpak, bubblewrap, Firejail -- is refused).  Message: "JFI1", u32 length of
the rest, u32 count, count x
(u32 length, UTF-8): the working folder, then the arguments (without the program), on Linux
then "XAT1", u32 length, the start's $XDG_ACTIVATION_TOKEN when it has one (the running
instance's window comes forward with it on Wayland: linux_wl_act.rs; an instance of an older
version refuses the block, then the request goes again without it); answer "OK".  At most
1 MiB, 3 s per exchange.
  • enum Claim what claim found

    • Primary -- this process is the app's instance
    • Forwarded -- the running instance got this start's request: end the process
    • Alone -- no instance channel here: carry on alone
  • struct Request the command line of a later start

    • cwd: String -- the working folder of the starting process
    • args: Vec<String> -- its arguments, without the program

impl Request

  • fn paths(&self) -> Vec<String> the arguments that are no options ("-..."): relative paths against cwd; local file:// URIs as paths (Linux desktops hand files over that way for %U); other names with a scheme ("config://..", "https://..") as they are

  • fn take() -> Vec<Request> the requests that arrived since the last call, oldest first

  • fn claim(app: &str) -> Claim become the app's single instance, or hand this start's arguments to the running one

  • fn send(app: &str, cwd: &str, args: &[String]) -> bool hand (cwd, args) to the running instance of app -> it confirmed the request

Source: docs/API.md in the JFLib repository.