added directory picker button
This commit is contained in:
@@ -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
|
||||
|
||||
}
|
||||
|
||||
+5
-1
@@ -6,7 +6,11 @@
|
||||
<title>yellowjacket</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<div id="app" class="container">
|
||||
<button class="btn" onclick="dirPicker()">Choose Directory...</button>
|
||||
<label id="library-directory">No Library Directory Selected</label>
|
||||
</div>
|
||||
|
||||
<script src="./src/main.js" type="module"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+15
-51
@@ -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 = `
|
||||
<div class="result" id="result">Please enter your name below 👇</div>
|
||||
<div class="input-box" id="input">
|
||||
<input class="input" id="name" type="text" autocomplete="off" />
|
||||
<button class="btn" onclick="greet()">Greet</button>
|
||||
<input type="file" id="directory-picker" name="fileList" webkitdirectory directory multiple/>
|
||||
<ul id="listing"></ul>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -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<string>;
|
||||
export function DirectoryPicker():Promise<string>;
|
||||
|
||||
@@ -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']();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user