mirror of
https://github.com/gabehf/Fladder.git
synced 2026-03-09 07:28:14 -07:00
feat: Customizable shortcuts/hotkeys (#439)
This implements the logic for allowing hotkeys with modifiers. Implemented globalhotkeys and videocontrol hotkeys Also implements saving the forward backwards seconds to the user. Co-authored-by: PartyDonut <PartyDonut@users.noreply.github.com>
This commit is contained in:
parent
23385d8e62
commit
fa30e634b4
29 changed files with 1360 additions and 162 deletions
70
lib/models/settings/key_combinations.dart
Normal file
70
lib/models/settings/key_combinations.dart
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
import 'package:fladder/screens/settings/widgets/key_listener.dart';
|
||||
|
||||
part 'key_combinations.freezed.dart';
|
||||
part 'key_combinations.g.dart';
|
||||
|
||||
@Freezed(toJson: true, fromJson: true)
|
||||
class KeyCombination with _$KeyCombination {
|
||||
const KeyCombination._();
|
||||
|
||||
factory KeyCombination({
|
||||
@LogicalKeyboardSerializer() LogicalKeyboardKey? modifier,
|
||||
@LogicalKeyboardSerializer() required LogicalKeyboardKey key,
|
||||
}) = _KeyCombination;
|
||||
|
||||
factory KeyCombination.fromJson(Map<String, dynamic> json) => _$KeyCombinationFromJson(json);
|
||||
|
||||
@override
|
||||
bool operator ==(covariant other) {
|
||||
return other is KeyCombination && other.key.keyId == key.keyId && other.modifier?.keyId == modifier?.keyId;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => key.hashCode ^ modifier.hashCode;
|
||||
|
||||
String get label => [modifier?.label, key.label].nonNulls.join(" + ");
|
||||
|
||||
static final Set<LogicalKeyboardKey> shiftKeys = {
|
||||
LogicalKeyboardKey.shift,
|
||||
LogicalKeyboardKey.shiftLeft,
|
||||
LogicalKeyboardKey.shiftRight,
|
||||
};
|
||||
|
||||
static final altKeys = {
|
||||
LogicalKeyboardKey.alt,
|
||||
LogicalKeyboardKey.altRight,
|
||||
LogicalKeyboardKey.altLeft,
|
||||
};
|
||||
|
||||
static final ctrlKeys = {
|
||||
LogicalKeyboardKey.control,
|
||||
LogicalKeyboardKey.controlLeft,
|
||||
LogicalKeyboardKey.controlRight,
|
||||
};
|
||||
|
||||
static final modifierKeys = {
|
||||
...shiftKeys,
|
||||
...altKeys,
|
||||
...ctrlKeys,
|
||||
};
|
||||
}
|
||||
|
||||
class LogicalKeyboardSerializer extends JsonConverter<LogicalKeyboardKey, String> {
|
||||
const LogicalKeyboardSerializer();
|
||||
|
||||
@override
|
||||
LogicalKeyboardKey fromJson(String json) {
|
||||
return LogicalKeyboardKey.findKeyByKeyId(int.parse(jsonDecode(json))) ?? LogicalKeyboardKey.abort;
|
||||
}
|
||||
|
||||
@override
|
||||
String toJson(LogicalKeyboardKey object) {
|
||||
return jsonEncode(object.keyId.toString());
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue