From 8ef5cfd3a8ec76c6c47b7e9f79bda7dc34989e1a Mon Sep 17 00:00:00 2001 From: sivan22 Date: Mon, 20 May 2024 06:53:27 +0300 Subject: [PATCH] library path default on windows --- lib/data/file_system_data_provider.dart | 22 +++++++--------------- lib/main.dart | 12 ++++++++++-- lib/screens/settings_screen.dart | 4 ++-- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/data/file_system_data_provider.dart b/lib/data/file_system_data_provider.dart index 833cf98ea..7d78345ba 100644 --- a/lib/data/file_system_data_provider.dart +++ b/lib/data/file_system_data_provider.dart @@ -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 @@ -68,6 +55,11 @@ class FileSystemData extends Data { String? libraryPath; Map 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 '_links.json' @override diff --git a/lib/main.dart b/lib/main.dart index c6f9983b2..f68daa382 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -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 @@ -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); } }(); diff --git a/lib/screens/settings_screen.dart b/lib/screens/settings_screen.dart index 1658cf0b3..f0c29aea2 100644 --- a/lib/screens/settings_screen.dart +++ b/lib/screens/settings_screen.dart @@ -121,8 +121,8 @@ class _MySettingsScreenState extends State { 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,