Skip to content

Commit b1e0679

Browse files
TotallyGamerJetDrakirus
authored and
Drakirus
committed
Fixes Wrong Directory
Fix: gets the directory of the running file instead of the binaries' temp folder as discussed in this: https://stackoverflow.com/questions/18537257/how-to-get-the-directory-of-the-currently-running-file readded path added path back
1 parent 316280e commit b1e0679

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

example/simpleDemo/main.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import (
55
_ "image/png"
66
"log"
77
"os"
8-
"path/filepath"
8+
"path"
9+
"runtime"
910

1011
gutter "github.com/Drakirus/go-flutter-desktop-embedder"
1112

@@ -17,10 +18,8 @@ func main() {
1718
err error
1819
)
1920

20-
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
21-
if err != nil {
22-
log.Fatal(err)
23-
}
21+
_, currentFilePath, _, _ := runtime.Caller(0)
22+
dir := path.Dir(currentFilePath)
2423

2524
options := []gutter.Option{
2625
gutter.OptionAssetPath(dir + "/flutter_project/demo/build/flutter_assets"),
@@ -35,10 +34,8 @@ func main() {
3534
}
3635

3736
func setIcon(window *glfw.Window) error {
38-
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
39-
if err != nil {
40-
return err
41-
}
37+
_, currentFilePath, _, _ := runtime.Caller(0)
38+
dir := path.Dir(currentFilePath)
4239
imgFile, err := os.Open(dir + "/assets/icon.png")
4340
if err != nil {
4441
return err

0 commit comments

Comments
 (0)