mitsuami_core/services/reopen.rs
1//! Later launches of a single-instance app, handed to the running one.
2
3use std::path::{Path, PathBuf};
4
5/// A launch of a single-instance app (`App::single_instance`) while it's
6/// already running: the platform or the second process hands it to the
7/// first, and [`on_reopen`](super::on_reopen) handlers get it there.
8/// What's in it is what the platform passes on: macOS gives no arguments
9/// or folder to a running app, and Windows no folder.
10#[derive(Clone, Debug, Default, PartialEq, Eq)]
11pub struct Reopen {
12 args: Vec<String>,
13 cwd: Option<PathBuf>,
14 files: Vec<PathBuf>,
15}
16
17impl Reopen {
18 /// What backends (and tests) hand the core: the launch's arguments
19 /// without the program, its working folder, and the files the platform
20 /// opened the app with.
21 pub fn new(args: Vec<String>, cwd: Option<PathBuf>, files: Vec<PathBuf>) -> Reopen {
22 Reopen { args, cwd, files }
23 }
24
25 /// The arguments the app was launched with, without `argv[0]`. Empty
26 /// for a launch from the platform's shell (macOS's Dock and Finder).
27 pub fn args(&self) -> &[String] {
28 &self.args
29 }
30
31 /// The folder the launch ran in, to resolve relative paths in
32 /// [`args`](Self::args) against, where the platform passes it on.
33 pub fn cwd(&self) -> Option<&Path> {
34 self.cwd.as_deref()
35 }
36
37 /// Files the platform opened the app with: Finder's Open With on macOS,
38 /// a D-Bus activated `.desktop` file's `%F` on Linux. A plain launch
39 /// passes paths as arguments instead.
40 pub fn files(&self) -> &[PathBuf] {
41 &self.files
42 }
43}