diff --git a/app.go b/app.go index 0850c62..323ac50 100644 --- a/app.go +++ b/app.go @@ -4,6 +4,8 @@ import ( "context" "fmt" "yellowjacket/backend" + + "github.com/wailsapp/wails/v2/pkg/runtime" ) // App struct @@ -29,10 +31,20 @@ func (a *App) startup(ctx context.Context) { a.config = conf } -// Greet returns a greeting for the given name -func (a *App) Greet(name string) string { - return fmt.Sprintf("Hello %s, here's your song!", name) -} +// trying to make a function +func (a *App) DirectoryPicker() (string, error) { + dir, err := runtime.OpenDirectoryDialog( + a.ctx, + runtime.OpenDialogOptions{ + ShowHiddenFiles: true, + }) -//trying to make a function -//func (a *App) dirPicker(ctx context.Context, dialogOptions OpenDialogOptions)(string, error){} + if err != nil { + return "", fmt.Errorf("could not open directory dialog\n%w", err) + } + if dir == "" { + return "No Library Directory Selected", nil + } + return fmt.Sprintf("Library Directory: %s", dir), nil + +} diff --git a/frontend/index.html b/frontend/index.html index 944889a..9c2384c 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -6,7 +6,11 @@ yellowjacket -
+
+ + +
+ diff --git a/frontend/src/main.js b/frontend/src/main.js index d51ef8c..c89517e 100644 --- a/frontend/src/main.js +++ b/frontend/src/main.js @@ -1,55 +1,19 @@ import './pico.css'; -import {Greet} from '../wailsjs/go/main/App'; +import { DirectoryPicker } from '../wailsjs/go/main/App'; -document.querySelector('#app').innerHTML = ` -
Please enter your name below 👇
-
- - - - -
- -`; - -let nameElement = document.getElementById("name"); -nameElement.focus(); -let resultElement = document.getElementById("result"); +let libraryDirectoryElement = document.getElementById("library-directory"); -document.getElementById("directory-picker").addEventListener( - "change", - (event) => { - let output = document.getElementById("listing"); - for (const file of event.target.files) { - let item = document.createElement("li"); - item.textContent = file.webkitRelativePath; - output.appendChild(item); - } - }, - false, - ); - - -// Setup the greet function -window.greet = function () { - // Get name - let name = nameElement.value; - - // Check if the input is empty - if (name === "") return; - - // Call App.Greet(name) - try { - Greet(name) - .then((result) => { - // Update result with data back from App.Greet() - resultElement.innerText = result; - }) - .catch((err) => { - console.error(err); - }); - } catch (err) { - console.error(err); - } -}; +window.dirPicker = function () { + var dir; + try { + DirectoryPicker() + .then((result) => {libraryDirectoryElement.innerText = result;}) + .catch((err) => { + console.log("There is an error with directory picker") + console.error(err);}); + } + catch (err) { + console.error(err); + } +} diff --git a/frontend/wailsjs/go/main/App.d.ts b/frontend/wailsjs/go/main/App.d.ts index 02a3bb9..265d33e 100755 --- a/frontend/wailsjs/go/main/App.d.ts +++ b/frontend/wailsjs/go/main/App.d.ts @@ -1,4 +1,4 @@ // Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL // This file is automatically generated. DO NOT EDIT -export function Greet(arg1:string):Promise; +export function DirectoryPicker():Promise; diff --git a/frontend/wailsjs/go/main/App.js b/frontend/wailsjs/go/main/App.js index c71ae77..36071ac 100755 --- a/frontend/wailsjs/go/main/App.js +++ b/frontend/wailsjs/go/main/App.js @@ -2,6 +2,6 @@ // Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL // This file is automatically generated. DO NOT EDIT -export function Greet(arg1) { - return window['go']['main']['App']['Greet'](arg1); +export function DirectoryPicker() { + return window['go']['main']['App']['DirectoryPicker'](); }