Skip to content

Commit

Permalink
Support passing files ot send through command line arguments
Browse files Browse the repository at this point in the history
Intended for getting #91 working, at least on Linux and BSD, in the future.

Fixes #75
  • Loading branch information
Jacalz committed Jun 28, 2023
1 parent 3827d20 commit 40aacdd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
4 changes: 2 additions & 2 deletions internal/transport/bridge/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import (
func newCodeDisplay(window fyne.Window) *fyne.Container {
codeLabel := &widget.Label{Text: "Waiting for code..."}
copyButton := &widget.Button{Icon: theme.ContentCopyIcon(), Importance: widget.LowImportance}
clipboard := window.Clipboard()

copyButton.OnTapped = func() {
if codeLabel.Text != "Waiting for code..." {
copyButton.SetIcon(theme.ConfirmIcon())
clipboard.SetContent(codeLabel.Text)
window.Clipboard().SetContent(codeLabel.Text)
} else {
copyButton.SetIcon(theme.CancelIcon())
}
Expand Down
2 changes: 1 addition & 1 deletion internal/ui/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (s *send) onCustomCode(enabled bool) {
s.client.CustomCode = enabled
}

func (s *send) onDropped(_ fyne.Position, uris []fyne.URI) {
func (s *send) newTransfer(uris []fyne.URI) {
if len(uris) == 0 {
return
}
Expand Down
23 changes: 21 additions & 2 deletions internal/ui/tabs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
package ui

import (
"os"
"path/filepath"

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/driver/desktop"
"fyne.io/fyne/v2/storage"
"github.com/Jacalz/rymdport/v3/internal/transport"
)

Expand All @@ -22,14 +26,29 @@ func Create(app fyne.App, window fyne.Window) *container.AppTabs {
},
}

window.SetOnDropped(func(pos fyne.Position, uris []fyne.URI) {
window.SetOnDropped(func(_ fyne.Position, uris []fyne.URI) {
if tabs.SelectedIndex() != 0 {
tabs.SelectIndex(0)
}

send.onDropped(pos, uris)
send.newTransfer(uris)
})

if args := os.Args[1:]; len(args) > 0 {
uris := make([]fyne.URI, 0, len(args))
for _, path := range args {
path, err := filepath.Abs(path)
if err != nil {
fyne.LogError("Failed to create absolute path", err)
continue
}

uris = append(uris, storage.NewFileURI(path))
}

send.newTransfer(uris)
}

canvas := window.Canvas()

// Set up support for switching between the tabs.
Expand Down

0 comments on commit 40aacdd

Please sign in to comment.