mirror of
https://github.com/taigrr/crocgui
synced 2025-01-18 04:03:16 -08:00
use file save dialog when receive files
This commit is contained in:
parent
9d1a04e586
commit
ac0e3f9aa6
@ -3,12 +3,10 @@
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="com.github.howeyc.crocgui"
|
||||
android:versionCode="6"
|
||||
android:versionName="1.3.0">
|
||||
android:versionCode="7"
|
||||
android:versionName="1.4.0">
|
||||
|
||||
<application android:label="Croc"
|
||||
tools:targetApi="30"
|
||||
>
|
||||
<application android:label="Croc">
|
||||
<activity android:name="org.golang.app.GoNativeActivity"
|
||||
android:label="Croc"
|
||||
android:configChanges="orientation|keyboardHidden">
|
||||
|
6
Makefile
6
Makefile
@ -2,10 +2,10 @@
|
||||
|
||||
all: crocgui.apk crocgui
|
||||
|
||||
crocgui.apk: main.go send.go recv.go settings.go about.go platforms_android.go AndroidManifest.xml
|
||||
ANDROID_HOME=~/android fyne package -os android -appID com.github.howeyc.crocgui -icon metadata/en-US/images/icon.png
|
||||
crocgui.apk: main.go send.go recv.go settings.go about.go AndroidManifest.xml
|
||||
ANDROID_HOME=~/android ./fyne-mobile-save/fyne package -os android -appID com.github.howeyc.crocgui -icon metadata/en-US/images/icon.png
|
||||
|
||||
crocgui: main.go send.go recv.go settings.go about.go platforms-all.go
|
||||
crocgui: main.go send.go recv.go settings.go about.go
|
||||
go build
|
||||
|
||||
clean:
|
||||
|
2
about.go
2
about.go
@ -26,7 +26,7 @@ func aboutTabItem() *container.TabItem {
|
||||
aboutInfo.Wrapping = fyne.TextWrapWord
|
||||
return container.NewTabItemWithIcon("About", theme.InfoIcon(), container.NewBorder(nil,
|
||||
widget.NewForm(
|
||||
widget.NewFormItem("croc GUI", widget.NewHyperlink("v1.3.0", parseURL("https://github.com/howeyc/crocgui"))),
|
||||
widget.NewFormItem("croc GUI", widget.NewHyperlink("v1.4.0", parseURL("https://github.com/howeyc/crocgui"))),
|
||||
widget.NewFormItem("croc", widget.NewHyperlink("v8.6.7", parseURL("https://github.com/schollz/croc"))),
|
||||
),
|
||||
nil,
|
||||
|
@ -13,9 +13,10 @@ export ANDROID_SDK_ROOT=$$SDK$$
|
||||
export ANDROID_NDK_ROOT=$$NDK$$
|
||||
export PATH=$(pwd)/go/bin:$PATH
|
||||
go version
|
||||
./golang/go/bin/go get fyne.io/fyne/v2/cmd/fyne\@v2.0.0
|
||||
./golang/go/bin/go get github.com/fyne-io/mobile\@v0.1.2
|
||||
sed -i '38s/^EGLDisplay/extern EGLDisplay/' ./gopath/pkg/mod/github.com/fyne-io/mobile\@v0.1.2/app/android.go
|
||||
sed -i '39s/^EGLSurface/extern EGLSurface/' ./gopath/pkg/mod/github.com/fyne-io/mobile\@v0.1.2/app/android.go
|
||||
./gopath/bin/fyne package -os android -release -appID com.github.howeyc.crocgui -icon metadata/en-US/images/icon.png
|
||||
curl -Lso fyne-mobile-save.zip https://github.com/howeyc/fyne/archive/mobile-save.zip
|
||||
unzip fyne-mobile-save
|
||||
pushd fyne-mobile-save
|
||||
go build fyne.io/fyne/v2/cmd/fyne
|
||||
popd
|
||||
./fyne-mobile-save/fyne package -os android -release -appID com.github.howeyc.crocgui -icon metadata/en-US/images/icon.png
|
||||
|
||||
|
2
go.mod
2
go.mod
@ -6,3 +6,5 @@ require (
|
||||
fyne.io/fyne/v2 v2.0.0
|
||||
github.com/schollz/croc/v8 v8.6.7
|
||||
)
|
||||
|
||||
replace fyne.io/fyne/v2 => ./fyne-mobile-save
|
||||
|
5
go.sum
5
go.sum
@ -21,6 +21,8 @@ github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWo
|
||||
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
||||
github.com/fyne-io/mobile v0.1.2 h1:0HaXDtOOwyOTn3Umi0uKVCOgJtfX73c6unC4U8i5VZU=
|
||||
github.com/fyne-io/mobile v0.1.2/go.mod h1:/kOrWrZB6sasLbEy2JIvr4arEzQTXBTZGb3Y96yWbHY=
|
||||
github.com/fyne-io/mobile v0.1.3-0.20210312180903-f9a21000f5dc h1:A5hFL3tVUfFHhVpjmLGPs8SdVIcSkTRpFMm1Vsio5+k=
|
||||
github.com/fyne-io/mobile v0.1.3-0.20210312180903-f9a21000f5dc/go.mod h1:/kOrWrZB6sasLbEy2JIvr4arEzQTXBTZGb3Y96yWbHY=
|
||||
github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7 h1:SCYMcCJ89LjRGwEa0tRluNRiMjZHalQZrVrvTbPh+qw=
|
||||
github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7/go.mod h1:482civXOzJJCPzJ4ZOX/pwvXBWSnzD4OKMdH4ClKGbk=
|
||||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200625191551-73d3c3675aa3 h1:q521PfSp5/z6/sD9FZZOWj4d1MLmfQW8PkRnI9M6PCE=
|
||||
@ -39,6 +41,7 @@ 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/lucor/goinfo v0.0.0-20200401173949-526b5363a13a/go.mod h1:ORP3/rB5IsulLEBwQZCJyyV6niqmI7P4EWSmkug+1Ng=
|
||||
github.com/lucor/goinfo v0.0.0-20210209132455-aee5dbc9b821/go.mod h1:ORP3/rB5IsulLEBwQZCJyyV6niqmI7P4EWSmkug+1Ng=
|
||||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
|
||||
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||
@ -84,6 +87,7 @@ github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/tscholl2/siec v0.0.0-20191122224205-8da93652b094 h1:tZWtuLE+LbUwT4OP1oWBSB9zXA8qmQ5qEm4kV9R72oo=
|
||||
github.com/tscholl2/siec v0.0.0-20191122224205-8da93652b094/go.mod h1:KL9+ubr1JZdaKjgAaHr+tCytEncXBa1pR6FjbTsOJnw=
|
||||
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
|
||||
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
@ -136,6 +140,7 @@ gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8
|
||||
gopkg.in/tylerb/is.v1 v1.1.2 h1:AB/MANFml2ySf+adwcinvajyHvsYltAOD+rb/8njfSU=
|
||||
gopkg.in/tylerb/is.v1 v1.1.2/go.mod h1:9yQB2tyIhZ5oph6Kk5Sq7cJMd9c5Jpa1p3hr9kxzPqo=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
4
main.go
4
main.go
@ -13,8 +13,6 @@ import (
|
||||
//go:embed metadata/en-US/images/featureGraphic.png
|
||||
var textlogobytes []byte
|
||||
|
||||
var DEFAULT_DOWNLOAD_DIR string
|
||||
|
||||
func main() {
|
||||
a := app.NewWithID("com.github.howeyc.crocgui")
|
||||
w := a.NewWindow("croc")
|
||||
@ -34,7 +32,7 @@ func main() {
|
||||
w.SetContent(container.NewBorder(top, nil, nil, nil,
|
||||
container.NewAppTabs(
|
||||
sendTabItem(a, w),
|
||||
recvTabItem(a),
|
||||
recvTabItem(a, w),
|
||||
settingsTabItem(a),
|
||||
aboutTabItem(),
|
||||
)))
|
||||
|
1
metadata/en-US/changelogs/7.txt
Normal file
1
metadata/en-US/changelogs/7.txt
Normal file
@ -0,0 +1 @@
|
||||
- Ask user to save files to ensure get writable file path
|
@ -1,16 +0,0 @@
|
||||
// +build !android
|
||||
|
||||
package main
|
||||
|
||||
import "os"
|
||||
|
||||
func init() {
|
||||
wd, werr := os.Getwd()
|
||||
if werr == nil {
|
||||
DEFAULT_DOWNLOAD_DIR = wd
|
||||
}
|
||||
}
|
||||
|
||||
func fixpath(fpath string) string {
|
||||
return fpath
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func init() {
|
||||
// TODO: android probably has a way to find this
|
||||
DEFAULT_DOWNLOAD_DIR = "/storage/emulated/0/Download"
|
||||
}
|
||||
|
||||
func fixpath(fpath string) string {
|
||||
if strings.Contains(fpath, "%3A") {
|
||||
fpath, _ = url.PathUnescape(fpath)
|
||||
colIdx := strings.Index(fpath, ":")
|
||||
fpath = "/storage/emulated/0/" + fpath[colIdx+1:]
|
||||
}
|
||||
|
||||
return fpath
|
||||
}
|
24
recv.go
24
recv.go
@ -9,16 +9,18 @@ import (
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/dialog"
|
||||
"fyne.io/fyne/v2/theme"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
"github.com/schollz/croc/v8/src/croc"
|
||||
)
|
||||
|
||||
func recvTabItem(a fyne.App) *container.TabItem {
|
||||
func recvTabItem(a fyne.App, w fyne.Window) *container.TabItem {
|
||||
status := widget.NewLabel("")
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
@ -104,27 +106,37 @@ func recvTabItem(a fyne.App) *container.TabItem {
|
||||
if len(filesReceived) > 1 {
|
||||
plural = "s"
|
||||
}
|
||||
status.Text = fmt.Sprintf("Received file%s %s", plural, strings.Join(filesReceived, ","))
|
||||
status.SetText(fmt.Sprintf("Received file%s %s", plural, strings.Join(filesReceived, ",")))
|
||||
filepath.Walk(recvDir, func(path string, info fs.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !info.IsDir() {
|
||||
newpath := filepath.Join(DEFAULT_DOWNLOAD_DIR, filepath.Base(path))
|
||||
ofile, oerr := os.Create(newpath)
|
||||
var diagwg sync.WaitGroup
|
||||
diagwg.Add(1)
|
||||
savedialog := dialog.NewFileSave(func(f fyne.URIWriteCloser, e error) {
|
||||
var ofile io.WriteCloser
|
||||
var oerr error
|
||||
ofile = f
|
||||
oerr = e
|
||||
if oerr != nil {
|
||||
status.SetText(oerr.Error())
|
||||
return oerr
|
||||
return
|
||||
}
|
||||
ifile, ierr := os.Open(path)
|
||||
if ierr != nil {
|
||||
status.SetText(ierr.Error())
|
||||
return ierr
|
||||
return
|
||||
}
|
||||
io.Copy(ofile, ifile)
|
||||
ifile.Close()
|
||||
ofile.Close()
|
||||
os.Remove(path)
|
||||
diagwg.Done()
|
||||
}, w)
|
||||
savedialog.SetFileName(filepath.Base(path))
|
||||
savedialog.Show()
|
||||
diagwg.Wait()
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
10
send.go
10
send.go
@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@ -48,15 +49,18 @@ func sendTabItem(a fyne.App, w fyne.Window) *container.TabItem {
|
||||
return
|
||||
}
|
||||
if f != nil {
|
||||
fpath := fixpath(f.URI().Path())
|
||||
nfile, oerr := os.Create(filepath.Join(sendDir, filepath.Base(fpath)))
|
||||
upath, _ := url.PathUnescape(f.URI().Path())
|
||||
if colidx := strings.Index(upath, ":"); colidx != -1 {
|
||||
upath = upath[colidx+1:]
|
||||
}
|
||||
nfile, oerr := os.Create(filepath.Join(sendDir, filepath.Base(upath)))
|
||||
if oerr != nil {
|
||||
status.SetText(fmt.Sprintf("Unable to copy file, error: %s - %s", sendDir, oerr.Error()))
|
||||
return
|
||||
}
|
||||
io.Copy(nfile, f)
|
||||
nfile.Close()
|
||||
fpath = nfile.Name()
|
||||
fpath := nfile.Name()
|
||||
|
||||
_, sterr := os.Stat(fpath)
|
||||
if sterr != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user