diff --git a/nix-monitor/panel.luau b/nix-monitor/panel.luau index dde6834..2868b48 100644 --- a/nix-monitor/panel.luau +++ b/nix-monitor/panel.luau @@ -119,6 +119,19 @@ local function render() end end + if not cfg("hide_optimize_button") then + table.insert( + buttons, + ui.button({ + text = tr("panel.optimize"), + glyph = "database-cog", + flexGrow = 1, + variant = "primary", + onClick = "onOptimizeClicked", + }) + ) + end + if not cfg("hide_clean_button") then table.insert( buttons, @@ -273,3 +286,18 @@ function onCleanClicked() panel.close() noctalia.runInTerminal(command) end + +function onOptimizeClicked() + local command = cfg("optimize_command") + if command == "" then + noctalia.notifyError(tr("notification.optimize_command_is_empty")) + return + end + + if cfg("close_on_enter") then + command = `{command} && echo && read -p "{tr("terminal.press_enter_to_exit")}"` + end + + panel.close() + noctalia.runInTerminal(command) +end diff --git a/nix-monitor/plugin.toml b/nix-monitor/plugin.toml index 00497cc..be1b726 100644 --- a/nix-monitor/plugin.toml +++ b/nix-monitor/plugin.toml @@ -180,6 +180,13 @@ label_key = "setting.update_command.label" description_key = "setting.update_command.description" default = "" +[[setting]] +key = "optimize_command" +type = "string" +label_key = "setting.optimize_command.label" +description_key = "setting.optimize_command.description" +default = "nix-store --optimise -vv" + [[setting]] key = "clean_command" type = "string" @@ -194,6 +201,13 @@ label_key = "setting.hide_update_button.label" description_key = "setting.hide_update_button.description" default = false +[[setting]] +key = "hide_optimize_button" +type = "bool" +label_key = "setting.hide_optimize_button.label" +description_key = "setting.hide_optimize_button.description" +default = false + [[setting]] key = "hide_clean_button" type = "bool" diff --git a/nix-monitor/translations/en.json b/nix-monitor/translations/en.json index 65cb305..23e9d7e 100644 --- a/nix-monitor/translations/en.json +++ b/nix-monitor/translations/en.json @@ -7,11 +7,13 @@ "notification.update_is_available": "NixOS update is available!", "notification.update_check_completed": "NixOS update check completed!", "notification.update_command_is_empty": "Update command is empty!", + "notification.optimize_command_is_empty": "Optimize command is empty!", "notification.clean_command_is_empty": "Clean command is empty!", "panel.title": "Nix Monitor", "panel.cancel": "Cancel", "panel.update": "Update", "panel.check": "Check", + "panel.optimize": "Optimize", "panel.clean": "Clean", "panel.local": "Local", "panel.remote": "Remote", @@ -50,10 +52,14 @@ "setting.branch.description": "Which nixpkgs branch to use", "setting.update_command.label": "Update command", "setting.update_command.description": "Command to run when clicking Update button", + "setting.optimize_command.label": "Optimize command", + "setting.optimize_command.description": "Command to run when clicking Optimize button", "setting.clean_command.label": "Clean command", "setting.clean_command.description": "Command to run when clicking Clean button", "setting.hide_update_button.label": "Hide update button", "setting.hide_update_button.description": "Whether to hide the update button on the panel", + "setting.hide_optimize_button.label": "Hide optimize button", + "setting.hide_optimize_button.description": "Whether to hide the optimize button on the panel", "setting.hide_clean_button.label": "Hide clean button", "setting.hide_clean_button.description": "Whether to hide the clean button on the panel", "setting.close_on_enter.label": "Close on press Enter",