From f1ea1397d76f2446fe15be6cc72acae80797792f Mon Sep 17 00:00:00 2001 From: poppingmoon <63451158+poppingmoon@users.noreply.github.com> Date: Mon, 22 Apr 2024 07:41:12 +0900 Subject: [PATCH] feat: disable data saver when on Wi-Fi Add an option to disable data saver depending on whether the device is connected via Wi-Fi or not. --- lib/i18n/aria/aria.i18n.yaml | 1 + lib/i18n/aria/aria_ja-JP.i18n.yaml | 1 + lib/i18n/aria/aria_ja-KS.i18n.yaml | 1 + lib/i18n/strings.g.dart | 2 +- lib/i18n/strings_en_US.g.dart | 1 + lib/i18n/strings_ja_JP.g.dart | 1 + lib/i18n/strings_ja_KS.g.dart | 1 + lib/model/general_settings.dart | 1 + lib/model/general_settings.freezed.dart | 32 ++++++++++++++++--- lib/model/general_settings.g.dart | 3 ++ lib/provider/connectivity_provider.dart | 9 ++++++ lib/provider/connectivity_provider.g.dart | 24 ++++++++++++++ .../general_settings_notifier_provider.dart | 8 +++++ .../general_settings_notifier_provider.g.dart | 2 +- lib/view/page/settings/appearance_page.dart | 7 ++++ lib/view/widget/media_card.dart | 21 +++++++++--- lib/view/widget/url_preview.dart | 20 +++++++++--- macos/Flutter/GeneratedPluginRegistrant.swift | 2 ++ pubspec.lock | 24 ++++++++++++++ pubspec.yaml | 1 + .../flutter/generated_plugin_registrant.cc | 3 ++ windows/flutter/generated_plugins.cmake | 1 + 22 files changed, 151 insertions(+), 15 deletions(-) create mode 100644 lib/provider/connectivity_provider.dart create mode 100644 lib/provider/connectivity_provider.g.dart diff --git a/lib/i18n/aria/aria.i18n.yaml b/lib/i18n/aria/aria.i18n.yaml index d5a6a1694..1cce2cb70 100644 --- a/lib/i18n/aria/aria.i18n.yaml +++ b/lib/i18n/aria/aria.i18n.yaml @@ -16,6 +16,7 @@ deleteFilesConfirm: one: "Are you sure you want to delete {n} file?" other: "Are you sure you want to delete {n} files?" deleteTabConfirm: "Are you sure you want to delete this tab?" +disableDataSaverWhenOnWifi: "Disable data saver when on Wi-Fi" disableSubscribingNotes: "Disable real-time reaction updates" discardChangesConfirm: "Are you sure you want to discard changes and back?" doubleTapToShow: "Double tap to show" diff --git a/lib/i18n/aria/aria_ja-JP.i18n.yaml b/lib/i18n/aria/aria_ja-JP.i18n.yaml index fe9aa76bf..fd10a38e2 100644 --- a/lib/i18n/aria/aria_ja-JP.i18n.yaml +++ b/lib/i18n/aria/aria_ja-JP.i18n.yaml @@ -14,6 +14,7 @@ crop: "クロップ" custom: "カスタム" deleteFilesConfirm: "{n}個のファイルを削除しますか?" deleteTabConfirm: "このタブを削除しますか?" +disableDataSaverWhenOnWifi: "Wi-Fi接続中はデータセーバーを無効にする" disableSubscribingNotes: "リアクションのリアルタイム更新を無効にする" discardChangesConfirm: "変更せずに戻りますか?" doubleTapToShow: "ダブルタップして表示" diff --git a/lib/i18n/aria/aria_ja-KS.i18n.yaml b/lib/i18n/aria/aria_ja-KS.i18n.yaml index 084ab46a5..ccbb9052d 100644 --- a/lib/i18n/aria/aria_ja-KS.i18n.yaml +++ b/lib/i18n/aria/aria_ja-KS.i18n.yaml @@ -14,6 +14,7 @@ crop: "クロップ" custom: "カスタム" deleteFilesConfirm: "ファイルが{n}個あるけどほかしてええか?" deleteTabConfirm: "このタブほかしてええか?" +disableDataSaverWhenOnWifi: "Wi-Fi接続中はデータセーバーを止めとく" disableSubscribingNotes: "ツッコミをいちいち更新せんようにする" discardChangesConfirm: "変えんと戻ってええか?" doubleTapToShow: "二度押ししたら見えるで" diff --git a/lib/i18n/strings.g.dart b/lib/i18n/strings.g.dart index 706ccd1fb..cb23c25ad 100644 --- a/lib/i18n/strings.g.dart +++ b/lib/i18n/strings.g.dart @@ -4,7 +4,7 @@ /// To regenerate, run: `dart run slang` /// /// Locales: 31 -/// Strings: 50698 (1635 per locale) +/// Strings: 50701 (1635 per locale) // coverage:ignore-file // ignore_for_file: type=lint diff --git a/lib/i18n/strings_en_US.g.dart b/lib/i18n/strings_en_US.g.dart index c6994173a..f41819779 100644 --- a/lib/i18n/strings_en_US.g.dart +++ b/lib/i18n/strings_en_US.g.dart @@ -68,6 +68,7 @@ class _StringsAriaEnUs { other: 'Are you sure you want to delete ${n} files?', ); String get deleteTabConfirm => 'Are you sure you want to delete this tab?'; + String get disableDataSaverWhenOnWifi => 'Disable data saver when on Wi-Fi'; String get disableSubscribingNotes => 'Disable real-time reaction updates'; String get discardChangesConfirm => 'Are you sure you want to discard changes and back?'; String get doubleTapToShow => 'Double tap to show'; diff --git a/lib/i18n/strings_ja_JP.g.dart b/lib/i18n/strings_ja_JP.g.dart index ec9511bfb..90c1129fb 100644 --- a/lib/i18n/strings_ja_JP.g.dart +++ b/lib/i18n/strings_ja_JP.g.dart @@ -60,6 +60,7 @@ class _StringsAriaJaJp extends _StringsAriaEnUs { @override String get custom => 'カスタム'; @override String deleteFilesConfirm({required Object n}) => '${n}個のファイルを削除しますか?'; @override String get deleteTabConfirm => 'このタブを削除しますか?'; + @override String get disableDataSaverWhenOnWifi => 'Wi-Fi接続中はデータセーバーを無効にする'; @override String get disableSubscribingNotes => 'リアクションのリアルタイム更新を無効にする'; @override String get discardChangesConfirm => '変更せずに戻りますか?'; @override String get doubleTapToShow => 'ダブルタップして表示'; diff --git a/lib/i18n/strings_ja_KS.g.dart b/lib/i18n/strings_ja_KS.g.dart index 775f0c44c..235a2e7ff 100644 --- a/lib/i18n/strings_ja_KS.g.dart +++ b/lib/i18n/strings_ja_KS.g.dart @@ -60,6 +60,7 @@ class _StringsAriaJaKs extends _StringsAriaEnUs { @override String get custom => 'カスタム'; @override String deleteFilesConfirm({required Object n}) => 'ファイルが${n}個あるけどほかしてええか?'; @override String get deleteTabConfirm => 'このタブほかしてええか?'; + @override String get disableDataSaverWhenOnWifi => 'Wi-Fi接続中はデータセーバーを止めとく'; @override String get disableSubscribingNotes => 'ツッコミをいちいち更新せんようにする'; @override String get discardChangesConfirm => '変えんと戻ってええか?'; @override String get doubleTapToShow => '二度押ししたら見えるで'; diff --git a/lib/model/general_settings.dart b/lib/model/general_settings.dart index 11eeec2a0..c61e22887 100644 --- a/lib/model/general_settings.dart +++ b/lib/model/general_settings.dart @@ -45,6 +45,7 @@ class GeneralSettings with _$GeneralSettings { @Default(false) bool useGroupedNotifications, @Default(false) bool dataSaverMedia, @Default(false) bool dataSaverUrlPreview, + @Default(false) bool disableDataSaverWhenOnWifi, @Default(false) bool showLikeButtonInNoteFooter, @Default(false) bool showTranslateButtonInNoteFooter, @Default(defaultFontSize) double fontSize, diff --git a/lib/model/general_settings.freezed.dart b/lib/model/general_settings.freezed.dart index 86e71aa5c..386165909 100644 --- a/lib/model/general_settings.freezed.dart +++ b/lib/model/general_settings.freezed.dart @@ -44,6 +44,7 @@ mixin _$GeneralSettings { bool get useGroupedNotifications => throw _privateConstructorUsedError; bool get dataSaverMedia => throw _privateConstructorUsedError; bool get dataSaverUrlPreview => throw _privateConstructorUsedError; + bool get disableDataSaverWhenOnWifi => throw _privateConstructorUsedError; bool get showLikeButtonInNoteFooter => throw _privateConstructorUsedError; bool get showTranslateButtonInNoteFooter => throw _privateConstructorUsedError; @@ -109,6 +110,7 @@ abstract class $GeneralSettingsCopyWith<$Res> { bool useGroupedNotifications, bool dataSaverMedia, bool dataSaverUrlPreview, + bool disableDataSaverWhenOnWifi, bool showLikeButtonInNoteFooter, bool showTranslateButtonInNoteFooter, double fontSize, @@ -173,6 +175,7 @@ class _$GeneralSettingsCopyWithImpl<$Res, $Val extends GeneralSettings> Object? useGroupedNotifications = null, Object? dataSaverMedia = null, Object? dataSaverUrlPreview = null, + Object? disableDataSaverWhenOnWifi = null, Object? showLikeButtonInNoteFooter = null, Object? showTranslateButtonInNoteFooter = null, Object? fontSize = null, @@ -287,6 +290,10 @@ class _$GeneralSettingsCopyWithImpl<$Res, $Val extends GeneralSettings> ? _value.dataSaverUrlPreview : dataSaverUrlPreview // ignore: cast_nullable_to_non_nullable as bool, + disableDataSaverWhenOnWifi: null == disableDataSaverWhenOnWifi + ? _value.disableDataSaverWhenOnWifi + : disableDataSaverWhenOnWifi // ignore: cast_nullable_to_non_nullable + as bool, showLikeButtonInNoteFooter: null == showLikeButtonInNoteFooter ? _value.showLikeButtonInNoteFooter : showLikeButtonInNoteFooter // ignore: cast_nullable_to_non_nullable @@ -434,6 +441,7 @@ abstract class _$$GeneralSettingsImplCopyWith<$Res> bool useGroupedNotifications, bool dataSaverMedia, bool dataSaverUrlPreview, + bool disableDataSaverWhenOnWifi, bool showLikeButtonInNoteFooter, bool showTranslateButtonInNoteFooter, double fontSize, @@ -496,6 +504,7 @@ class __$$GeneralSettingsImplCopyWithImpl<$Res> Object? useGroupedNotifications = null, Object? dataSaverMedia = null, Object? dataSaverUrlPreview = null, + Object? disableDataSaverWhenOnWifi = null, Object? showLikeButtonInNoteFooter = null, Object? showTranslateButtonInNoteFooter = null, Object? fontSize = null, @@ -610,6 +619,10 @@ class __$$GeneralSettingsImplCopyWithImpl<$Res> ? _value.dataSaverUrlPreview : dataSaverUrlPreview // ignore: cast_nullable_to_non_nullable as bool, + disableDataSaverWhenOnWifi: null == disableDataSaverWhenOnWifi + ? _value.disableDataSaverWhenOnWifi + : disableDataSaverWhenOnWifi // ignore: cast_nullable_to_non_nullable + as bool, showLikeButtonInNoteFooter: null == showLikeButtonInNoteFooter ? _value.showLikeButtonInNoteFooter : showLikeButtonInNoteFooter // ignore: cast_nullable_to_non_nullable @@ -752,6 +765,7 @@ class _$GeneralSettingsImpl implements _GeneralSettings { this.useGroupedNotifications = false, this.dataSaverMedia = false, this.dataSaverUrlPreview = false, + this.disableDataSaverWhenOnWifi = false, this.showLikeButtonInNoteFooter = false, this.showTranslateButtonInNoteFooter = false, this.fontSize = defaultFontSize, @@ -852,6 +866,9 @@ class _$GeneralSettingsImpl implements _GeneralSettings { final bool dataSaverUrlPreview; @override @JsonKey() + final bool disableDataSaverWhenOnWifi; + @override + @JsonKey() final bool showLikeButtonInNoteFooter; @override @JsonKey() @@ -939,7 +956,7 @@ class _$GeneralSettingsImpl implements _GeneralSettings { @override String toString() { - return 'GeneralSettings(locale: $locale, collapseRenotes: $collapseRenotes, sensitive: $sensitive, highlightSensitiveMedia: $highlightSensitiveMedia, animatedMfm: $animatedMfm, advancedMfm: $advancedMfm, showReactionsCount: $showReactionsCount, loadRawImages: $loadRawImages, emojiStyle: $emojiStyle, emojiPickerUseDialog: $emojiPickerUseDialog, emojiPickerScale: $emojiPickerScale, emojiPickerAutofocus: $emojiPickerAutofocus, squareAvatars: $squareAvatars, showAvatarDecorations: $showAvatarDecorations, showClipButtonInNoteFooter: $showClipButtonInNoteFooter, reactionsDisplayScale: $reactionsDisplayScale, limitWidthOfReaction: $limitWidthOfReaction, forceShowAds: $forceShowAds, useGroupedNotifications: $useGroupedNotifications, dataSaverMedia: $dataSaverMedia, dataSaverUrlPreview: $dataSaverUrlPreview, showLikeButtonInNoteFooter: $showLikeButtonInNoteFooter, showTranslateButtonInNoteFooter: $showTranslateButtonInNoteFooter, fontSize: $fontSize, fontFamily: $fontFamily, showAvatarsInNote: $showAvatarsInNote, showAvatarsInSubNote: $showAvatarsInSubNote, showNoteReactionsViewer: $showNoteReactionsViewer, showNoteFooter: $showNoteFooter, showSubNoteReactionsViewer: $showSubNoteReactionsViewer, showSubNoteFooter: $showSubNoteFooter, vibrateNote: $vibrateNote, vibrateNotification: $vibrateNotification, showTimelineTabBarOnBottom: $showTimelineTabBarOnBottom, noteFooterScale: $noteFooterScale, enableInfiniteScroll: $enableInfiniteScroll, keepScreenOn: $keepScreenOn, enableHorizontalSwipe: $enableHorizontalSwipe, openSensitiveMediaOnDoubleTap: $openSensitiveMediaOnDoubleTap, noteTapAction: $noteTapAction, noteDoubleTapAction: $noteDoubleTapAction, noteLongPressAction: $noteLongPressAction, confirmBeforePost: $confirmBeforePost, confirmBeforeReact: $confirmBeforeReact, confirmBeforeFollow: $confirmBeforeFollow, themeMode: $themeMode, lightThemeId: $lightThemeId, darkThemeId: $darkThemeId, emojiPickerKeepOpen: $emojiPickerKeepOpen)'; + return 'GeneralSettings(locale: $locale, collapseRenotes: $collapseRenotes, sensitive: $sensitive, highlightSensitiveMedia: $highlightSensitiveMedia, animatedMfm: $animatedMfm, advancedMfm: $advancedMfm, showReactionsCount: $showReactionsCount, loadRawImages: $loadRawImages, emojiStyle: $emojiStyle, emojiPickerUseDialog: $emojiPickerUseDialog, emojiPickerScale: $emojiPickerScale, emojiPickerAutofocus: $emojiPickerAutofocus, squareAvatars: $squareAvatars, showAvatarDecorations: $showAvatarDecorations, showClipButtonInNoteFooter: $showClipButtonInNoteFooter, reactionsDisplayScale: $reactionsDisplayScale, limitWidthOfReaction: $limitWidthOfReaction, forceShowAds: $forceShowAds, useGroupedNotifications: $useGroupedNotifications, dataSaverMedia: $dataSaverMedia, dataSaverUrlPreview: $dataSaverUrlPreview, disableDataSaverWhenOnWifi: $disableDataSaverWhenOnWifi, showLikeButtonInNoteFooter: $showLikeButtonInNoteFooter, showTranslateButtonInNoteFooter: $showTranslateButtonInNoteFooter, fontSize: $fontSize, fontFamily: $fontFamily, showAvatarsInNote: $showAvatarsInNote, showAvatarsInSubNote: $showAvatarsInSubNote, showNoteReactionsViewer: $showNoteReactionsViewer, showNoteFooter: $showNoteFooter, showSubNoteReactionsViewer: $showSubNoteReactionsViewer, showSubNoteFooter: $showSubNoteFooter, vibrateNote: $vibrateNote, vibrateNotification: $vibrateNotification, showTimelineTabBarOnBottom: $showTimelineTabBarOnBottom, noteFooterScale: $noteFooterScale, enableInfiniteScroll: $enableInfiniteScroll, keepScreenOn: $keepScreenOn, enableHorizontalSwipe: $enableHorizontalSwipe, openSensitiveMediaOnDoubleTap: $openSensitiveMediaOnDoubleTap, noteTapAction: $noteTapAction, noteDoubleTapAction: $noteDoubleTapAction, noteLongPressAction: $noteLongPressAction, confirmBeforePost: $confirmBeforePost, confirmBeforeReact: $confirmBeforeReact, confirmBeforeFollow: $confirmBeforeFollow, themeMode: $themeMode, lightThemeId: $lightThemeId, darkThemeId: $darkThemeId, emojiPickerKeepOpen: $emojiPickerKeepOpen)'; } @override @@ -989,6 +1006,9 @@ class _$GeneralSettingsImpl implements _GeneralSettings { other.dataSaverMedia == dataSaverMedia) && (identical(other.dataSaverUrlPreview, dataSaverUrlPreview) || other.dataSaverUrlPreview == dataSaverUrlPreview) && + (identical(other.disableDataSaverWhenOnWifi, disableDataSaverWhenOnWifi) || + other.disableDataSaverWhenOnWifi == + disableDataSaverWhenOnWifi) && (identical(other.showLikeButtonInNoteFooter, showLikeButtonInNoteFooter) || other.showLikeButtonInNoteFooter == showLikeButtonInNoteFooter) && @@ -1001,10 +1021,8 @@ class _$GeneralSettingsImpl implements _GeneralSettings { other.fontFamily == fontFamily) && (identical(other.showAvatarsInNote, showAvatarsInNote) || other.showAvatarsInNote == showAvatarsInNote) && - (identical(other.showAvatarsInSubNote, showAvatarsInSubNote) || - other.showAvatarsInSubNote == showAvatarsInSubNote) && - (identical(other.showNoteReactionsViewer, showNoteReactionsViewer) || - other.showNoteReactionsViewer == showNoteReactionsViewer) && + (identical(other.showAvatarsInSubNote, showAvatarsInSubNote) || other.showAvatarsInSubNote == showAvatarsInSubNote) && + (identical(other.showNoteReactionsViewer, showNoteReactionsViewer) || other.showNoteReactionsViewer == showNoteReactionsViewer) && (identical(other.showNoteFooter, showNoteFooter) || other.showNoteFooter == showNoteFooter) && (identical(other.showSubNoteReactionsViewer, showSubNoteReactionsViewer) || other.showSubNoteReactionsViewer == showSubNoteReactionsViewer) && (identical(other.showSubNoteFooter, showSubNoteFooter) || other.showSubNoteFooter == showSubNoteFooter) && @@ -1053,6 +1071,7 @@ class _$GeneralSettingsImpl implements _GeneralSettings { useGroupedNotifications, dataSaverMedia, dataSaverUrlPreview, + disableDataSaverWhenOnWifi, showLikeButtonInNoteFooter, showTranslateButtonInNoteFooter, fontSize, @@ -1122,6 +1141,7 @@ abstract class _GeneralSettings implements GeneralSettings { final bool useGroupedNotifications, final bool dataSaverMedia, final bool dataSaverUrlPreview, + final bool disableDataSaverWhenOnWifi, final bool showLikeButtonInNoteFooter, final bool showTranslateButtonInNoteFooter, final double fontSize, @@ -1199,6 +1219,8 @@ abstract class _GeneralSettings implements GeneralSettings { @override bool get dataSaverUrlPreview; @override + bool get disableDataSaverWhenOnWifi; + @override bool get showLikeButtonInNoteFooter; @override bool get showTranslateButtonInNoteFooter; diff --git a/lib/model/general_settings.g.dart b/lib/model/general_settings.g.dart index 80c321ff6..75e4b2f70 100644 --- a/lib/model/general_settings.g.dart +++ b/lib/model/general_settings.g.dart @@ -39,6 +39,8 @@ _$GeneralSettingsImpl _$$GeneralSettingsImplFromJson( json['useGroupedNotifications'] as bool? ?? false, dataSaverMedia: json['dataSaverMedia'] as bool? ?? false, dataSaverUrlPreview: json['dataSaverUrlPreview'] as bool? ?? false, + disableDataSaverWhenOnWifi: + json['disableDataSaverWhenOnWifi'] as bool? ?? false, showLikeButtonInNoteFooter: json['showLikeButtonInNoteFooter'] as bool? ?? false, showTranslateButtonInNoteFooter: @@ -114,6 +116,7 @@ Map _$$GeneralSettingsImplToJson( val['useGroupedNotifications'] = instance.useGroupedNotifications; val['dataSaverMedia'] = instance.dataSaverMedia; val['dataSaverUrlPreview'] = instance.dataSaverUrlPreview; + val['disableDataSaverWhenOnWifi'] = instance.disableDataSaverWhenOnWifi; val['showLikeButtonInNoteFooter'] = instance.showLikeButtonInNoteFooter; val['showTranslateButtonInNoteFooter'] = instance.showTranslateButtonInNoteFooter; diff --git a/lib/provider/connectivity_provider.dart b/lib/provider/connectivity_provider.dart new file mode 100644 index 000000000..4fefe5954 --- /dev/null +++ b/lib/provider/connectivity_provider.dart @@ -0,0 +1,9 @@ +import 'package:connectivity_plus/connectivity_plus.dart'; +import 'package:riverpod_annotation/riverpod_annotation.dart'; + +part 'connectivity_provider.g.dart'; + +@Riverpod(keepAlive: true) +Stream> connectivity(ConnectivityRef ref) { + return Connectivity().onConnectivityChanged; +} diff --git a/lib/provider/connectivity_provider.g.dart b/lib/provider/connectivity_provider.g.dart new file mode 100644 index 000000000..2a12f4197 --- /dev/null +++ b/lib/provider/connectivity_provider.g.dart @@ -0,0 +1,24 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'connectivity_provider.dart'; + +// ************************************************************************** +// RiverpodGenerator +// ************************************************************************** + +String _$connectivityHash() => r'2b45f46f28b989bcf776392819952488633323fc'; + +/// See also [connectivity]. +@ProviderFor(connectivity) +final connectivityProvider = StreamProvider>.internal( + connectivity, + name: r'connectivityProvider', + debugGetCreateSourceHash: + const bool.fromEnvironment('dart.vm.product') ? null : _$connectivityHash, + dependencies: null, + allTransitiveDependencies: null, +); + +typedef ConnectivityRef = StreamProviderRef>; +// ignore_for_file: type=lint +// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member diff --git a/lib/provider/general_settings_notifier_provider.dart b/lib/provider/general_settings_notifier_provider.dart index a51f717c2..a0284171b 100644 --- a/lib/provider/general_settings_notifier_provider.dart +++ b/lib/provider/general_settings_notifier_provider.dart @@ -154,6 +154,14 @@ class GeneralSettingsNotifier extends _$GeneralSettingsNotifier { await _save(); } + Future setDisableDataSaverWhenOnWifi( + bool disableDataSaverWhenOnWifi, + ) async { + state = + state.copyWith(disableDataSaverWhenOnWifi: disableDataSaverWhenOnWifi); + await _save(); + } + Future setShowLikeButtonInNoteFooter( bool showLikeButtonInNoteFooter, ) async { diff --git a/lib/provider/general_settings_notifier_provider.g.dart b/lib/provider/general_settings_notifier_provider.g.dart index f9c3b3835..5882187bc 100644 --- a/lib/provider/general_settings_notifier_provider.g.dart +++ b/lib/provider/general_settings_notifier_provider.g.dart @@ -7,7 +7,7 @@ part of 'general_settings_notifier_provider.dart'; // ************************************************************************** String _$generalSettingsNotifierHash() => - r'92ba4a49332ce00579072609b665e1b4ec1cb81b'; + r'81de072e49c1710f6ca3534084bb59b7f9b6903f'; /// See also [GeneralSettingsNotifier]. @ProviderFor(GeneralSettingsNotifier) diff --git a/lib/view/page/settings/appearance_page.dart b/lib/view/page/settings/appearance_page.dart index 31c443420..c1540fe98 100644 --- a/lib/view/page/settings/appearance_page.dart +++ b/lib/view/page/settings/appearance_page.dart @@ -40,6 +40,13 @@ class AppearancePage extends HookConsumerWidget { .read(generalSettingsNotifierProvider.notifier) .setDataSaverUrlPreview(value), ), + SwitchListTile( + title: Text(t.aria.disableDataSaverWhenOnWifi), + value: settings.disableDataSaverWhenOnWifi, + onChanged: (value) => ref + .read(generalSettingsNotifierProvider.notifier) + .setDisableDataSaverWhenOnWifi(value), + ), const Divider(), SwitchListTile( title: Text(t.misskey.forceShowAds), diff --git a/lib/view/widget/media_card.dart b/lib/view/widget/media_card.dart index 35150211b..75e6d3ead 100644 --- a/lib/view/widget/media_card.dart +++ b/lib/view/widget/media_card.dart @@ -1,3 +1,4 @@ +import 'package:connectivity_plus/connectivity_plus.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_blurhash/flutter_blurhash.dart'; @@ -12,6 +13,7 @@ import '../../extension/text_style_extension.dart'; import '../../i18n/strings.g.dart'; import '../../model/account.dart'; import '../../model/general_settings.dart'; +import '../../provider/connectivity_provider.dart'; import '../../provider/general_settings_notifier_provider.dart'; import '../../provider/misskey_colors_provider.dart'; import '../dialog/audio_dialog.dart'; @@ -174,9 +176,18 @@ class MediaCard extends HookConsumerWidget { generalSettingsNotifierProvider.select((settings) => settings.sensitive), ); final dataSaver = ref.watch( - generalSettingsNotifierProvider - .select((settings) => settings.dataSaverMedia), - ); + generalSettingsNotifierProvider + .select((settings) => settings.dataSaverMedia), + ) && + !(ref.watch( + generalSettingsNotifierProvider + .select((settings) => settings.disableDataSaverWhenOnWifi), + ) && + (ref + .watch(connectivityProvider) + .valueOrNull + ?.contains(ConnectivityResult.wifi) ?? + false)); final openMediaOnDoubleTap = ref.watch( generalSettingsNotifierProvider .select((settings) => settings.openSensitiveMediaOnDoubleTap), @@ -306,7 +317,8 @@ class MediaCard extends HookConsumerWidget { style: const TextStyle(fontWeight: FontWeight.bold), children: [ - if (dataSaver && file.size > 0) + if (dataSaver && file.size > 0) ...[ + const TextSpan(text: ' '), TextSpan( text: prettyBytes( file.size.toDouble(), @@ -315,6 +327,7 @@ class MediaCard extends HookConsumerWidget { binary: true, ), ), + ], ], ), TextSpan( diff --git a/lib/view/widget/url_preview.dart b/lib/view/widget/url_preview.dart index be4c2db06..756c83a26 100644 --- a/lib/view/widget/url_preview.dart +++ b/lib/view/widget/url_preview.dart @@ -1,3 +1,4 @@ +import 'package:connectivity_plus/connectivity_plus.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; @@ -7,6 +8,7 @@ import '../../extension/text_style_extension.dart'; import '../../i18n/strings.g.dart'; import '../../model/account.dart'; import '../../model/summaly_result.dart'; +import '../../provider/connectivity_provider.dart'; import '../../provider/general_settings_notifier_provider.dart'; import '../../provider/summaly_provider.dart'; import '../../util/navigate.dart'; @@ -61,10 +63,20 @@ class UrlPreview extends HookConsumerWidget { final isPlayerOpen = useState(false); final thumbnail = summalyResult?.thumbnail; final hideThumbnail = (summalyResult?.sensitive ?? false) || - ref.watch( - generalSettingsNotifierProvider - .select((settings) => settings.dataSaverUrlPreview), - ); + (ref.watch( + generalSettingsNotifierProvider + .select((settings) => settings.dataSaverUrlPreview), + ) && + !(ref.watch( + generalSettingsNotifierProvider.select( + (settings) => settings.disableDataSaverWhenOnWifi, + ), + ) && + (ref + .watch(connectivityProvider) + .valueOrNull + ?.contains(ConnectivityResult.wifi) ?? + false))); final icon = summalyResult?.icon; final playerUrl = summalyResult?.player.url; final tweetId = _extractTweetId(link); diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index 65bbd0792..f946296ea 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -7,6 +7,7 @@ import Foundation import audio_service import audio_session +import connectivity_plus import flutter_image_compress_macos import flutter_inappwebview_macos import flutter_secure_storage_macos @@ -25,6 +26,7 @@ import wakelock_plus func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { AudioServicePlugin.register(with: registry.registrar(forPlugin: "AudioServicePlugin")) AudioSessionPlugin.register(with: registry.registrar(forPlugin: "AudioSessionPlugin")) + ConnectivityPlusPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlusPlugin")) FlutterImageCompressMacosPlugin.register(with: registry.registrar(forPlugin: "FlutterImageCompressMacosPlugin")) InAppWebViewFlutterPlugin.register(with: registry.registrar(forPlugin: "InAppWebViewFlutterPlugin")) FlutterSecureStoragePlugin.register(with: registry.registrar(forPlugin: "FlutterSecureStoragePlugin")) diff --git a/pubspec.lock b/pubspec.lock index 11e984db0..8fd10a7bb 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -281,6 +281,22 @@ packages: url: "https://pub.dev" source: hosted version: "0.7.0" + connectivity_plus: + dependency: "direct main" + description: + name: connectivity_plus + sha256: ebe15d94de9dd7c31dc2ac54e42780acdf3384b1497c69290c9f3c5b0279fc57 + url: "https://pub.dev" + source: hosted + version: "6.0.2" + connectivity_plus_platform_interface: + dependency: transitive + description: + name: connectivity_plus_platform_interface + sha256: b6a56efe1e6675be240de39107281d4034b64ac23438026355b4234042a35adb + url: "https://pub.dev" + source: hosted + version: "2.0.0" convert: dependency: transitive description: @@ -1238,6 +1254,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.0" + nm: + dependency: transitive + description: + name: nm + sha256: "2c9aae4127bdc8993206464fcc063611e0e36e72018696cd9631023a31b24254" + url: "https://pub.dev" + source: hosted + version: "0.5.0" octo_image: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index f05a0135b..82ed4fea8 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,6 +16,7 @@ dependencies: collection: ^1.18.0 colorfilter_generator: ^0.0.8 confetti: ^0.7.0 + connectivity_plus: ^6.0.2 dio: ^5.4.3+1 dotted_border: ^2.1.0 extended_image: ^8.2.0 diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index 50a0dedcc..8cfd125d1 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -6,12 +6,15 @@ #include "generated_plugin_registrant.h" +#include #include #include #include #include void RegisterPlugins(flutter::PluginRegistry* registry) { + ConnectivityPlusWindowsPluginRegisterWithRegistrar( + registry->GetRegistrarForPlugin("ConnectivityPlusWindowsPlugin")); FlutterSecureStorageWindowsPluginRegisterWithRegistrar( registry->GetRegistrarForPlugin("FlutterSecureStorageWindowsPlugin")); GalPluginCApiRegisterWithRegistrar( diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index 9c3dd2017..6271f1e53 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -3,6 +3,7 @@ # list(APPEND FLUTTER_PLUGIN_LIST + connectivity_plus flutter_secure_storage_windows gal share_plus