Some refinement
Moved more complex appimage stuff to seperate package (github.com/CalebQ42/GoAppImage) Moved settings to a seperate file for organization Some work to allow asyncronouse app loading (Since goappimage is super slow) Comments to show what's going to be there in the future.
This commit is contained in:
@@ -1,79 +0,0 @@
|
|||||||
package appimg
|
|
||||||
|
|
||||||
// Thanks to probono for the majority of this C code: https://discourse.appimage.org/t/accessing-appimage-desktop-file/173/4?u=calebq42
|
|
||||||
|
|
||||||
/*
|
|
||||||
#cgo CFLAGS: -I/usr/lib
|
|
||||||
#cgo LDFLAGS: -L/usr/lib/libappimage.so -lappimage
|
|
||||||
|
|
||||||
#include <appimage/appimage.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
int char_length(char** in){
|
|
||||||
int i = 0;
|
|
||||||
for (; in[i] != NULL ; i++);
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
import "C"
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
//ErrNotAppImage return if the given location does not point to an AppImage
|
|
||||||
ErrNotAppImage = errors.New("file is not an appimage")
|
|
||||||
)
|
|
||||||
|
|
||||||
//Thanks to https://stackoverflow.com/questions/36188649/cgo-char-to-slice-string for char** to string slice code :)
|
|
||||||
|
|
||||||
//GetDesktopFile tries to find the desktop file inside the appimage at appimageLoc and extract it to extractLoc.
|
|
||||||
//extractLoc is deleted first to provent conflicts.
|
|
||||||
func GetDesktopFile(appimageLoc string, extractLoc string) (*os.File, error) {
|
|
||||||
if !strings.HasSuffix(appimageLoc, ".AppImage") {
|
|
||||||
return nil, ErrNotAppImage
|
|
||||||
}
|
|
||||||
err := os.Remove(extractLoc)
|
|
||||||
if err != os.ErrNotExist {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
cextractLoc := C.CString(extractLoc)
|
|
||||||
defer C.free(unsafe.Pointer(cextractLoc))
|
|
||||||
cloc := C.CString(appimageLoc)
|
|
||||||
defer C.free(unsafe.Pointer(cloc))
|
|
||||||
cfiles := C.appimage_list_files(cloc)
|
|
||||||
defer C.appimage_string_list_free(cfiles)
|
|
||||||
cfilesLength := C.char_length(cfiles)
|
|
||||||
tmpslice := (*[1 << 30]*C.char)(unsafe.Pointer(cfiles))[:cfilesLength:cfilesLength]
|
|
||||||
for _, v := range tmpslice {
|
|
||||||
tmp := C.GoString(v)
|
|
||||||
if strings.HasSuffix(tmp, ".desktop") {
|
|
||||||
C.appimage_extract_file_following_symlinks(cloc, v, cextractLoc)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return os.Open(extractLoc)
|
|
||||||
}
|
|
||||||
|
|
||||||
//ExtractFile tries to extract the file at fileLoc to extractLoc from the appimage at appimageLoc.
|
|
||||||
//extractLoc is deleted first to provent conflicts.
|
|
||||||
func ExtractFile(appimageLoc string, fileLoc string, extractLoc string) (*os.File, error) {
|
|
||||||
if !strings.HasSuffix(appimageLoc, ".AppImage") {
|
|
||||||
return nil, ErrNotAppImage
|
|
||||||
}
|
|
||||||
err := os.Remove(extractLoc)
|
|
||||||
if err != os.ErrNotExist {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
cextractLoc := C.CString(extractLoc)
|
|
||||||
defer C.free(unsafe.Pointer(cextractLoc))
|
|
||||||
cloc := C.CString(appimageLoc)
|
|
||||||
defer C.free(unsafe.Pointer(cloc))
|
|
||||||
cfileLoc := C.CString(fileLoc)
|
|
||||||
defer C.free(unsafe.Pointer(cfileLoc))
|
|
||||||
C.appimage_extract_file_following_symlinks(cloc, cfileLoc, cextractLoc)
|
|
||||||
return os.Open(extractLoc)
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/gob"
|
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
@@ -18,13 +17,8 @@ var (
|
|||||||
linmaster map[string][]app
|
linmaster map[string][]app
|
||||||
cats []string
|
cats []string
|
||||||
lin []string
|
lin []string
|
||||||
wine bool
|
|
||||||
comEnbld bool
|
comEnbld bool
|
||||||
wineAvail bool
|
populated bool
|
||||||
portableHide bool
|
|
||||||
betaUpdate bool
|
|
||||||
versionNewest = true
|
|
||||||
paDirs = true
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -57,63 +51,6 @@ func uiStart(forced bool) {
|
|||||||
gtk.Main()
|
gtk.Main()
|
||||||
}
|
}
|
||||||
|
|
||||||
func savePrefs() {
|
|
||||||
os.Remove("PortableApps/LinuxPACom/Prefs.gob")
|
|
||||||
fil, err := os.Create("PortableApps/LinuxPACom/Prefs.gob")
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
enc := gob.NewEncoder(fil)
|
|
||||||
err = enc.Encode(wine)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
err = enc.Encode(portableHide)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
err = enc.Encode(versionNewest)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
err = enc.Encode(paDirs)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
err = enc.Encode(betaUpdate)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func loadPrefs() {
|
|
||||||
fil, err := os.Open("PortableApps/LinuxPACom/Prefs.gob")
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
dec := gob.NewDecoder(fil)
|
|
||||||
err = dec.Decode(&wine)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
err = dec.Decode(&portableHide)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
err = dec.Decode(&versionNewest)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
err = dec.Decode(&paDirs)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
err = dec.Decode(&betaUpdate)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func contains(arr []string, str string) bool {
|
func contains(arr []string, str string) bool {
|
||||||
for _, v := range arr {
|
for _, v := range arr {
|
||||||
if v == str {
|
if v == str {
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/gob"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
wine bool
|
||||||
|
wineAvail bool
|
||||||
|
portableHide bool
|
||||||
|
betaUpdate bool
|
||||||
|
versionNewest = true
|
||||||
|
paDirs = true
|
||||||
|
)
|
||||||
|
|
||||||
|
func savePrefs() {
|
||||||
|
os.Remove("PortableApps/LinuxPACom/Prefs.gob")
|
||||||
|
fil, err := os.Create("PortableApps/LinuxPACom/Prefs.gob")
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
enc := gob.NewEncoder(fil)
|
||||||
|
err = enc.Encode(wine)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = enc.Encode(portableHide)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = enc.Encode(versionNewest)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = enc.Encode(paDirs)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = enc.Encode(betaUpdate)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func loadPrefs() {
|
||||||
|
fil, err := os.Open("PortableApps/LinuxPACom/Prefs.gob")
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
dec := gob.NewDecoder(fil)
|
||||||
|
err = dec.Decode(&wine)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = dec.Decode(&portableHide)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = dec.Decode(&versionNewest)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = dec.Decode(&paDirs)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = dec.Decode(&betaUpdate)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"encoding/json"
|
||||||
_ "image/png"
|
_ "image/png"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@@ -9,6 +10,7 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/CalebQ42/GoAppImage"
|
||||||
"github.com/gotk3/gotk3/gdk"
|
"github.com/gotk3/gotk3/gdk"
|
||||||
"github.com/gotk3/gotk3/gtk"
|
"github.com/gotk3/gotk3/gtk"
|
||||||
)
|
)
|
||||||
@@ -64,28 +66,12 @@ func setup() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
populated = true
|
||||||
}
|
}
|
||||||
|
|
||||||
func processApp(fold string) (out app) {
|
func processApp(fold string) (out app) {
|
||||||
wd, _ := os.Getwd()
|
wd, _ := os.Getwd()
|
||||||
out.dir = wd + "/" + fold
|
out.dir = wd + "/" + fold
|
||||||
out.ini = findInfo(fold)
|
|
||||||
if out.ini != nil {
|
|
||||||
out.name = getName(out.ini)
|
|
||||||
out.ini = findInfo(fold)
|
|
||||||
out.cat = getCat(out.ini)
|
|
||||||
out.ini = findInfo(fold)
|
|
||||||
}
|
|
||||||
if out.name == "" {
|
|
||||||
out.name = strings.TrimPrefix(fold, "PortableApps/")
|
|
||||||
}
|
|
||||||
if out.cat == "" {
|
|
||||||
out.cat = "Other"
|
|
||||||
}
|
|
||||||
if portableHide {
|
|
||||||
out.name = strings.TrimSuffix(out.name, "Portable")
|
|
||||||
}
|
|
||||||
out.icon = getIcon(fold)
|
|
||||||
folder, _ := os.Open(fold)
|
folder, _ := os.Open(fold)
|
||||||
fis, _ := folder.Readdirnames(-1)
|
fis, _ := folder.Readdirnames(-1)
|
||||||
for _, v := range fis {
|
for _, v := range fis {
|
||||||
@@ -116,6 +102,36 @@ func processApp(fold string) (out app) {
|
|||||||
out.name += " (Wine)"
|
out.name += " (Wine)"
|
||||||
out.wine = true
|
out.wine = true
|
||||||
}
|
}
|
||||||
|
out.icon = getIcon(fold)
|
||||||
|
if len(out.appimg) > 0 {
|
||||||
|
os.Mkdir(out.dir+"/.appimageconfig", 0777)
|
||||||
|
fil, err := os.Open(out.dir + "/.appimageconfig/info.json")
|
||||||
|
if err == os.ErrNotExist {
|
||||||
|
fil, _ = os.Create(out.dir + "/.appimageconfig/info.json")
|
||||||
|
ai := goappimage.NewAppImage(out.dir + "/" + out.appimg[0])
|
||||||
|
ai.ExtractDesktop(out.dir + "/.appimageconfig/the.desktop")
|
||||||
|
//extract desktop and parse info then send to json
|
||||||
|
//also md5 so when updating happens it can update the desktop file
|
||||||
|
ai.Free()
|
||||||
|
} else {
|
||||||
|
//decode json, check if desktop needs to be updated
|
||||||
|
}
|
||||||
|
//Parse extracted desktop file
|
||||||
|
}
|
||||||
|
out.ini = findInfo(fold)
|
||||||
|
if out.ini != nil {
|
||||||
|
out.name = getName(out.ini)
|
||||||
|
out.cat = getCat(out.ini)
|
||||||
|
}
|
||||||
|
if out.name == "" {
|
||||||
|
out.name = strings.TrimPrefix(fold, "PortableApps/")
|
||||||
|
}
|
||||||
|
if out.cat == "" {
|
||||||
|
out.cat = "Other"
|
||||||
|
}
|
||||||
|
if portableHide {
|
||||||
|
out.name = strings.TrimSuffix(out.name, "Portable")
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user