Skip to content

Commit

Permalink
feat: toggle clipboard monitoring
Browse files Browse the repository at this point in the history
(disabled by default)
  • Loading branch information
MSOB7YY committed Nov 28, 2023
1 parent ea50869 commit d147170
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 6 deletions.
16 changes: 12 additions & 4 deletions lib/controller/clipboard_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,20 @@ class ClipboardController {
ClipboardController._internal();

Timer? _timer;
void initialize() {

void setClipboardMonitoringStatus(bool monitor) {
_timer?.cancel();
_timer = null;
_timer = Timer.periodic(const Duration(seconds: 3), (timer) {
_checkClipboardChanged();
});

if (monitor) {
_timer = Timer.periodic(const Duration(seconds: 3), (timer) {
_checkClipboardChanged();
});
} else {
_textInControllerEmpty.value = true;
_lastCopyUsed.value = '';
_clipboardText.value = '';
}
}

void _checkClipboardChanged() async {
Expand Down
7 changes: 7 additions & 0 deletions lib/controller/settings_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ class SettingsController {
final RxBool prioritizeEmbeddedLyrics = true.obs;
final RxBool swipeableDrawer = true.obs;
final RxBool dismissibleMiniplayer = false.obs;
final RxBool enableClipboardMonitoring = false.obs;
final RxList<TagField> tagFieldsToEdit = <TagField>[
TagField.trackNumber,
TagField.year,
Expand Down Expand Up @@ -429,6 +430,7 @@ class SettingsController {
prioritizeEmbeddedLyrics.value = json['prioritizeEmbeddedLyrics'] ?? prioritizeEmbeddedLyrics.value;
swipeableDrawer.value = json['swipeableDrawer'] ?? swipeableDrawer.value;
dismissibleMiniplayer.value = json['dismissibleMiniplayer'] ?? dismissibleMiniplayer.value;
enableClipboardMonitoring.value = json['enableClipboardMonitoring'] ?? enableClipboardMonitoring.value;

final listFromStorage = List<String>.from(json['tagFieldsToEdit'] ?? []);
tagFieldsToEdit.value = listFromStorage.isNotEmpty ? List<TagField>.from(listFromStorage.map((e) => TagField.values.getEnum(e))) : tagFieldsToEdit;
Expand Down Expand Up @@ -639,6 +641,7 @@ class SettingsController {
'prioritizeEmbeddedLyrics': prioritizeEmbeddedLyrics.value,
'swipeableDrawer': swipeableDrawer.value,
'dismissibleMiniplayer': dismissibleMiniplayer.value,
'enableClipboardMonitoring': enableClipboardMonitoring.value,
'tagFieldsToEdit': tagFieldsToEdit.mapped((element) => element.convertToString),
'wakelockMode': wakelockMode.value.convertToString,
'localVideoMatchingType': localVideoMatchingType.value.convertToString,
Expand Down Expand Up @@ -818,6 +821,7 @@ class SettingsController {
bool? prioritizeEmbeddedLyrics,
bool? swipeableDrawer,
bool? dismissibleMiniplayer,
bool? enableClipboardMonitoring,
List<TagField>? tagFieldsToEdit,
WakelockMode? wakelockMode,
LocalVideoMatchingType? localVideoMatchingType,
Expand Down Expand Up @@ -1268,6 +1272,9 @@ class SettingsController {
if (dismissibleMiniplayer != null) {
this.dismissibleMiniplayer.value = dismissibleMiniplayer;
}
if (enableClipboardMonitoring != null) {
this.enableClipboardMonitoring.value = enableClipboardMonitoring;
}
if (tagFieldsToEdit != null) {
tagFieldsToEdit.loop((d, index) {
if (!this.tagFieldsToEdit.contains(d)) {
Expand Down
2 changes: 2 additions & 0 deletions lib/core/translations/keys.dart
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ abstract class LanguageKeys {
String get ENABLE_BLUR_EFFECT => _getKey('ENABLE_BLUR_EFFECT');
String get ENABLE_BOTTOM_NAV_BAR_SUBTITLE => _getKey('ENABLE_BOTTOM_NAV_BAR_SUBTITLE');
String get ENABLE_BOTTOM_NAV_BAR => _getKey('ENABLE_BOTTOM_NAV_BAR');
String get ENABLE_CLIPBOARD_MONITORING => _getKey('ENABLE_CLIPBOARD_MONITORING');
String get ENABLE_CLIPBOARD_MONITORING_SUBTITLE => _getKey('ENABLE_CLIPBOARD_MONITORING_SUBTITLE');
String get ENABLE_CROSSFADE_EFFECT => _getKey('ENABLE_CROSSFADE_EFFECT');
String get ENABLE_FADE_EFFECT_ON_PLAY_PAUSE => _getKey('ENABLE_FADE_EFFECT_ON_PLAY_PAUSE');
String get ENABLE_FOLDERS_HIERARCHY => _getKey('ENABLE_FOLDERS_HIERARCHY');
Expand Down
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void main() async {
Language.initialize(),
]);
ConnectivityController.inst.initialize();
ClipboardController.inst.initialize();
ClipboardController.inst.setClipboardMonitoringStatus(settings.enableClipboardMonitoring.value);

/// updates values on startup
Indexer.inst.updateImageSizeInStorage();
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/pages/main_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ class NamidaSearchBar extends StatelessWidget {

return AnimatedSwitcher(
duration: const Duration(milliseconds: 200),
child: empty || (clipboard != '' && !alreadyPasted)
child: clipboard != '' && (empty || !alreadyPasted)
? NamidaIconButton(
horizontalPadding: 0,
icon: Broken.clipboard_tick,
Expand Down
19 changes: 19 additions & 0 deletions lib/ui/widgets/settings/extra_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';

import 'package:get/get.dart';

import 'package:namida/controller/clipboard_controller.dart';
import 'package:namida/controller/current_color.dart';
import 'package:namida/controller/folders_controller.dart';
import 'package:namida/controller/indexer_controller.dart';
Expand Down Expand Up @@ -30,6 +31,7 @@ enum _ExtraSettingsKeys {
prioritizeEmbeddedLyrics,
immersiveMode,
swipeToOpenDrawer,
enableClipboardMonitoring,
extractAllPalettes,
}

Expand All @@ -52,6 +54,7 @@ class ExtrasSettings extends SettingSubpageProvider {
_ExtraSettingsKeys.prioritizeEmbeddedLyrics: [lang.PRIORITIZE_EMBEDDED_LYRICS],
_ExtraSettingsKeys.immersiveMode: [lang.IMMERSIVE_MODE, lang.IMMERSIVE_MODE_SUBTITLE],
_ExtraSettingsKeys.swipeToOpenDrawer: [lang.SWIPE_TO_OPEN_DRAWER],
_ExtraSettingsKeys.enableClipboardMonitoring: [lang.ENABLE_CLIPBOARD_MONITORING, lang.ENABLE_CLIPBOARD_MONITORING_SUBTITLE],
_ExtraSettingsKeys.extractAllPalettes: [lang.EXTRACT_ALL_COLOR_PALETTES],
};

Expand Down Expand Up @@ -279,6 +282,22 @@ class ExtrasSettings extends SettingSubpageProvider {
),
),
),
getItemWrapper(
key: _ExtraSettingsKeys.enableClipboardMonitoring,
child: Obx(
() => CustomSwitchListTile(
bgColor: getBgColor(_ExtraSettingsKeys.enableClipboardMonitoring),
icon: Broken.clipboard_export,
title: lang.ENABLE_CLIPBOARD_MONITORING,
subtitle: lang.ENABLE_CLIPBOARD_MONITORING_SUBTITLE,
value: settings.enableClipboardMonitoring.value,
onChanged: (isTrue) {
settings.save(enableClipboardMonitoring: !isTrue);
ClipboardController.inst.setClipboardMonitoringStatus(!isTrue);
},
),
),
),
getItemWrapper(
key: _ExtraSettingsKeys.extractAllPalettes,
child: CustomListTile(
Expand Down

0 comments on commit d147170

Please sign in to comment.