Skip to content
This repository has been archived by the owner on Nov 25, 2024. It is now read-only.

Commit

Permalink
Handle cancelling out of selection
Browse files Browse the repository at this point in the history
  • Loading branch information
achhabra2 committed Dec 14, 2021
1 parent 7df9464 commit 35e4917
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 10 deletions.
18 changes: 14 additions & 4 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"errors"
"fmt"
"io"
"log"
Expand Down Expand Up @@ -69,28 +70,37 @@ func (b *App) shutdown(ctx context.Context) {
}

// Greet returns a greeting for the given name
func (b *App) OpenDirectoryDialog() []string {
func (b *App) OpenDirectoryDialog() ([]string, error) {
opts := runtime.OpenDialogOptions{Title: "Select Directory", DefaultDirectory: b.GetDownloadsFolder(), AllowDirectories: true}
selection, err := runtime.OpenDirectoryDialog(b.ctx, opts)
if err != nil {
runtime.LogInfo(b.ctx, "Error opening dialog")
b.ShowErrorDialog(err.Error())
}
runtime.LogInfo(b.ctx, "File Selected:"+selection)
if selection == "" {
runtime.LogError(b.ctx, "No files selected")
return b.selectedFiles, errors.New("invalid selection")
}
b.selectedFiles = []string{selection}
return b.selectedFiles
return b.selectedFiles, nil
}

func (b *App) OpenFilesDialog() []string {
func (b *App) OpenFilesDialog() ([]string, error) {
opts := runtime.OpenDialogOptions{Title: "Select File", AllowFiles: true, DefaultDirectory: b.GetDownloadsFolder()}
selection, err := runtime.OpenMultipleFilesDialog(b.ctx, opts)
if err != nil {
runtime.LogInfo(b.ctx, "Error opening dialog")
b.ShowErrorDialog(err.Error())
}
runtime.LogInfo(b.ctx, "File Selected:")
log.Println(selection)
if len(selection) == 0 {
runtime.LogError(b.ctx, "No files selected")
return b.selectedFiles, errors.New("invalid selection")
}
b.selectedFiles = selection
return b.selectedFiles
return b.selectedFiles, nil
}

func (b *App) SendFile(filePath string) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/dist/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion frontend/dist/bundle.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions frontend/src/sender.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
}
})
.catch((err) => {
// No directory selected
console.log(err);
});
}
Expand All @@ -40,6 +41,7 @@
}
})
.catch((err) => {
// No files selected
console.log(err);
});
}
Expand Down
4 changes: 2 additions & 2 deletions frontend/wailsjs/go/bindings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ interface go {
GetDownloadsFolder():Promise<string>
GetNotificationsParam():Promise<boolean>
GetOverwriteParam():Promise<boolean>
OpenDirectoryDialog():Promise<Array<string>>
OpenDirectoryDialog():Promise<Array<string>|Error>
OpenFile(arg1:string):Promise<void>
OpenFilesDialog():Promise<Array<string>>
OpenFilesDialog():Promise<Array<string>|Error>
ReceiveFile(arg1:string):Promise<void>
SelectedFilesSend():Promise<void>
SendDirectory(arg1:string):Promise<void>
Expand Down
4 changes: 2 additions & 2 deletions frontend/wailsjs/go/bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const go = {
},
/**
* OpenDirectoryDialog
* @returns {Promise<Array<string>>} - Go Type: []string
* @returns {Promise<Array<string>|Error>} - Go Type: []string
*/
"OpenDirectoryDialog": () => {
return window.go.main.App.OpenDirectoryDialog();
Expand All @@ -56,7 +56,7 @@ const go = {
},
/**
* OpenFilesDialog
* @returns {Promise<Array<string>>} - Go Type: []string
* @returns {Promise<Array<string>|Error>} - Go Type: []string
*/
"OpenFilesDialog": () => {
return window.go.main.App.OpenFilesDialog();
Expand Down

0 comments on commit 35e4917

Please sign in to comment.