diff --git a/.gitignore b/.gitignore index b69f9e9..8ff5c88 100644 --- a/.gitignore +++ b/.gitignore @@ -22,4 +22,7 @@ go.work # Fyne's packaging files -*.syso \ No newline at end of file +*.syso + +# Signing certificate +sign.txt \ No newline at end of file diff --git a/FyneApp.toml b/FyneApp.toml index 29280cb..b295ffd 100644 --- a/FyneApp.toml +++ b/FyneApp.toml @@ -3,4 +3,4 @@ Name = "Gualto" ID = "com.lostdusty.gualto" Version = "1.0.0" - Build = 11 + Build = 14 diff --git a/go.mod b/go.mod index 8a14987..2d4c6b8 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.21.5 require ( fyne.io/fyne/v2 v2.4.4 - github.com/princessmortix/gobalt v1.0.4 + github.com/lostdusty/gobalt v1.0.5 ) require ( diff --git a/go.sum b/go.sum index 01fc21a..f857a4c 100644 --- a/go.sum +++ b/go.sum @@ -209,6 +209,8 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/lostdusty/gobalt v1.0.5 h1:SdCW+tHDCBaRE/TYs8FPSUwgDLzinRUY5hlw5KC3flA= +github.com/lostdusty/gobalt v1.0.5/go.mod h1:gv+Hmbv0SC3lWpJvUvxJYRmmcuBjlmhKCIRskk0lSjY= github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= @@ -235,8 +237,6 @@ github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= -github.com/princessmortix/gobalt v1.0.4 h1:U6AXr1987W6iOfkKAF4kX4G/XcgoNDJlDiWdI9y+YGs= -github.com/princessmortix/gobalt v1.0.4/go.mod h1:YMW28QoWjxXTY7N67+3H5hIqUDpzsLx4DIJG+I3H9OA= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= diff --git a/main.go b/main.go index 3d10f21..d8c3373 100644 --- a/main.go +++ b/main.go @@ -16,22 +16,36 @@ import ( "fyne.io/fyne/v2/dialog" "fyne.io/fyne/v2/theme" "fyne.io/fyne/v2/widget" - "github.com/princessmortix/gobalt" + "github.com/lostdusty/gobalt" ) var verifyLink = regexp.MustCompile(`[-a-zA-Z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?`) -var count int +var count = 0 var GualtoWin fyne.Window -var onSaveDialog bool +var instancesList []string func main() { - newDownload := gobalt.CreateDefaultSettings() + newDownload := gobalt.CreateDefaultSettings() //Create default settings for downloading gualtoApp := app.NewWithID("com.lostdusty.gualto") GualtoWin = gualtoApp.NewWindow("Gualto") GualtoWin.CenterOnScreen() GualtoWin.Resize(fyne.Size{Width: 800, Height: 400}) + //Async fetches cobalt instances. If it fails, add only the main instance to the list + go func() { + asyncGetCobaltInstances, err := gobalt.GetCobaltInstances() + if err != nil { + dialog.ShowError(fmt.Errorf("failed to fetch more cobalt instances"), GualtoWin) + instancesList = append(instancesList, gobalt.CobaltApi) + return + } + + for _, cobaltInstances := range asyncGetCobaltInstances { + instancesList = append(instancesList, fmt.Sprintf("https://%v", cobaltInstances.URL)) + } + }() + labelMain := widget.NewRichTextFromMarkdown("# Gualto\n\nSave what you love, no extra bullshit. Paste your url below to begin the download.") labelMain.Wrapping = fyne.TextWrapWord @@ -49,7 +63,7 @@ func main() { } }) - checkAccordionSettingTwitter := widget.NewCheck("Convert Twitter gifs", func(b bool) { + checkAccordionSettingTwitter := widget.NewCheck("Don't convert Twitter gifs", func(b bool) { newDownload.ConvertTwitterGifs = b }) checkAccordionSettingTwitter.Checked = true @@ -154,17 +168,24 @@ func main() { info.Show() }) aboutButton.Importance = widget.HighImportance + + //Settings settingsButton := widget.NewButtonWithIcon("settings", theme.SettingsIcon(), func() { storedInstance := gualtoApp.Preferences().StringWithFallback("instance", gobalt.CobaltApi) + checkClipboard := gualtoApp.Preferences().BoolWithFallback("clipboard", true) changeInstancesList := &widget.Select{ Selected: storedInstance, - Options: []string{"https://co.wuk.sh", "https://cobalt-api.hyper.lol", "https://coapi.bigbenster702.com", "https://downloadapi.stuff.solutions", "https://cobalt.api.timelessnesses.me", "https://api-dl.cgm.rs", "https://co-api.mae.wtf", "https://capi.oak.li"}, + Options: instancesList, } changeInstancesLabel := widget.NewLabel("This allows you to use a custom instance.\nOnly change if you know what you are doing!") changeInstancesList.OnChanged = func(s string) { gualtoApp.Preferences().SetString("instance", s) } - settingsDialog := dialog.NewCustom("Gualto App Settings", "Close", container.NewVBox(changeInstancesLabel, changeInstancesList), GualtoWin) + shouldCheckClipboard := widget.NewCheck("Check clipboard for media to download?", func(b bool) { + gualtoApp.Preferences().SetBool("clipboard", b) + }) + shouldCheckClipboard.Checked = checkClipboard + settingsDialog := dialog.NewCustom("Gualto App Settings", "Close", container.NewVBox(changeInstancesLabel, changeInstancesList, widget.NewSeparator(), shouldCheckClipboard), GualtoWin) settingsDialog.Show() }) settingsButton.IconPlacement = widget.ButtonIconTrailingText @@ -175,7 +196,6 @@ func main() { newDownload.Url = pasteURL.Text downloadMedia(newDownload) submitURL.Enable() - } /* CREATE THE FINAL LAYOUT AND DISPLAY */ @@ -186,21 +206,20 @@ func main() { GualtoWin.SetContent(windowContent) gualtoApp.Lifecycle().SetOnEnteredForeground(func() { - if count == 0 || onSaveDialog { - count++ - return - } go func() { - isLink := verifyLink.MatchString(GualtoWin.Clipboard().Content()) - if !isLink { - return - } - downloadClipAsk := dialog.NewConfirm("We found an link!", "Found an url on your clipboard, do you want to paste it?", func(b bool) { - if b { - pasteURL.SetText(GualtoWin.Clipboard().Content()) + if count != 0 || gualtoApp.Preferences().Bool("clipboard") { + isLink := verifyLink.MatchString(GualtoWin.Clipboard().Content()) + if !isLink { + return } - }, GualtoWin) - downloadClipAsk.Show() + downloadClipAsk := dialog.NewConfirm("We found an link!", "Paste URL found on clipboard?", func(b bool) { + if b { + pasteURL.SetText(GualtoWin.Clipboard().Content()) + } + }, GualtoWin) + downloadClipAsk.Show() + count++ + } }() }) @@ -208,7 +227,7 @@ func main() { } func downloadMedia(options gobalt.Settings) { - onSaveDialog = true + count = 0 statusProgressBar := dialog.NewCustomWithoutButtons("Downloading....", widget.NewProgressBarInfinite(), GualtoWin) statusProgressBar.Show() cobaltRequestDownloadFile, err := gobalt.Run(options) @@ -217,7 +236,7 @@ func downloadMedia(options gobalt.Settings) { return } if cobaltRequestDownloadFile.Status == "picker" { - dialog.ShowError(fmt.Errorf("Picker is not supported yet."), GualtoWin) + dialog.ShowError(fmt.Errorf("picker is not supported yet"), GualtoWin) return } @@ -241,10 +260,12 @@ func downloadMedia(options gobalt.Settings) { saveFileDialog := dialog.NewFileSave(func(uc fyne.URIWriteCloser, err error) { if err != nil { + statusProgressBar.Hide() dialog.ShowError(err, GualtoWin) return } if uc == nil { + statusProgressBar.Hide() return } @@ -256,11 +277,10 @@ func downloadMedia(options gobalt.Settings) { } cobaltMediaResponse.Body.Close() statusProgressBar.Hide() - dialog.ShowInformation(fmt.Sprintf("Downloaded %d.2MB of your media!", (fromReqToFile/1000000)), "The download was sucessful.", GualtoWin) + dialog.ShowInformation(fmt.Sprintf("Media (%d.2MB) saved with success!", (fromReqToFile/1000000)), fmt.Sprintf("Saved to %v", uc.URI().Path()), GualtoWin) }, GualtoWin) saveFileDialog.SetFileName(mediaFilename) saveFileDialog.Show() - onSaveDialog = false }