Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 0 additions & 1 deletion flatpak/com.cypherstack.campfire.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ finish-args:
- --socket=fallback-x11
- --socket=wayland
- --device=dri
- --filesystem=~/.campfire
- --talk-name=org.freedesktop.secrets
- --talk-name=org.freedesktop.Notifications

Expand Down
1 change: 0 additions & 1 deletion flatpak/com.cypherstack.stackduo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ finish-args:
- --socket=fallback-x11
- --socket=wayland
- --device=dri
- --filesystem=~/.stackduo
- --talk-name=org.freedesktop.secrets
- --talk-name=org.freedesktop.Notifications

Expand Down
1 change: 0 additions & 1 deletion flatpak/com.cypherstack.stackwallet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ finish-args:
- --socket=fallback-x11
- --socket=wayland
- --device=dri
- --filesystem=~/.stackwallet
- --talk-name=org.freedesktop.secrets
- --talk-name=org.freedesktop.Notifications

Expand Down
39 changes: 39 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import 'package:google_fonts/google_fonts.dart';
import 'package:keyboard_dismisser/keyboard_dismisser.dart';
import 'package:logger/logger.dart';
import 'package:mobile_app_privacy/mobile_app_privacy.dart';
import 'package:path/path.dart' as path;
import 'package:path_provider/path_provider.dart';
import 'package:window_size/window_size.dart';

Expand Down Expand Up @@ -98,6 +99,44 @@ void main(List<String> args) async {

if (Util.isDesktop && args.length == 2 && args.first == "-d") {
StackFileSystem.setDesktopOverrideDir(args.last);
} else if (Platform.isLinux) {
// Flatpak detection: use XDG_DATA_HOME instead of ~/.stackwallet.
final flatpakId = Platform.environment['FLATPAK_ID'];
if (flatpakId != null || File('/.flatpak-info').existsSync()) {
// Resolve the persistent data root. Prefer XDG_DATA_HOME when set.
// Otherwise fall back to $HOME/.local/share, but only if HOME is
// available. If neither is set we leave the data dir unchanged and
// let StackFileSystem use its default, rather than crashing.
final home = Platform.environment['HOME'];
final xdgDataHome = Platform.environment['XDG_DATA_HOME'] ??
(home != null ? path.join(home, '.local', 'share') : null);

if (xdgDataHome != null) {
final flatpakDataDir =
path.join(xdgDataHome, AppConfig.appDefaultDataDirName);

// Migration: move legacy data from $HOME/.stackwallet into the new
// location, but only when the legacy dir exists and the new one does
// not. Best-effort: never crash if the move fails.
if (home != null) {
final legacyDir = Directory(
path.join(home, '.${AppConfig.appDefaultDataDirName}'),
);
final newDir = Directory(flatpakDataDir);
if (legacyDir.existsSync() && !newDir.existsSync()) {
try {
await Directory(xdgDataHome).create(recursive: true);
await legacyDir.rename(newDir.path);
} catch (_) {
// If rename fails (e.g. different filesystem), fall back to
// using the new path anyway. The user can manually move data.
}
}
}

StackFileSystem.setDesktopOverrideDir(flatpakDataDir);
}
}
Comment on lines +102 to +142

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this breaks setDesktopOverrideDir

}

final loadCoinlibFuture = loadCoinlib();
Expand Down
37 changes: 23 additions & 14 deletions lib/utilities/stack_file_system.dart
Original file line number Diff line number Diff line change
Expand Up @@ -213,23 +213,32 @@ abstract class StackFileSystem {
}
}

final appDocsDir = await getApplicationDocumentsDirectory();
const logsDirName = "${AppConfig.prefix}_Logs";
final Directory logsDir;

if (Platform.isIOS) {
logsDir = Directory(path.join(appDocsDir.path, "logs"));
} else if (Platform.isMacOS || Platform.isLinux || Platform.isWindows) {
// TODO check this is correct for macos
logsDir = Directory(path.join(appDocsDir.path, logsDirName));
} else if (Platform.isAndroid) {
// final dir = await wtfAndroidDocumentsPath();
// final logsDirPath = path.join(dir.path, logsDirName);
// logsDir = Directory(logsDirPath);

logsDir = Directory(path.join(appDocsDir.path, "logs"));
// When a desktop override dir is set (e.g. the Flatpak XDG_DATA_HOME
// location or the -d launch flag) keep logs under that persistent root
// so they follow the data directory rather than landing in the
// application documents directory.
if (_overrideDesktopDirPath != null) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whole file needs different changes.

Although I do agree the logs dir currently has some issues re _overrideDesktopDirPath

logsDir = Directory(path.join(_overrideDesktopDirPath!, "logs"));
} else {
throw Exception("Unsupported Platform");
final appDocsDir = await getApplicationDocumentsDirectory();
const logsDirName = "${AppConfig.prefix}_Logs";

if (Platform.isIOS) {
logsDir = Directory(path.join(appDocsDir.path, "logs"));
} else if (Platform.isMacOS || Platform.isLinux || Platform.isWindows) {
// TODO check this is correct for macos
logsDir = Directory(path.join(appDocsDir.path, logsDirName));
} else if (Platform.isAndroid) {
// final dir = await wtfAndroidDocumentsPath();
// final logsDirPath = path.join(dir.path, logsDirName);
// logsDir = Directory(logsDirPath);

logsDir = Directory(path.join(appDocsDir.path, "logs"));
} else {
throw Exception("Unsupported Platform");
}
}

if (!logsDir.existsSync()) {
Expand Down
Loading