Skip to content

Commit

Permalink
Warning modal for low disk space. <10GB produces a warning
Browse files Browse the repository at this point in the history
  • Loading branch information
budak7273 committed Sep 6, 2024
1 parent 0b88eb3 commit af762bf
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
18 changes: 18 additions & 0 deletions backend/settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"path/filepath"

psUtilDisk "github.com/shirou/gopsutil/v3/disk"
"github.com/spf13/viper"
wailsRuntime "github.com/wailsapp/wails/v2/pkg/runtime"

Expand Down Expand Up @@ -328,6 +329,23 @@ func ValidateCacheDir(dir string) error {
return nil
}

// GetCacheDirDiskSpaceLeft returns the amount of disk space left on the cache directory's disk in bytes
func (s *settings) GetCacheDirDiskSpaceLeft() (uint64, error) {
cacheDir := s.GetCacheDir()
err := ValidateCacheDir(cacheDir)

if err != nil {
return 0, fmt.Errorf("cache directory to check space on failed to validate: %w", err)
} else {

Check warning on line 339 in backend/settings/settings.go

View workflow job for this annotation

GitHub Actions / lint-backend (ubuntu-latest)

indent-error-flow: if block ends with a return statement, so drop this else and outdent its block (revive)

Check warning on line 339 in backend/settings/settings.go

View workflow job for this annotation

GitHub Actions / lint-backend (macos-latest)

indent-error-flow: if block ends with a return statement, so drop this else and outdent its block (revive)
usage, err := psUtilDisk.Usage(cacheDir)
if err != nil {
return 0, fmt.Errorf("failed to get disk free space: %w", err)
} else {

Check warning on line 343 in backend/settings/settings.go

View workflow job for this annotation

GitHub Actions / lint-backend (ubuntu-latest)

indent-error-flow: if block ends with a return statement, so drop this else and outdent its block (revive)

Check warning on line 343 in backend/settings/settings.go

View workflow job for this annotation

GitHub Actions / lint-backend (macos-latest)

indent-error-flow: if block ends with a return statement, so drop this else and outdent its block (revive)
return usage.Free, nil
}
}
}

func moveCacheDir(newDir string) error {
if newDir == viper.GetString("cache-dir") {
return nil
Expand Down
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"Maximised",
"Minimised",
"mircearoata",
"noclose",
"Nyan",
"smmanager",
"smmprofile",
Expand Down
22 changes: 17 additions & 5 deletions frontend/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
import { getModalStore, initializeModalStore } from '$lib/skeletonExtensions';
import { installs, invalidInstalls, progress } from '$lib/store/ficsitCLIStore';
import { error, expandedMod, siteURL } from '$lib/store/generalStore';
import { konami, language, updateCheckMode } from '$lib/store/settingsStore';
import { cacheDir, konami, language, updateCheckMode } from '$lib/store/settingsStore';
import { smmUpdate, smmUpdateReady } from '$lib/store/smmUpdateStore';
import { ExpandMod, UnexpandMod } from '$wailsjs/go/app/app';
import { NeedsSmm2Migration } from '$wailsjs/go/migration/migration';
import { GetNewUserSetupComplete } from '$wailsjs/go/settings/settings';
import { Environment, EventsOn, LogError } from '$wailsjs/runtime';
import { GetCacheDirDiskSpaceLeft, GetNewUserSetupComplete } from '$wailsjs/go/settings/settings';
import { Environment, EventsOn } from '$wailsjs/runtime';
initializeStores();
initializeModalStore();
Expand Down Expand Up @@ -142,11 +142,23 @@
meta: {
persistent: true,
},
});
});
}
}
}
cacheDir.subscribe((cacheDirectory) => {
GetCacheDirDiskSpaceLeft().then((spaceLeftBytes) => {
if (spaceLeftBytes < 10e9) {
const spaceLeftGbReadable = (spaceLeftBytes * 1e-9).toFixed(1);
$error = `The drive your cache directory is on (${cacheDirectory}) is very low on disk space (Only ~${spaceLeftGbReadable} GB left). Please free up some space or move the cache directory to another drive in the Mod Manager Settings.`;
}
}).catch((err) => {
$error = `failed to check cache directory disk space left: ${err}`;
});
});
$: if ($smmUpdateReady && $updateCheckMode === 'ask') {
modalStore.trigger({
type: 'component',
Expand Down

0 comments on commit af762bf

Please sign in to comment.