Skip to content

Commit

Permalink
library path default on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Sivan22 committed May 20, 2024
1 parent e311cc9 commit 8ef5cfd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
22 changes: 7 additions & 15 deletions lib/data/file_system_data_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,9 @@ class FileSystemData extends Data {
///
/// Returns a `Future` that completes when the initialization is done.
///
init() {
init() async {
//taking care of getting the library path
() async {
//first try to get the library path from settings
libraryPath = Settings.getValue('key-library-path');

//if faild, or the path doesn't conatains 'אוצריא', ask the user to choose the path
while (libraryPath == null ||
(!Directory('$libraryPath${Platform.pathSeparator}אוצריא')
.existsSync())) {
libraryPath = await FilePicker.platform
.getDirectoryPath(dialogTitle: "הגדר את מיקום ספריית אוצריא");
Settings.setValue('key-library-path', libraryPath);
}
}();

await getLibraryPath();
//updating the title to path index
_updateTitleToPath();
//fetching the metadata for the books in the library
Expand All @@ -68,6 +55,11 @@ class FileSystemData extends Data {
String? libraryPath;
Map<String, String> titleToPath = {};

getLibraryPath() async {
//get the library path from settings (as it was initialized in main())
libraryPath = Settings.getValue('key-library-path');
}

///the implementation of the links from app's model, based on the filesystem.
///the links are in the folder 'links' with the name '<book_title>_links.json'
@override
Expand Down
12 changes: 10 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:flutter_settings_screens/flutter_settings_screens.dart';
import 'package:otzaria/data/cache_provider.dart';
import 'package:otzaria/data/hive_data_provider.dart';
import 'package:file_picker/file_picker.dart';
import 'dart:io';

void main() async {
// initializing all the hive components
Expand All @@ -18,10 +19,17 @@ void main() async {
await () async {
//first try to get the library path from settings
String? libraryPath = Settings.getValue('key-library-path');
//on windows, if the path is not set, defaults to C:/אוצריא
if (Platform.isWindows && libraryPath == null) {
libraryPath = 'C:/אוצריא';
Settings.setValue('key-library-path', libraryPath);
}
//if faild, ask the user to choose the path
while (libraryPath == null) {
while (libraryPath == null ||
(!Directory('$libraryPath${Platform.pathSeparator}אוצריא')
.existsSync())) {
libraryPath = await FilePicker.platform
.getDirectoryPath(dialogTitle: "מיקום ספריית אוצריא נדרש");
.getDirectoryPath(dialogTitle: "הגדר את מיקום ספריית אוצריא");
Settings.setValue('key-library-path', libraryPath);
}
}();
Expand Down
4 changes: 2 additions & 2 deletions lib/screens/settings_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ class _MySettingsScreenState extends State<MySettingsScreen> {
settingKey: 'key-padding-size',
defaultValue: 10,
min: 0,
max: 300,
step: 1,
max: 500,
step: 2,
leading: Icon(Icons.horizontal_distribute),
decimalPrecision: 0,
onChange: (p0) => appModel.paddingSize.value = p0,
Expand Down

0 comments on commit 8ef5cfd

Please sign in to comment.