Skip to content

Commit

Permalink
Fixed deletion bug
Browse files Browse the repository at this point in the history
  • Loading branch information
mawilms committed Jan 10, 2024
1 parent fec9fae commit 4c2436b
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 15 deletions.
15 changes: 12 additions & 3 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,20 @@ type App struct {
}

func NewApp() *App {
s, _ := settings.New()
datastore, _ := models.NewDatastore(s.DataDirectory)

loggerHandler := slog.NewTextHandler(os.Stdout, nil)
logger := slog.New(loggerHandler)

s, err := settings.New()
if err != nil {
logger.Error("Error while initializing settings", slog.String("err", err.Error()))
os.Exit(1)
}

datastore, err := models.NewDatastore(s.DataDirectory)
if err != nil {
logger.Error("Error while initializing datastore", slog.String("err", err.Error()))
os.Exit(1)
}
process := processes.Process{Logger: logger}

return &App{logger: logger, settings: s, datastore: datastore, process: process}
Expand Down
26 changes: 23 additions & 3 deletions frontend/src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@
import type { entities } from '$lib/wailsjs/go/models';
import { ToggleState } from './interactions';
import PluginRow from './PluginRow.svelte';
// export let data;
// TODO: Add state for plugins loading and no plugins found
enum Status {
Loading = 1,
Loaded
}
let amountPlugins = 0;
let error = '';
let status = Status.Loading;
$: plugins = [];
$: if (plugins != null) {
Expand All @@ -20,7 +27,10 @@
}
GetInstalledPlugins()
.then((result) => plugins = result);
.then((result) => {
status = Status.Loaded;
plugins = result;
});
async function getInstalledPlugins() {
const installedPlugins = await GetInstalledPlugins();
Expand Down Expand Up @@ -97,7 +107,17 @@

<ul id="plugin-list" class="space-y-2 h-full overflow-y-scroll">
{#if plugins === null}
<p class="text-center text-gold">Loading plugins from the data store</p>
{#if status === Status.Loading}
<p class="text-center text-gold">Loading plugins from the data store</p>
{:else}
<p class="text-center text-gold">No plugins found</p>
{/if}
{:else if plugins.length === 0}
{#if status === Status.Loading}
<p class="text-center text-gold">Loading plugins from the data store</p>
{:else}
<p class="text-center text-gold">No plugins found</p>
{/if}
{:else if plugins.length !== 0}
{#each plugins as plugin, index}
<PluginRow index={index} plugin={plugin} toggle={toggle} deletePlugin={deletePlugin} />
Expand Down
6 changes: 5 additions & 1 deletion internal/processes/processes.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,12 @@ func (p Process) DeletePlugin(datastore models.DatastoreInterface, name, author,
plugin := pluginDatastore[id]

err = internal.DeletePlugin(plugin, pluginDirectory)
if err == nil {
if err != nil {
p.Logger.Error("failed to delete plugin", slog.String("name", name), slog.String("author", author), slog.String("error", err.Error()))
return plugins, err
}

if err == nil {
err = datastore.DeleteById(id)
if err != nil {
p.Logger.Error("failed to delete entry from datastore", slog.String("id", id))
Expand Down
28 changes: 20 additions & 8 deletions internal/settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package settings

import (
"encoding/json"
"fmt"
"os"
"path/filepath"
)
Expand All @@ -13,16 +14,25 @@ type Settings struct {
}

func New() (Settings, error) {
pluginDirectory, _ := findPluginDirectory()
dataDirectory, _ := findDataDirectory()
pluginDirectory, err := findPluginDirectory()
if err != nil {
return Settings{}, err
}
dataDirectory, err := findDataDirectory()
if err != nil {
return Settings{}, err
}

fmt.Println(pluginDirectory)
fmt.Println(dataDirectory)

settings := Settings{
PluginDirectory: pluginDirectory,
DataDirectory: dataDirectory,
InfoUrl: "https://api.lotrointerface.com/fav/plugincompendium.xml",
}

_, err := os.Stat(filepath.Join(dataDirectory, "settings.json"))
_, err = os.Stat(filepath.Join(dataDirectory, "settings.json"))
if err != nil {
err := settings.Store()
if err != nil {
Expand Down Expand Up @@ -78,12 +88,14 @@ func findPluginDirectory() (string, error) {
return "", err
}

lotroDirectory := ""
_, err = os.Stat(filepath.Join(homeDir, "Documents", "The Lord of the Rings Online", "Plugins"))
if err == nil {
lotroDirectory = filepath.Join(homeDir, "Documents", "The Lord of the Rings Online", "Plugins")
lotroDirectory := filepath.Join(homeDir, "Documents", "The Lord of the Rings Online", "Plugins")
_, err = os.Stat(lotroDirectory)
if err != nil {
err := os.MkdirAll(lotroDirectory, os.ModePerm)
if err != nil {
return lotroDirectory, err
}
}

// TODO: Check for steam folder

return lotroDirectory, nil
Expand Down

0 comments on commit 4c2436b

Please sign in to comment.