diff --git a/app.go b/app.go index dcaca8d..311d6fc 100644 --- a/app.go +++ b/app.go @@ -2,6 +2,8 @@ package main import ( "context" + "os" + "path/filepath" "github.com/wailsapp/wails/v2/pkg/runtime" ) @@ -90,12 +92,36 @@ func (a *App) GetGamePath() (res StringResponse) { func (a *App) SetGamePath(path string) (res StringResponse) { settings.GamePath = path - SaveSettings(*settings) - res.Data = path + err := SaveSettings(*settings) + if err != nil { + res.Error = err.Error() + } return res } func (a *App) IsGamePathValid() (res BoolResponse) { - res.Data = settings.GamePath != "" + if settings.GamePath == "" { + res.Data = false + return res + } + // Check if the path exists and contains the Interface/AddOns directory + addonPath := filepath.Join(settings.GamePath, "Interface", "AddOns") + if _, err := os.Stat(addonPath); os.IsNotExist(err) { + res.Data = false + return res + } + res.Data = true return res } + +func (a *App) SelectDirectory() (res StringResponse) { + path, err := runtime.OpenDirectoryDialog(a.ctx, runtime.OpenDialogOptions{ + Title: "Select World of Warcraft Directory", + }) + if err != nil { + res.Error = err.Error() + return + } + res.Data = path + return +} diff --git a/frontend/src/lib/components/Header.svelte b/frontend/src/lib/components/Header.svelte index 8771d23..2102502 100644 --- a/frontend/src/lib/components/Header.svelte +++ b/frontend/src/lib/components/Header.svelte @@ -1,17 +1,62 @@ - - - - {name} - - {description} - - - - + + + + + {name} + + + + + + + + {gamePathValid ? "Change Game Path" : "Set Game Path"} + + + + diff --git a/frontend/src/lib/router/routes/Home.svelte b/frontend/src/lib/router/routes/Home.svelte index 3c9c6a4..658394c 100644 --- a/frontend/src/lib/router/routes/Home.svelte +++ b/frontend/src/lib/router/routes/Home.svelte @@ -1,6 +1,6 @@ - - {#each Object.values(addons) as addon} - - {/each} - + {#if gamePathValid} + + {#each Object.values(addons) as addon} + + {/each} + + {:else} + + Game path is not valid + Set Game Path + + {/if} diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts index 2cf0ee5..3bd2573 100644 --- a/frontend/vite.config.ts +++ b/frontend/vite.config.ts @@ -12,6 +12,7 @@ export default defineConfig({ $components: join(__dirname, "src/lib/components"), $router: join(__dirname, "src/lib/router"), $wails: join(__dirname, "wailsjs/go"), + $runtime: join(__dirname, "wailsjs/runtime"), }, }, diff --git a/frontend/wailsjs/go/main/App.d.ts b/frontend/wailsjs/go/main/App.d.ts index 0f37118..78e4f20 100644 --- a/frontend/wailsjs/go/main/App.d.ts +++ b/frontend/wailsjs/go/main/App.d.ts @@ -12,4 +12,12 @@ export function GetAddonRemoteVersion(arg1:string):Promise; export function GetAddons():Promise; +export function GetGamePath():Promise; + +export function IsGamePathValid():Promise; + +export function SelectDirectory():Promise; + +export function SetGamePath(arg1:string):Promise; + export function UpdateAddon(arg1:string):Promise; diff --git a/frontend/wailsjs/go/main/App.js b/frontend/wailsjs/go/main/App.js index ff79d50..a72b1e2 100644 --- a/frontend/wailsjs/go/main/App.js +++ b/frontend/wailsjs/go/main/App.js @@ -22,6 +22,22 @@ export function GetAddons() { return window['go']['main']['App']['GetAddons'](); } +export function GetGamePath() { + return window['go']['main']['App']['GetGamePath'](); +} + +export function IsGamePathValid() { + return window['go']['main']['App']['IsGamePathValid'](); +} + +export function SelectDirectory() { + return window['go']['main']['App']['SelectDirectory'](); +} + +export function SetGamePath(arg1) { + return window['go']['main']['App']['SetGamePath'](arg1); +} + export function UpdateAddon(arg1) { return window['go']['main']['App']['UpdateAddon'](arg1); } diff --git a/frontend/wailsjs/go/models.ts b/frontend/wailsjs/go/models.ts index a84bbbb..0c33111 100644 --- a/frontend/wailsjs/go/models.ts +++ b/frontend/wailsjs/go/models.ts @@ -78,6 +78,20 @@ export namespace main { return a; } } + export class BoolResponse { + data: boolean; + error?: string; + + static createFrom(source: any = {}) { + return new BoolResponse(source); + } + + constructor(source: any = {}) { + if ('string' === typeof source) source = JSON.parse(source); + this.data = source["data"]; + this.error = source["error"]; + } + } export class StringResponse { data: string; error?: string; diff --git a/settings.json b/settings.json index b9340d9..cc97bdd 100644 --- a/settings.json +++ b/settings.json @@ -1 +1 @@ -{"gamePath":"","addons":{"Channeler":{"name":"Channeler","url":"https://git.site.quack-lab.dev/dave/wow_channeler"},"Dechickenator":{"name":"Dechickenator","url":"https://git.site.quack-lab.dev/dave/wow_dechickenator"},"Heimdall":{"name":"Heimdall","url":"https://git.site.quack-lab.dev/dave/wow-Heimdall"}}} +{"gamePath":"C:\\Games\\WoWRuski","addons":{"Channeler":{"name":"Channeler","url":"https://git.site.quack-lab.dev/dave/wow_channeler"},"Dechickenator":{"name":"Dechickenator","url":"https://git.site.quack-lab.dev/dave/wow_dechickenator"},"Heimdall":{"name":"Heimdall","url":"https://git.site.quack-lab.dev/dave/wow-Heimdall"}}}
- {description} -
Game path is not valid