1
0
mirror of https://github.com/taigrr/crocgui synced 2025-01-18 04:03:16 -08:00

use temp files

This commit is contained in:
Chris Howey 2021-03-14 10:36:27 -05:00
parent 5e9d2a114b
commit f80c572905
3 changed files with 18 additions and 2 deletions

View File

@ -3,8 +3,8 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.github.howeyc.crocgui"
android:versionCode="5"
android:versionName="1.2.0">
android:versionCode="6"
android:versionName="1.3.0">
<application android:label="Croc"
tools:targetApi="30"

View File

@ -0,0 +1 @@
- User request of permissions no longer necessary to send files, uses android URI and temp files instead

15
send.go
View File

@ -2,6 +2,7 @@ package main
import (
"fmt"
"io"
"log"
"os"
"path/filepath"
@ -36,6 +37,8 @@ func sendTabItem(a fyne.App, w fyne.Window) *container.TabItem {
})
copyCodeButton.Hide()
sendDir, _ := os.MkdirTemp("", "crocgui")
boxholder := container.NewVBox()
fileentries := make(map[string]*fyne.Container)
@ -46,6 +49,15 @@ func sendTabItem(a fyne.App, w fyne.Window) *container.TabItem {
}
if f != nil {
fpath := fixpath(f.URI().Path())
nfile, oerr := os.Create(filepath.Join(sendDir, filepath.Base(fpath)))
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()
_, sterr := os.Stat(fpath)
if sterr != nil {
status.SetText(fmt.Sprintf("Stat error: %s - %s", fpath, sterr.Error()))
@ -55,6 +67,7 @@ func sendTabItem(a fyne.App, w fyne.Window) *container.TabItem {
newentry := container.NewHBox(labelFile, layout.NewSpacer(), widget.NewButtonWithIcon("", theme.CancelIcon(), func() {
if fe, ok := fileentries[fpath]; ok {
boxholder.Remove(fe)
os.Remove(fpath)
delete(fileentries, fpath)
}
}))
@ -130,9 +143,11 @@ func sendTabItem(a fyne.App, w fyne.Window) *container.TabItem {
for _, fpath := range filepaths {
if fe, ok := fileentries[fpath]; ok {
boxholder.Remove(fe)
os.Remove(fpath)
delete(fileentries, fpath)
}
}
topline.SetText("Pick a file to send")
addFileButton.Show()
if serr != nil {