1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-08-02 03:28:28 -04:00

sysupdate: pass custom command to daemon instead of fire and forget from

QML

related #2873

port 1.5
This commit is contained in:
bbedward
2026-07-17 09:46:02 -04:00
parent adbbd9b112
commit 0ffec5011b
7 changed files with 34 additions and 52 deletions
@@ -112,7 +112,7 @@ func (b archHelperBackend) Upgrade(ctx context.Context, opts UpgradeOptions, onL
} }
cmd := strings.Join(archHelperUpgradeArgv(b.id, opts.IncludeAUR, opts.Ignored), " ") cmd := strings.Join(archHelperUpgradeArgv(b.id, opts.IncludeAUR, opts.Ignored), " ")
title := fmt.Sprintf("DMS — System Update (%s)", b.id) title := fmt.Sprintf("DMS — System Update (%s)", b.id)
return Run(ctx, wrapInTerminal(term, title, cmd), RunOptions{OnLine: onLine}) return Run(ctx, wrapInTerminal(term, title, cmd, opts.TerminalArgs), RunOptions{OnLine: onLine})
} }
func archHelperUpgradeArgv(id string, includeAUR bool, ignored []string) []string { func archHelperUpgradeArgv(id string, includeAUR bool, ignored []string) []string {
+14 -13
View File
@@ -119,7 +119,7 @@ func findTerminal(override string) string {
return "" return ""
} }
func wrapInTerminal(term, title, shellCmd string) []string { func wrapInTerminal(term, title, shellCmd string, extraArgs []string) []string {
const appID = "com.danklinux.dms" const appID = "com.danklinux.dms"
banner := fmt.Sprintf( banner := fmt.Sprintf(
`printf '\033[1;36m=== %s ===\033[0m\n'; printf '\033[2m$ %s\033[0m\n'; printf '\033[33mYou may be prompted for your sudo password to apply system updates.\033[0m\n\n'`, `printf '\033[1;36m=== %s ===\033[0m\n'; printf '\033[2m$ %s\033[0m\n'; printf '\033[33mYou may be prompted for your sudo password to apply system updates.\033[0m\n\n'`,
@@ -129,24 +129,25 @@ func wrapInTerminal(term, title, shellCmd string) []string {
export := `export SUDO_PROMPT="[DMS] sudo password for %u: "; ` export := `export SUDO_PROMPT="[DMS] sudo password for %u: "; `
full := export + banner + "; " + shellCmd + "; " + closer full := export + banner + "; " + shellCmd + "; " + closer
var argv []string
execFlag := "-e"
switch term { switch term {
case "kitty": case "kitty", "alacritty", "wezterm":
return []string{term, "--class", appID, "-T", title, "-e", "sh", "-c", full} argv = []string{term, "--class", appID, "-T", title}
case "alacritty":
return []string{term, "--class", appID, "-T", title, "-e", "sh", "-c", full}
case "foot": case "foot":
return []string{term, "--app-id=" + appID, "--title=" + title, "-e", "sh", "-c", full} argv = []string{term, "--app-id=" + appID, "--title=" + title}
case "ghostty": case "ghostty":
return []string{term, "--class=" + appID, "--title=" + title, "-e", "sh", "-c", full} argv = []string{term, "--class=" + appID, "--title=" + title}
case "wezterm":
return []string{term, "--class", appID, "-T", title, "-e", "sh", "-c", full}
case "xterm": case "xterm":
return []string{term, "-class", appID, "-T", title, "-e", "sh", "-c", full} argv = []string{term, "-class", appID, "-T", title}
case "konsole": case "konsole":
return []string{term, "-p", "tabtitle=" + title, "-e", "sh", "-c", full} argv = []string{term, "-p", "tabtitle=" + title}
case "gnome-terminal": case "gnome-terminal":
return []string{term, "--title=" + title, "--", "sh", "-c", full} argv = []string{term, "--title=" + title}
execFlag = "--"
default: default:
return []string{term, "-e", "sh", "-c", full} argv = []string{term}
} }
argv = append(argv, extraArgs...)
return append(argv, execFlag, "sh", "-c", full)
} }
@@ -46,6 +46,7 @@ func handleUpgrade(conn net.Conn, req models.Request, m *Manager) {
DryRun: params.BoolOpt(req.Params, "dry", false), DryRun: params.BoolOpt(req.Params, "dry", false),
CustomCommand: params.StringOpt(req.Params, "customCommand", ""), CustomCommand: params.StringOpt(req.Params, "customCommand", ""),
Terminal: params.StringOpt(req.Params, "terminal", ""), Terminal: params.StringOpt(req.Params, "terminal", ""),
TerminalArgs: stringSliceOpt(req.Params, "terminalArgs"),
Ignored: stringSliceOpt(req.Params, "ignored"), Ignored: stringSliceOpt(req.Params, "ignored"),
} }
if err := m.Upgrade(opts); err != nil { if err := m.Upgrade(opts); err != nil {
+5 -4
View File
@@ -336,7 +336,7 @@ func (m *Manager) runUpgrade(ctx context.Context, opts UpgradeOptions) {
}() }()
if opts.CustomCommand != "" { if opts.CustomCommand != "" {
m.runCustomUpgrade(ctx, opts.CustomCommand, opts.Terminal) m.runCustomUpgrade(ctx, opts)
return return
} }
@@ -389,8 +389,8 @@ func (m *Manager) runUpgrade(ctx context.Context, opts UpgradeOptions) {
m.finishSuccessfulUpgrade(true) m.finishSuccessfulUpgrade(true)
} }
func (m *Manager) runCustomUpgrade(ctx context.Context, command, terminalOverride string) { func (m *Manager) runCustomUpgrade(ctx context.Context, opts UpgradeOptions) {
term := findTerminal(terminalOverride) term := findTerminal(opts.Terminal)
if term == "" { if term == "" {
m.setError(ErrCodeBackendFailed, "no terminal found (pick one in DMS settings, set $TERMINAL, or install kitty/ghostty/foot/alacritty)") m.setError(ErrCodeBackendFailed, "no terminal found (pick one in DMS settings, set $TERMINAL, or install kitty/ghostty/foot/alacritty)")
return return
@@ -407,7 +407,7 @@ func (m *Manager) runCustomUpgrade(ctx context.Context, command, terminalOverrid
m.markDirty() m.markDirty()
onLine := func(line string) { m.appendLog(line) } onLine := func(line string) { m.appendLog(line) }
argv := wrapInTerminal(term, "DMS — System Update (custom)", command) argv := wrapInTerminal(term, "DMS — System Update (custom)", opts.CustomCommand, opts.TerminalArgs)
if err := Run(ctx, argv, RunOptions{OnLine: onLine}); err != nil { if err := Run(ctx, argv, RunOptions{OnLine: onLine}); err != nil {
code := ErrCodeBackendFailed code := ErrCodeBackendFailed
switch { switch {
@@ -425,6 +425,7 @@ func (m *Manager) runCustomUpgrade(ctx context.Context, command, terminalOverrid
} }
m.finishSuccessfulUpgrade(false) m.finishSuccessfulUpgrade(false)
m.runRefresh(context.Background(), false)
} }
func (m *Manager) finishSuccessfulUpgrade(clearPackages bool) { func (m *Manager) finishSuccessfulUpgrade(clearPackages bool) {
+1
View File
@@ -80,6 +80,7 @@ type UpgradeOptions struct {
AttachStdio bool AttachStdio bool
CustomCommand string CustomCommand string
Terminal string Terminal string
TerminalArgs []string
Targets []Package Targets []Package
Ignored []string Ignored []string
} }
@@ -74,7 +74,7 @@ DankPopout {
color: "transparent" color: "transparent"
focus: true focus: true
readonly property bool hasTerminalBackend: (SystemUpdateService.backends || []).some(b => b.runsInTerminal === true) readonly property bool upgradeRunsInTerminal: SystemUpdateService.useCustomCommand || (SystemUpdateService.backends || []).some(b => b.runsInTerminal === true)
property int nowUnix: Math.floor(Date.now() / 1000) property int nowUnix: Math.floor(Date.now() / 1000)
@@ -272,7 +272,7 @@ DankPopout {
includeAUR: SettingsData.updaterAllowAUR, includeAUR: SettingsData.updaterAllowAUR,
terminal: SessionData.terminalOverride terminal: SessionData.terminalOverride
}; };
if (updaterPanel.hasTerminalBackend) { if (updaterPanel.upgradeRunsInTerminal) {
systemUpdatePopout._reopenAfterUpgrade = true; systemUpdatePopout._reopenAfterUpgrade = true;
SystemUpdateService.runUpdates(opts); SystemUpdateService.runUpdates(opts);
systemUpdatePopout.close(); systemUpdatePopout.close();
@@ -478,7 +478,7 @@ DankPopout {
anchors.fill: parent anchors.fill: parent
anchors.margins: Theme.spacingM anchors.margins: Theme.spacingM
spacing: Theme.spacingS spacing: Theme.spacingS
visible: SystemUpdateService.isUpgrading && updaterPanel.hasTerminalBackend visible: SystemUpdateService.isUpgrading && updaterPanel.upgradeRunsInTerminal
DankIcon { DankIcon {
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
@@ -509,7 +509,7 @@ DankPopout {
DankFlickable { DankFlickable {
anchors.fill: parent anchors.fill: parent
anchors.margins: Theme.spacingM anchors.margins: Theme.spacingM
visible: SystemUpdateService.isUpgrading && !updaterPanel.hasTerminalBackend visible: SystemUpdateService.isUpgrading && !updaterPanel.upgradeRunsInTerminal
contentWidth: width contentWidth: width
contentHeight: logText.implicitHeight contentHeight: logText.implicitHeight
clip: true clip: true
+8 -30
View File
@@ -3,7 +3,6 @@ pragma ComponentBehavior: Bound
import QtQuick import QtQuick
import Quickshell import Quickshell
import Quickshell.Io
import qs.Common import qs.Common
import qs.Services import qs.Services
@@ -34,6 +33,7 @@ Singleton {
readonly property int updateCount: availableUpdates.length readonly property int updateCount: availableUpdates.length
readonly property bool helperAvailable: sysupdateAvailable && backends.length > 0 readonly property bool helperAvailable: sysupdateAvailable && backends.length > 0
readonly property bool useCustomCommand: SettingsData.updaterUseCustomCommand && (SettingsData.updaterCustomCommand || "").trim().length > 0
Connections { Connections {
target: DMSService target: DMSService
@@ -183,11 +183,14 @@ Singleton {
function runUpdates(opts) { function runUpdates(opts) {
const params = opts || {}; const params = opts || {};
if (SettingsData.updaterUseCustomCommand && SettingsData.updaterCustomCommand.length > 0) {
_runCustomTerminalCommand();
return;
}
params.ignored = SettingsData.updaterIgnoredPackages || []; params.ignored = SettingsData.updaterIgnoredPackages || [];
if (useCustomCommand) {
params.customCommand = SettingsData.updaterCustomCommand.trim();
const termArgs = (SettingsData.updaterTerminalAdditionalParams || "").trim();
if (termArgs.length > 0) {
params.terminalArgs = termArgs.split(/\s+/);
}
}
DMSService.sysupdateUpgrade(params, null); DMSService.sysupdateUpgrade(params, null);
} }
@@ -199,30 +202,6 @@ Singleton {
DMSService.sysupdateSetInterval(seconds, null); DMSService.sysupdateSetInterval(seconds, null);
} }
function _runCustomTerminalCommand() {
const terminal = SessionData.resolveTerminal();
if (!terminal || terminal.length === 0) {
ToastService.showError(I18n.tr("No terminal configured"), I18n.tr("Pick a terminal in Settings → Launcher (or set $TERMINAL)."));
return;
}
const updateCommand = `${SettingsData.updaterCustomCommand} && echo -n "Updates complete! " ; echo "Press Enter to close..." && read`;
const termClass = SettingsData.updaterTerminalAdditionalParams || "";
var argv = [terminal];
if (termClass.length > 0) {
argv = argv.concat(termClass.split(" "));
}
argv.push("-e");
argv.push("sh");
argv.push("-c");
argv.push(updateCommand);
customRunner.command = argv;
customRunner.running = true;
}
Process {
id: customRunner
}
property bool _startupCheckDone: false property bool _startupCheckDone: false
function _maybeStartupCheck() { function _maybeStartupCheck() {
@@ -262,5 +241,4 @@ Singleton {
} }
DMSService.sysupdateRelease(null); DMSService.sysupdateRelease(null);
} }
} }