Skip to content

Commit

Permalink
Merge pull request #138 from vicolo-dev/hotfix-update-crash
Browse files Browse the repository at this point in the history
Fix crash on updating to 0.3.2
  • Loading branch information
AhsanSarwar45 authored Mar 27, 2024
2 parents fef3164 + c1eb54d commit 89f2ef2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 13 deletions.
18 changes: 18 additions & 0 deletions lib/common/utils/list_storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'dart:io';
import 'package:clock_app/common/data/paths.dart';
import 'package:clock_app/common/types/json.dart';
import 'package:clock_app/common/utils/json_serialize.dart';
import 'package:get_storage/get_storage.dart';
import 'package:path/path.dart' as path;
import 'package:path/path.dart';
import 'package:queue/queue.dart';
Expand Down Expand Up @@ -57,6 +58,23 @@ Future<void> saveList<T extends JsonSerializable>(
await saveTextFile(key, listToString(list));
}

Future<void> initList<T extends JsonSerializable>(
String key, List<T> value) async {
await initTextFile(key, listToString(value));
}

Future<void> initTextFile(String key, String value) async {
if (GetStorage().read('init_$key') == null) {
GetStorage().write('init_$key', true);
try {
loadTextFileSync(key);
} catch (e) {
print("Initializing $key");
await saveTextFile(key, value);
}
}
}

Future<void> saveTextFile(String key, String content) async {
await queue.add(() async {
String appDataDirectory = getAppDataDirectoryPathSync();
Expand Down
35 changes: 22 additions & 13 deletions lib/settings/logic/initialize_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import 'dart:io';

import 'package:clock_app/alarm/types/alarm.dart';
import 'package:clock_app/audio/logic/system_ringtones.dart';
import 'package:clock_app/clock/data/default_favorite_cities.dart';
import 'package:clock_app/clock/logic/initialize_default_favorite_cities.dart';
import 'package:clock_app/clock/types/city.dart';
import 'package:clock_app/common/data/paths.dart';
import 'package:clock_app/common/types/file_item.dart';
import 'package:clock_app/common/utils/list_storage.dart';
Expand All @@ -12,8 +14,10 @@ import 'package:clock_app/theme/data/default_color_schemes.dart';
import 'package:clock_app/theme/data/default_style_themes.dart';
import 'package:clock_app/theme/types/color_scheme.dart';
import 'package:clock_app/theme/types/style_theme.dart';
import 'package:clock_app/timer/data/default_timer_presets.dart';
import 'package:clock_app/timer/logic/initialize_default_timer_presets.dart';
import 'package:clock_app/timer/types/timer.dart';
import 'package:clock_app/timer/types/timer_preset.dart';
import 'package:flutter/foundation.dart';
import 'package:get_storage/get_storage.dart';

Expand Down Expand Up @@ -48,16 +52,25 @@ Future<void> initializeStorage() async {
GetStorage().write('first_alarm_created', false);
GetStorage().write('first_timer_created', false);

initializeDefaultFavoriteCities();
initializeDefaultTimerPresets();
initializeDefaultAlarms();
await saveList<ClockTimer>('timers', []);
await saveList<FileItem>('ringtones', await getSystemRingtones());
await saveList<ClockStopwatch>('stopwatches', [ClockStopwatch()]);
await saveList<ColorSchemeData>('color_schemes', defaultColorSchemes);
await saveList<StyleTheme>('style_themes', defaultStyleThemes);
await saveTextFile("time_format_string", "h:mm a");
// initializeDefaultFavoriteCities();
// initializeDefaultTimerPresets();
// await saveList<ClockTimer>('timers', []);
// await saveList<FileItem>('ringtones', await getSystemRingtones());
// await saveList<ClockStopwatch>('stopwatches', [ClockStopwatch()]);
// await saveList<ColorSchemeData>('color_schemes', defaultColorSchemes);
// await saveList<StyleTheme>('style_themes', defaultStyleThemes);
// await saveTextFile("time_format_string", "h:mm a");
}

await initList<Alarm>("alarms", []);
await initList<ClockTimer>('timers', []);
await initList<City>('favorite_cities', initialFavoriteCities);
await initList<ClockStopwatch>('stopwatches', [ClockStopwatch()]);
await initList<ColorSchemeData>('color_schemes', defaultColorSchemes);
await initList<StyleTheme>('style_themes', defaultStyleThemes);
await initList<TimerPreset>("timer_presets", defaultTimerPresets);
await initList<FileItem>("ringtones", await getSystemRingtones());
await initTextFile("time_format_string", "h:mm a");
}

Future<void> initializeSettings() async {
Expand All @@ -70,7 +83,3 @@ Future<void> initializeSettings() async {

appSettings.load();
}

void initializeDefaultAlarms() {
saveList<Alarm>('alarms', []);
}
1 change: 1 addition & 0 deletions lib/timer/logic/initialize_default_timer_presets.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:clock_app/common/utils/list_storage.dart';
import 'package:clock_app/timer/data/default_timer_presets.dart';


void initializeDefaultTimerPresets() {
saveList('timer_presets', defaultTimerPresets);
}

0 comments on commit 89f2ef2

Please sign in to comment.