Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions lib/common/path.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ class AppPath {
Completer<Directory> tempDir = Completer();
Completer<Directory> cacheDir = Completer();
late String appDirPath;
bool isPortable = false;

AppPath._internal() {
appDirPath = join(dirname(Platform.resolvedExecutable));
getApplicationSupportDirectory().then((value) {
dataDir.complete(value);
});
_initDataDir();
getTemporaryDirectory().then((value) {
tempDir.complete(value);
});
Expand All @@ -29,6 +28,25 @@ class AppPath {
});
}

bool get _isDesktop =>
Platform.isWindows || Platform.isMacOS || Platform.isLinux;

Future<void> _initDataDir() async {
// Portable mode: if a 'config' directory exists next to the executable on
// desktop platforms, use it as the data directory instead of the
// platform-specific application support directory.
if (_isDesktop) {
final portableConfigDir = Directory(join(appDirPath, 'config'));
if (await portableConfigDir.exists()) {
isPortable = true;
dataDir.complete(portableConfigDir);
return;
}
}
final dir = await getApplicationSupportDirectory();
dataDir.complete(dir);
}

factory AppPath() {
_instance ??= AppPath._internal();
return _instance!;
Expand Down