1pub const REPO_URL: &str = "https://github.com/AprilNEA/OpenLogi";
12pub const HELP_URL: &str = "https://github.com/AprilNEA/OpenLogi#readme";
14pub const RELEASES_URL: &str = "https://github.com/AprilNEA/OpenLogi/releases/latest";
16
17#[must_use]
19pub fn release_tag_url(version: &str) -> String {
20 format!("{REPO_URL}/releases/tag/v{version}")
21}
22
23#[derive(Clone, Copy, Debug, Eq, PartialEq)]
31pub enum DeeplinkCommand {
32 Show,
34 OpenSettings,
36 OpenAbout,
38 CheckForUpdates,
41 Quit,
43}
44
45impl DeeplinkCommand {
46 pub const SCHEME: &str = "openlogi";
48
49 #[must_use]
51 pub const fn as_name(self) -> &'static str {
52 match self {
53 Self::Show => "show",
54 Self::OpenSettings => "open-settings",
55 Self::OpenAbout => "open-about",
56 Self::CheckForUpdates => "check-for-updates",
57 Self::Quit => "quit",
58 }
59 }
60
61 #[must_use]
63 pub fn to_url(self) -> String {
64 format!("{}://{}", Self::SCHEME, self.as_name())
65 }
66
67 #[must_use]
69 pub fn from_name(name: &str) -> Option<Self> {
70 match name {
71 "show" => Some(Self::Show),
72 "open-settings" => Some(Self::OpenSettings),
73 "open-about" => Some(Self::OpenAbout),
74 "check-for-updates" => Some(Self::CheckForUpdates),
75 "quit" => Some(Self::Quit),
76 _ => None,
77 }
78 }
79
80 #[must_use]
85 pub fn parse_url(url: &str) -> Option<Self> {
86 let rest = url.strip_prefix(Self::SCHEME)?.strip_prefix("://")?;
87 let name = rest.split(['/', '?']).next().unwrap_or(rest);
88 Self::from_name(name)
89 }
90}
91
92#[cfg(test)]
93mod tests {
94 use super::DeeplinkCommand;
95
96 const ALL: [DeeplinkCommand; 5] = [
97 DeeplinkCommand::Show,
98 DeeplinkCommand::OpenSettings,
99 DeeplinkCommand::OpenAbout,
100 DeeplinkCommand::CheckForUpdates,
101 DeeplinkCommand::Quit,
102 ];
103
104 #[test]
105 fn url_round_trips() {
106 for cmd in ALL {
107 assert_eq!(DeeplinkCommand::parse_url(&cmd.to_url()), Some(cmd));
108 }
109 }
110
111 #[test]
112 fn parse_url_ignores_trailing_path_and_query() {
113 assert_eq!(
114 DeeplinkCommand::parse_url("openlogi://show/"),
115 Some(DeeplinkCommand::Show)
116 );
117 assert_eq!(
118 DeeplinkCommand::parse_url("openlogi://open-settings?from=tray"),
119 Some(DeeplinkCommand::OpenSettings)
120 );
121 }
122
123 #[test]
124 fn parse_url_rejects_foreign_scheme_and_unknown_command() {
125 assert_eq!(DeeplinkCommand::parse_url("https://example.com/show"), None);
126 assert_eq!(DeeplinkCommand::parse_url("openlogi://bogus"), None);
127 assert_eq!(DeeplinkCommand::parse_url("openlogi://"), None);
128 }
129}