{"record":{"id":"897cc11a28ff958c","repo":"tonhowtf/omniget","slug":"este-item-so-pode-ser-alterado-com-privilegios-de","errorCode":null,"errorMessage":"este item so pode ser alterado com privilegios de administrador","messagePattern":"este item so pode ser alterado com privilegios de administrador","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/startup.rs","lineNumber":558,"sourceCode":"}\n\n// ── API ────────────────────────────────────────────────────────────────\n\npub async fn list() -> Vec<StartupItem> {\n    let mut items = if cfg!(target_os = \"macos\") {\n        mac_items().await\n    } else if cfg!(target_os = \"windows\") {\n        win_items().await\n    } else {\n        linux_items().await\n    };\n    items.sort_by_key(|a| a.name.to_lowercase());\n    items\n}\n\npub async fn set_enabled(item: &StartupItem, enabled: bool) -> anyhow::Result<()> {\n    if !item.can_toggle {\n        return Err(anyhow!(\n            \"este item so pode ser alterado com privilegios de administrador\"\n        ));\n    }\n    if cfg!(target_os = \"macos\") {\n        mac_set(item, enabled).await\n    } else if cfg!(target_os = \"windows\") {\n        win_set(item, enabled).await\n    } else {\n        linux_set(item, enabled).await\n    }\n}\n\n#[cfg(test)]\nmod tests {\n    use super::*;\n\n    #[test]\n    fn desktop() {","sourceCodeStart":540,"sourceCodeEnd":576,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/startup.rs#L540-L576","documentation":"`set_enabled` (startup.rs, public API) refuses to modify any StartupItem whose `can_toggle` flag is false. `can_toggle` is set to false during `list()` for items that live in privileged locations (e.g. system-wide autostart directories, root-owned LaunchAgents, HKLM registry entries) which the current user lacks permission to modify. The message says the item can only be changed with administrator privileges.","triggerScenarios":"Calling `startup::set_enabled(&item, enabled)` for any item returned by `startup::list()` with `item.can_toggle == false` — regardless of OS (the check runs before the platform dispatch).","commonSituations":"Toggling system-wide autostart .desktop files on Linux (/etc/xdg/autostart), root-owned LaunchDaemons on macOS, or machine-wide Windows startup entries while running as a non-elevated user.","solutions":["Check `item.can_toggle` before calling `set_enabled` and skip/alert for non-togglable items (the UI should already disable the switch).","Re-run the application with elevated privileges (sudo / Run as administrator) so privileged items can be modified — note `can_toggle` is computed per-user, so elevation may require re-listing.","Modify the underlying entry manually with admin rights (edit /etc/xdg/autostart/*.desktop, LaunchDaemons plist, or HKLM Run key).","If the item should be user-togglable, copy it into the user-level autostart location and toggle that copy instead."],"exampleFix":"// before\nfor item in startup::list().await {\n    startup::set_enabled(&item, should_enable(&item)).await?;\n}\n\n// after\nfor item in startup::list().await {\n    if !item.can_toggle {\n        eprintln!(\"{} requer privilegios de administrador; ignorado\", item.name);\n        continue;\n    }\n    startup::set_enabled(&item, should_enable(&item)).await?;\n}","handlingStrategy":"validation","validationCode":"if !item.can_toggle {\n    eprintln!(\"{}: requer privilegios de administrador\", item.name);\n    return Ok(()); // or prompt for elevation\n}\nstartup::set_enabled(&item, enabled).await?;","typeGuard":"fn togglable(item: &StartupItem) -> bool { item.can_toggle }","tryCatchPattern":"match startup::set_enabled(&item, enabled).await {\n    Err(e) if e.to_string().contains(\"privilegios de administrador\") => {\n        // relaunch with elevation or show \"run as admin\" hint\n    }\n    r => { r?; }\n}","preventionTips":["Always gate the UI toggle on item.can_toggle returned by list()","Re-run list() after elevating privileges; can_toggle is computed per-user","Document that system-wide startup entries need admin rights to toggle"],"tags":["permissions","privileges","startup-items","cross-platform"],"backgroundTag":"insufficient-permissions","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}