const { invoke, Channel } = window.__TAURI__.core;
export function message(error) {
if (error && typeof error === "object" && typeof error.message === "string") return error.message;
return error instanceof Error ? error.message : String(error);
}
export const api = {
version: () => invoke("app_version"),
profiles: () => invoke("list_profiles"),
createProfile: (name, profile) => invoke("create_profile", { name, profile }),
updateProfile: (name, profile) => invoke("update_profile", { name, profile }),
renameProfile: (oldName, newName) => invoke("rename_profile", { oldName, newName }),
removeProfile: (name) => invoke("remove_profile", { name }),
importPreview: (repository) => invoke("import_profile_preview", { repository }),
chooseFolder: () => invoke("choose_folder"),
chooseKeyFile: () => invoke("choose_key_file"),
roots: () => invoke("list_repository_roots"),
addRoot: (path) => invoke("add_repository_root", { path }),
removeRoot: (path) => invoke("remove_repository_root", { path }),
cancelScan: () => invoke("cancel_repository_scan"),
directoryRules: () => invoke("list_directory_rules"),
addDirectoryRule: (profile, path) => invoke("add_directory_rule", { profile, path }),
removeDirectoryRule: (path) => invoke("remove_directory_rule", { path }),
scan(onEvent) {
const events = new Channel();
events.onmessage = onEvent;
return invoke("scan_repositories", { events });
},
clone: (profile, repository, parent, protocol) =>
invoke("clone_repository", { profile, repository, parent, protocol }),
inspect: (repository, network = false) => invoke("inspect_repository", { repository, network }),
audit: (repository, range, maxCommits = 200) =>
invoke("audit_repository", { repository, range, maxCommits }),
ciStatus: (repository, limit = 5) => invoke("repository_ci_status", { repository, limit }),
bind: (repository, profile, force = false) =>
invoke("bind_repository", { repository, profile, force }),
unbind: (repository) => invoke("unbind_repository", { repository }),
hookState: (repository) => invoke("hook_state", { repository }),
installHooks: (repository) => invoke("install_hooks", { repository }),
uninstallHooks: (repository) => invoke("uninstall_hooks", { repository }),
copyText: (text) => invoke("copy_text", { text }),
openPath: (repository) => invoke("open_path", { repository }),
switchAccount: (profile) => invoke("switch_github_account", { profile }),
accounts: (hostname) => invoke("github_accounts", { hostname }),
testSsh: (profile) => invoke("test_ssh", { profile }),
doctor: () => invoke("doctor"),
demoFixtures: () => invoke("demo_fixtures"),
};