Tombol Run menghormati Terminal=true (gio launch) + wrapper pakai script asli
- launch lewat 'gio launch <file .desktop>' kalau tersedia: Terminal=true membuka terminal, Path= dihormati, sama seperti menu desktop (script yang butuh sudo atau input sekarang bisa jalan dari tombol Run) - wrapper script memakai berkas script asli kalau masih ada, jadi dirname $0 menunjuk folder aslinya (laporan/hasil tidak nyasar ke ~/.local/bin); salinan .real tetap jadi cadangan - tes: pemilihan perintah launch, wrapper memakai script asli + PATH
This commit is contained in:
1 parent
581cd07dba
commit
35e83dba09
7 files changed
+150
-18
No files matched your search
+30
-11
@@ -1,7 +1,9 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/url"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
||||
"fyne.io/fyne/v2"
|
||||
@@ -27,18 +29,15 @@ func (ui *app) openURL(raw string) {
|
||||
}
|
||||
}
|
||||
|
||||
// launch menjalankan shortcut: pakai argv hasil install, fallback ke binary/URL.
|
||||
// launch menjalankan shortcut.
|
||||
//
|
||||
// Kalau ada, `gio launch <file .desktop>` dipakai supaya aturannya sama dengan
|
||||
// menu desktop: Terminal=true membuka jendela terminal (script yang butuh sudo
|
||||
// atau input bisa jalan) dan Path= ikut dihormati.
|
||||
func (ui *app) launch(sc store.Shortcut) {
|
||||
args := sc.ExecArgs
|
||||
if len(args) == 0 {
|
||||
switch {
|
||||
case sc.Type == store.TypeWebApp && sc.URL != "":
|
||||
args = []string{"xdg-open", sc.URL}
|
||||
case sc.BinaryPath != "":
|
||||
args = []string{sc.BinaryPath}
|
||||
}
|
||||
}
|
||||
if len(args) == 0 {
|
||||
args, err := launchCommand(sc)
|
||||
if err != nil {
|
||||
dialog.ShowError(err, ui.win)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -49,3 +48,23 @@ func (ui *app) launch(sc store.Shortcut) {
|
||||
}
|
||||
go cmd.Wait() // supaya proses anak tidak jadi zombie
|
||||
}
|
||||
|
||||
// launchCommand menyusun perintah untuk menjalankan shortcut.
|
||||
func launchCommand(sc store.Shortcut) ([]string, error) {
|
||||
if sc.DesktopPath != "" {
|
||||
if gio, err := exec.LookPath("gio"); err == nil {
|
||||
if _, err := os.Stat(sc.DesktopPath); err == nil {
|
||||
return []string{gio, "launch", sc.DesktopPath}, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
switch {
|
||||
case len(sc.ExecArgs) > 0:
|
||||
return sc.ExecArgs, nil
|
||||
case sc.Type == store.TypeWebApp && sc.URL != "":
|
||||
return []string{"xdg-open", sc.URL}, nil
|
||||
case sc.BinaryPath != "":
|
||||
return []string{sc.BinaryPath}, nil
|
||||
}
|
||||
return nil, errors.New("shortcut ini tidak punya perintah yang bisa dijalankan")
|
||||
}
|
||||
Reference in new issue
Block a user