Files
oxpoe d6f6c69c5a Label jenis aplikasi dengan auto-detect (Go/AppImage/Electron/Script/Windows/Binary/PWA)
- internal/shortcut/kind.go: deteksi dari isi berkas - build info Go, magic
  AppImage, resources/*.asar untuk Electron, shebang untuk script, MZ untuk .exe
- .exe Windows kini boleh dipasang dan dijalankan lewat wine (Exec=wine <path>);
  kalau wine tidak terpasang, install ditolak dengan pesan jelas
- metadata menyimpan kind; chip jenis ditampilkan di setiap baris shortcut
  (data lama tetap tampil sebagai Executable/PWA)
- dialog menampilkan hasil deteksi setelah berkas dipilih, mis. 'winbox.exe - windows'
- README: bagian label otomatis + screenshot baru
2026-10-13 08:21:38 +07:00

70 lines
1.7 KiB
Go

package shortcut
import (
"bytes"
"debug/buildinfo"
"os"
"path/filepath"
)
// Jenis aplikasi yang bisa dikenali LazyRun.
const (
KindGo = "go"
KindAppImage = "appimage"
KindElectron = "electron"
KindScript = "script"
KindWindows = "windows"
KindBinary = "binary"
KindPWA = "pwa"
)
// DetectKind menebak jenis berkas yang dipilih user:
// binary Go, AppImage, aplikasi Electron, script, .exe Windows, atau binary biasa.
func DetectKind(path string) string {
f, err := os.Open(path)
if err != nil {
return ""
}
head := make([]byte, 12)
n, _ := f.Read(head)
f.Close()
head = head[:n]
switch {
case bytes.HasPrefix(head, []byte("MZ")):
return KindWindows
case bytes.HasPrefix(head, []byte("#!")):
return KindScript
case isAppImageHead(head):
return KindAppImage
case bytes.HasPrefix(head, []byte{0x7f, 'E', 'L', 'F'}):
if _, err := buildinfo.ReadFile(path); err == nil {
return KindGo
}
if hasElectronResources(path) {
return KindElectron
}
return KindBinary
}
return ""
}
// hasElectronResources mencari berkas penanda Electron di sebelah binary.
func hasElectronResources(path string) bool {
resources := filepath.Join(filepath.Dir(path), "resources")
for _, name := range []string{"app.asar", "default_app.asar", "app"} {
if _, err := os.Stat(filepath.Join(resources, name)); err == nil {
return true
}
}
return false
}
// isAppImageHead memeriksa magic AppImage (ELF + "AI" pada offset 8).
// Sengaja terpisah dari internal/update supaya paket ini tidak tergantung ke sana.
func isAppImageHead(head []byte) bool {
return len(head) >= 11 &&
head[0] == 0x7f && head[1] == 'E' && head[2] == 'L' && head[3] == 'F' &&
head[8] == 'A' && head[9] == 'I' && (head[10] == 0x01 || head[10] == 0x02)
}