diff --git a/assets/translations/en-US.json b/assets/translations/en-US.json index 8336d7c..22187a3 100644 --- a/assets/translations/en-US.json +++ b/assets/translations/en-US.json @@ -227,5 +227,6 @@ "alias_minutes": "minutes", "n_minute": "{} minutes", "choose": "Choose", - "finish_time_must_be_after_start_time": "Finish time must be after start time" + "finish_time_must_be_after_start_time": "Finish time must be after start time", + "play_sound": "Play sound" } \ No newline at end of file diff --git a/lib/core/util/notification_helper.dart b/lib/core/util/notification_helper.dart index 4ed499e..7a6a4a4 100644 --- a/lib/core/util/notification_helper.dart +++ b/lib/core/util/notification_helper.dart @@ -1,3 +1,5 @@ +import 'package:dipantau_desktop_client/core/util/enum/global_variable.dart'; +import 'package:dipantau_desktop_client/core/util/shared_preferences_manager.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter_local_notifications/flutter_local_notifications.dart'; @@ -18,14 +20,19 @@ class NotificationHelper { } void showScreenshotTakenNotification() { + final presentSound = sharedPreferencesManager.getBool( + SharedPreferencesManager.keyIsEnableSoundScreenshotNotification, + defaultValue: true, + ) ?? + true; localNotification?.show( DateTime.now().millisecond, 'app_name'.tr(), 'screenshot_taken'.tr(), - const NotificationDetails( + NotificationDetails( macOS: DarwinNotificationDetails( presentAlert: true, - presentSound: true, + presentSound: presentSound, ), ), ); diff --git a/lib/core/util/shared_preferences_manager.dart b/lib/core/util/shared_preferences_manager.dart index e047035..3b479c1 100644 --- a/lib/core/util/shared_preferences_manager.dart +++ b/lib/core/util/shared_preferences_manager.dart @@ -23,6 +23,7 @@ class SharedPreferencesManager { static const keyFinishTimeReminderTrack = 'finish_time_reminder_track'; static const keyDayReminderTrack = 'day_reminder_track'; static const keyIntervalReminderTrack = 'interval_reminder_track'; + static const keyIsEnableSoundScreenshotNotification = 'is_enable_sound_screenshot_notification'; SharedPreferencesManager(); diff --git a/lib/feature/presentation/page/home/home_page.dart b/lib/feature/presentation/page/home/home_page.dart index a75cc70..244a4a9 100644 --- a/lib/feature/presentation/page/home/home_page.dart +++ b/lib/feature/presentation/page/home/home_page.dart @@ -99,6 +99,9 @@ class _HomePageState extends State with TrayListener, WindowListener { if (!sharedPreferencesManager.isKeyExists(SharedPreferencesManager.keyIsEnableScreenshotNotification)) { sharedPreferencesManager.putBool(SharedPreferencesManager.keyIsEnableScreenshotNotification, true); } + if (!sharedPreferencesManager.isKeyExists(SharedPreferencesManager.keyIsEnableSoundScreenshotNotification)) { + sharedPreferencesManager.putBool(SharedPreferencesManager.keyIsEnableSoundScreenshotNotification, true); + } initDefaultSelectedProject(); setupWindow(); setupTray(); diff --git a/lib/feature/presentation/page/setting/setting_page.dart b/lib/feature/presentation/page/setting/setting_page.dart index 4c503b8..232fcce 100644 --- a/lib/feature/presentation/page/setting/setting_page.dart +++ b/lib/feature/presentation/page/setting/setting_page.dart @@ -38,6 +38,7 @@ class _SettingPageState extends State { final navigationRailDestinations = []; final sharedPreferencesManager = sl(); final valueNotifierIsEnableScreenshotNotification = ValueNotifier(false); + final valueNotifierIsEnableSoundScreenshotNotification = ValueNotifier(true); final valueNotifierAppearanceMode = ValueNotifier(AppearanceMode.light); final valueNotifierLaunchAtStartup = ValueNotifier(true); final valueNotifierAlwaysOnTop = ValueNotifier(true); @@ -258,6 +259,7 @@ class _SettingPageState extends State { ), children: [ buildWidgetScreenshotNotification(), + buildWidgetPlaySoundScreenshotNotification(), const SizedBox(height: 16), buildWidgetReminderNotTrackNotification(), const SizedBox(height: 8), @@ -686,6 +688,8 @@ class _SettingPageState extends State { void prepareData() { valueNotifierIsEnableScreenshotNotification.value = sharedPreferencesManager.getBool(SharedPreferencesManager.keyIsEnableScreenshotNotification) ?? false; + valueNotifierIsEnableSoundScreenshotNotification.value = + sharedPreferencesManager.getBool(SharedPreferencesManager.keyIsEnableSoundScreenshotNotification) ?? false; valueNotifierAlwaysOnTop.value = sharedPreferencesManager.getBool(SharedPreferencesManager.keyIsAlwaysOnTop, defaultValue: true) ?? true; @@ -1072,6 +1076,37 @@ class _SettingPageState extends State { ); } + Widget buildWidgetPlaySoundScreenshotNotification() { + return Row( + children: [ + SizedBox( + width: 24, + child: ValueListenableBuilder( + valueListenable: valueNotifierIsEnableSoundScreenshotNotification, + builder: (BuildContext context, bool isEnable, _) { + return Checkbox( + value: isEnable, + onChanged: (newValue) { + if (newValue != null) { + valueNotifierIsEnableSoundScreenshotNotification.value = newValue; + sharedPreferencesManager.putBool( + SharedPreferencesManager.keyIsEnableSoundScreenshotNotification, + newValue, + ); + } + }, + ); + }, + ), + ), + const SizedBox(width: 4), + Text( + 'play_sound'.tr(), + ), + ], + ); + } + Widget buildWidgetMember() { return Row( crossAxisAlignment: CrossAxisAlignment.start,