mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-23 06:19:32 +01:00
refactor(desktop): move code out of main.rs and setup.rs into modules
Pure moves, no function body changed (git diff --color-moved shows it): - terminal_install.rs: the Terminal and SSH installs (the scripts, the ssh arguments, open_in_terminal, copy_to_clipboard) and their tests, out of setup.rs, which keeps one subject: the Codeman on this Mac. - login.rs: choose_login, update_keychain and their types and tests, out of main.rs. - menu.rs: the menu bar, its ids and AppMenu, out of main.rs. - policy.rs: loaded_on_commit and its test, a pure Phase decision like the rest of policy. What changed besides the moves: module paths, pub on the moved items, imports, the module docs, and the plutil test's temporary folder name, which no longer draws on the Terminal scripts' counter. main.rs goes from 2312 to 1881 lines and setup.rs from 2160 to 1625. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f3087a12c0
commit
db6fb53f5e
7 files changed
+1021
-992
No files matched your search
@@ -61,6 +61,16 @@ impl Phase {
|
||||
}
|
||||
}
|
||||
|
||||
/// The phase a commit of `committed` in the main window moves to: Loaded once
|
||||
/// a page from the server that is loading is the document.
|
||||
pub fn loaded_on_commit(phase: &Phase, committed: &str) -> Option<Phase> {
|
||||
let Phase::Loading(server) = phase else {
|
||||
return None;
|
||||
};
|
||||
let url = Url::parse(committed).ok()?;
|
||||
same_origin(&url, server).then(|| Phase::Loaded(server.clone()))
|
||||
}
|
||||
|
||||
/// Turn what the user typed into a server URL: scheme added when missing,
|
||||
/// query and fragment dropped, and the path ending in `/` so `api/status`
|
||||
/// joins below a base path. The scheme is `https` for a tailnet `.ts.net`
|
||||
@@ -631,7 +641,7 @@ pub enum ConnectCmd {
|
||||
/// Show the agent install that is running already.
|
||||
AgentAttach,
|
||||
/// Run the installer on another machine over SSH, in Terminal. `target`
|
||||
/// is what the user typed; setup::SshTarget::parse checks it.
|
||||
/// is what the user typed; terminal_install::SshTarget::parse checks it.
|
||||
InstallRemote {
|
||||
target: String,
|
||||
},
|
||||
@@ -959,6 +969,32 @@ mod tests {
|
||||
assert!(!Phase::Loaded(srv).connect_page_live());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_commit_from_the_loading_server_is_the_loaded_page() {
|
||||
let server = Url::parse("https://box.ts.net/codeman/").unwrap();
|
||||
let loading = Phase::Loading(server.clone());
|
||||
assert_eq!(
|
||||
loaded_on_commit(&loading, "https://box.ts.net/codeman/"),
|
||||
Some(Phase::Loaded(server.clone()))
|
||||
);
|
||||
// Any page of that origin counts: the server may redirect within it.
|
||||
assert_eq!(
|
||||
loaded_on_commit(&loading, "https://box.ts.net/codeman/session/abc"),
|
||||
Some(Phase::Loaded(server.clone()))
|
||||
);
|
||||
// Another origin, the connect page, or junk: still loading.
|
||||
assert_eq!(loaded_on_commit(&loading, "https://other.ts.net/codeman/"), None);
|
||||
assert_eq!(loaded_on_commit(&loading, "http://box.ts.net/codeman/"), None);
|
||||
assert_eq!(loaded_on_commit(&loading, CONNECT_PAGE), None);
|
||||
assert_eq!(loaded_on_commit(&loading, "not a url"), None);
|
||||
// Only a load under way can finish.
|
||||
assert_eq!(loaded_on_commit(&Phase::Connect, "https://box.ts.net/codeman/"), None);
|
||||
assert_eq!(
|
||||
loaded_on_commit(&Phase::Loaded(server), "https://box.ts.net/codeman/"),
|
||||
None
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn navigation_policy() {
|
||||
let srv = u("http://127.0.0.1:3000/");
|
||||
|
||||
Reference in new issue
Block a user