Skip to content

Commit a2998d0

Browse files
cfsmp3claude
andauthored
fix: Use proper app support directory for config storage (#74)
Move config.json from Documents folder to the proper application support directory (AppData\Roaming on Windows, ~/.local/share on Linux, ~/Library/Application Support on macOS). This fixes the app hanging on startup on Windows 11 25H2 when the Documents folder is inaccessible (OneDrive sync issues, permissions, network redirects, etc.). Changes: - Use getApplicationSupportDirectory() instead of getApplicationDocumentsDirectory() - Add 10-second timeout on directory resolution - Ensure directory exists before writing config - Add try-catch in SettingsBloc to emit error state instead of hanging Fixes: CCExtractor/ccextractor#1936 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent cfaab6c commit a2998d0

2 files changed

Lines changed: 23 additions & 6 deletions

File tree

lib/bloc/settings_bloc/settings_bloc.dart

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,16 @@ class SettingsBloc extends Bloc<SettingsEvent, SettingsState> {
1919

2020
Future<void> _onCheckSettings(
2121
CheckSettingsEvent event, Emitter<SettingsState> emit) async {
22-
bool settingsStatus = await _settingsRepository.checkValidJSON();
23-
if (settingsStatus) {
24-
add(GetSettingsEvent());
25-
} else {
26-
emit(SettingsErrorState("Couldn't parse json file"));
22+
try {
23+
bool settingsStatus = await _settingsRepository.checkValidJSON();
24+
if (settingsStatus) {
25+
add(GetSettingsEvent());
26+
} else {
27+
// Config was invalid but has been rewritten with defaults, load it
28+
add(GetSettingsEvent());
29+
}
30+
} catch (e) {
31+
emit(SettingsErrorState('Failed to initialize settings: $e'));
2732
}
2833
}
2934

lib/repositories/settings_repository.dart

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,24 @@ import 'package:ccxgui/utils/logger.dart';
99

1010
class SettingsRepository {
1111
Future<String> get _localPath async {
12-
final directory = await getApplicationDocumentsDirectory();
12+
// Use application support directory instead of documents directory.
13+
// On Windows this is AppData\Roaming, on macOS ~/Library/Application Support,
14+
// on Linux ~/.local/share. This is the proper location for app config files
15+
// and avoids issues with OneDrive sync, permissions, etc.
16+
final directory = await getApplicationSupportDirectory()
17+
.timeout(const Duration(seconds: 10), onTimeout: () {
18+
throw Exception('Timeout getting application support directory');
19+
});
1320
return directory.path;
1421
}
1522

1623
Future<File> get _localFile async {
1724
final path = await _localPath;
25+
// Ensure directory exists before returning file reference
26+
final dir = Directory(path);
27+
if (!await dir.exists()) {
28+
await dir.create(recursive: true);
29+
}
1830
return File('$path/config.json');
1931
}
2032

0 commit comments

Comments
 (0)