From be64aa083faceb3f75f314f4a383b578cdcccca9 Mon Sep 17 00:00:00 2001 From: Caleb Date: Mon, 4 Jun 2018 17:34:15 -0500 Subject: [PATCH] Added beta update support. Started work on further appimage support --- README.md | 6 +++- appimg/CTesting.go | 78 ++++++++++++++++++++++++++++++++++++++++++++++ main.go | 11 ++++++- settings.go | 2 ++ update.go | 47 +++++++++++++++++++--------- 5 files changed, 127 insertions(+), 17 deletions(-) create mode 100644 appimg/CTesting.go diff --git a/README.md b/README.md index 489bdcf..cfea132 100644 --- a/README.md +++ b/README.md @@ -31,5 +31,9 @@ Photos are found [Here](https://goo.gl/photos/VtBUL6DyZTMidj5n6). The screenshot # TODO (Might be in order) 1. MAKE IT BETTER   1. Manual update check   -1. Better appimage support in general +1. Better AppImage integrations (Specifically updating, getting information from the appimage, and better appimage downloading) +1. Automagic appimage updating (It will of course ask you beforehand) +1. Get information (such as name and icon) directly from an appimage +1. Better appimage downloading (probably based around [AppImageHub](https://appimage.github.io/apps/)) +1. Sandboxing support 1. Check if all apps are closed when it closes and ask if you want to force stop the apps diff --git a/appimg/CTesting.go b/appimg/CTesting.go new file mode 100644 index 0000000..b338c2e --- /dev/null +++ b/appimg/CTesting.go @@ -0,0 +1,78 @@ +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 +#cgo pkg-config: glib-2.0 + +#include +#include +#include +#include + +bool extract_desktop(char* appimageLoc,char* extractLoc){ + char** files = appimage_list_files(appimageLoc); + g_autofree gchar *desktop_file = NULL; + gchar *extracted_desktop_file = extractLoc; + int i = 0; + for (; files[i] != NULL ; i++) { + // g_debug("AppImage file: %s", files[i]); + if (g_str_has_suffix (files[i],".desktop")) { + desktop_file = files[i]; + g_debug("AppImage desktop file: %s", desktop_file); + break; + } + } + if(desktop_file == NULL) { + g_debug("AppImage desktop file not found"); + appimage_string_list_free(files); + return FALSE; + } + appimage_extract_file_following_symlinks(appimageLoc, desktop_file,extracted_desktop_file); + appimage_string_list_free(files); + return TRUE; +} + +bool extract_file(char* appimageLoc,char* filename,char* extractLoc){ + char** files = appimage_list_files(appimageLoc); + g_autofree gchar *found_file = NULL; + gchar *extracted_file = extractLoc; + int i = 0; + for (; files[i] != NULL ; i++) { + g_debug("AppImage file: %s", files[i]); + if (strcmp(files[i],filename)==0) { + found_file = files[i]; + g_debug("FileFound: %s", found_file); + } + } + if(found_file == NULL) { + g_debug("filenotfound"); + appimage_string_list_free(files); + return FALSE; + } + appimage_extract_file_following_symlinks(appimageLoc, found_file,extracted_file); + appimage_string_list_free(files); + return TRUE; +} +*/ +import "C" +import ( + "errors" + "os" + "unsafe" +) + +func GetDesktopFile(loc string) (*os.File, error) { + os.Remove("/tmp/my.desktop") + var locTmp *C.char = C.CString(loc) + defer C.free(unsafe.Pointer(locTmp)) + var extractLoc *C.char = C.CString("/tmp/my.desktop") + defer C.free(unsafe.Pointer(extractLoc)) + var out C.bool = C.extract_desktop(locTmp, extractLoc) + if out == false { + return nil, errors.New("Desktop File Not Found!") + } + return os.Open("/tmp/my.desktop") +} diff --git a/main.go b/main.go index a299806..bbe757c 100644 --- a/main.go +++ b/main.go @@ -10,7 +10,7 @@ import ( ) const ( - version = "2.1.2.1" + version = "2.1.4.0" ) var ( @@ -22,6 +22,7 @@ var ( comEnbld bool wineAvail bool portableHide bool + betaUpdate bool versionNewest = true paDirs = true ) @@ -79,6 +80,10 @@ func savePrefs() { if err != nil { return } + err = enc.Encode(betaUpdate) + if err != nil { + return + } } func loadPrefs() { @@ -103,6 +108,10 @@ func loadPrefs() { if err != nil { return } + err = dec.Decode(&betaUpdate) + if err != nil { + return + } } func contains(arr []string, str string) bool { diff --git a/settings.go b/settings.go index 5325726..d1d52bf 100644 --- a/settings.go +++ b/settings.go @@ -93,12 +93,14 @@ func settingsUI(parent *gtk.Window, onExit func()) { paDirsCheck.Connect("toggled", func() { paDirs = paDirsCheck.GetActive() }) + betaCheck, _ := gtk.CheckButtonNewWithLabel("Update to beta releases") gnrl.Add(wineLbl) gnrl.Add(dlWine) gnrl.Add(pthdCheck) gnrl.Add(wineCheck) gnrl.Add(versCheck) gnrl.Add(paDirsCheck) + gnrl.Add(betaCheck) ntbk.AppendPage(gnrl, getLabel("General")) com, _ := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 5) com.SetMarginStart(10) diff --git a/update.go b/update.go index 8c6564e..d980682 100644 --- a/update.go +++ b/update.go @@ -15,9 +15,10 @@ import ( ) const ( - versionURL = "https://www.dropbox.com/s/a0xizzo0a4vsfqt/Version?dl=1" - downloadURL = "https://github.com/CalebQ42/LinuxPA/releases/download/vXXX/LinuxPA" - changelogURL = "https://www.dropbox.com/s/nmbk318er5kej5h/Changelog?dl=1" + versionURL = "https://www.dropbox.com/s/a0xizzo0a4vsfqt/Version?dl=1" + downloadURL = "https://github.com/CalebQ42/LinuxPA/releases/download/vXXX/LinuxPA" + changelogURL = "https://www.dropbox.com/s/nmbk318er5kej5h/Changelog?dl=1" + changelogBetaURL = "https://www.dropbox.com/s/m8mo2o3nsvfqbfx/ChangelogBeta?dl=1" ) //Thanks to https://www.socketloop.com/tutorials/golang-download-file-example @@ -47,14 +48,17 @@ func versionDL() (bool, error) { return true, nil } -func getVersionFileInfo() string { +func getVersionFileInfo() (stable string, beta string) { fil, err := os.Open("PortableApps/LinuxPACom/Version") if err != nil { - return "Error!" + return "Error!", "" } rdr := bufio.NewReader(fil) out, _, _ := rdr.ReadLine() - return string(out) + stable = string(out) + out, _, _ = rdr.ReadLine() + beta = string(out) + return } func changelogDL() (bool, error) { @@ -69,7 +73,12 @@ func changelogDL() (bool, error) { return nil }, } - response, err := check.Get(changelogURL) + var response *http.Response + if betaUpdate { + response, err = check.Get(changelogBetaURL) + } else { + response, err = check.Get(changelogURL) + } if err != nil { return false, err } @@ -89,7 +98,11 @@ func getChangelog() string { return string(out) } -func checkForUpdate(new string) (bool, error) { +func checkForUpdate(stable, beta string) (bool, error) { + new := stable + if betaUpdate { + new = beta + } curSlice := strings.Split(version, ".") newSlice := strings.Split(new, ".") curNums := make([]int, 4) @@ -148,9 +161,9 @@ func downloadUpdate(newVersion string) (bool, error) { func update(win *gtk.Window, forced bool) { stat, err := versionDL() if stat { - res := getVersionFileInfo() - if res != "Error!" { - stat, err = checkForUpdate(res) + stable, beta := getVersionFileInfo() + if stable != "Error!" { + stat, err = checkForUpdate(stable, beta) if stat || forced { stat, err = changelogDL() if stat { @@ -222,11 +235,15 @@ func actuallyUpdate(win *gtk.Window, forced bool) { defer updateWin.Close() stat, err := versionDL() if stat { - res := getVersionFileInfo() - if res != "Error!" { - stat, err = checkForUpdate(res) + stable, beta := getVersionFileInfo() + if stable != "Error!" { + stat, err = checkForUpdate(stable, beta) if stat || forced { - downloadUpdate(res) + if betaUpdate { + downloadUpdate(beta) + } else { + downloadUpdate(stable) + } win.Close() cmd := exec.Command("./LinuxPA") cmd.Stdin = os.Stdin