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,
40 Quit,
42}
43
44impl DeeplinkCommand {
45 pub const SCHEME: &str = "openlogi";
47
48 #[must_use]
50 pub const fn as_name(self) -> &'static str {
51 match self {
52 Self::Show => "show",
53 Self::OpenSettings => "open-settings",
54 Self::OpenAbout => "open-about",
55 Self::CheckForUpdates => "check-for-updates",
56 Self::Quit => "quit",
57 }
58 }
59
60 #[must_use]
62 pub fn to_url(self) -> String {
63 format!("{}://{}", Self::SCHEME, self.as_name())
64 }
65
66 #[must_use]
68 pub fn from_name(name: &str) -> Option<Self> {
69 match name {
70 "show" => Some(Self::Show),
71 "open-settings" => Some(Self::OpenSettings),
72 "open-about" => Some(Self::OpenAbout),
73 "check-for-updates" => Some(Self::CheckForUpdates),
74 "quit" => Some(Self::Quit),
75 _ => None,
76 }
77 }
78
79 #[must_use]
84 pub fn parse_url(url: &str) -> Option<Self> {
85 let rest = url.strip_prefix(Self::SCHEME)?.strip_prefix("://")?;
86 let name = rest.split(['/', '?']).next().unwrap_or(rest);
87 Self::from_name(name)
88 }
89}
90
91#[cfg(test)]
92mod tests {
93 use super::DeeplinkCommand;
94
95 const ALL: [DeeplinkCommand; 5] = [
96 DeeplinkCommand::Show,
97 DeeplinkCommand::OpenSettings,
98 DeeplinkCommand::OpenAbout,
99 DeeplinkCommand::CheckForUpdates,
100 DeeplinkCommand::Quit,
101 ];
102
103 #[test]
104 fn url_round_trips() {
105 for cmd in ALL {
106 assert_eq!(DeeplinkCommand::parse_url(&cmd.to_url()), Some(cmd));
107 }
108 }
109
110 #[test]
111 fn parse_url_ignores_trailing_path_and_query() {
112 assert_eq!(
113 DeeplinkCommand::parse_url("openlogi://show/"),
114 Some(DeeplinkCommand::Show)
115 );
116 assert_eq!(
117 DeeplinkCommand::parse_url("openlogi://open-settings?from=tray"),
118 Some(DeeplinkCommand::OpenSettings)
119 );
120 }
121
122 #[test]
123 fn parse_url_rejects_foreign_scheme_and_unknown_command() {
124 assert_eq!(DeeplinkCommand::parse_url("https://example.com/show"), None);
125 assert_eq!(DeeplinkCommand::parse_url("openlogi://bogus"), None);
126 assert_eq!(DeeplinkCommand::parse_url("openlogi://"), None);
127 }
128}