Skip to content

Commit

Permalink
use temp files
Browse files Browse the repository at this point in the history
  • Loading branch information
howeyc committed Mar 14, 2021
1 parent 5e9d2a1 commit f80c572
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions metadata/en-US/changelogs/6.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- User request of permissions no longer necessary to send files, uses android URI and temp files instead
15 changes: 15 additions & 0 deletions send.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"io"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -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)

Expand All @@ -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()))
Expand All @@ -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)
}
}))
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit f80c572

Please sign in to comment.