mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 07:47:24 +00:00
handle mouse back button event
This commit is contained in:
@@ -21,7 +21,6 @@ import 'package:venera/foundation/history.dart';
|
|||||||
import 'package:venera/foundation/image_provider/cached_image.dart';
|
import 'package:venera/foundation/image_provider/cached_image.dart';
|
||||||
import 'package:venera/foundation/local.dart';
|
import 'package:venera/foundation/local.dart';
|
||||||
import 'package:venera/foundation/res.dart';
|
import 'package:venera/foundation/res.dart';
|
||||||
import 'package:venera/foundation/state_controller.dart';
|
|
||||||
import 'package:venera/network/cloudflare.dart';
|
import 'package:venera/network/cloudflare.dart';
|
||||||
import 'package:venera/pages/comic_page.dart';
|
import 'package:venera/pages/comic_page.dart';
|
||||||
import 'package:venera/pages/favorites/favorites_page.dart';
|
import 'package:venera/pages/favorites/favorites_page.dart';
|
||||||
@@ -46,3 +45,4 @@ part 'select.dart';
|
|||||||
part 'side_bar.dart';
|
part 'side_bar.dart';
|
||||||
part 'comic.dart';
|
part 'comic.dart';
|
||||||
part 'effects.dart';
|
part 'effects.dart';
|
||||||
|
part 'gesture.dart';
|
61
lib/components/gesture.dart
Normal file
61
lib/components/gesture.dart
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
part of 'components.dart';
|
||||||
|
|
||||||
|
class MouseBackRecognizer extends BaseTapGestureRecognizer {
|
||||||
|
GestureTapDownCallback? onTapDown;
|
||||||
|
|
||||||
|
MouseBackRecognizer({
|
||||||
|
super.debugOwner,
|
||||||
|
super.supportedDevices,
|
||||||
|
super.allowedButtonsFilter,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
void handleTapCancel({
|
||||||
|
required PointerDownEvent down,
|
||||||
|
PointerCancelEvent? cancel,
|
||||||
|
required String reason,
|
||||||
|
}) {}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void handleTapDown({required PointerDownEvent down}) {
|
||||||
|
final TapDownDetails details = TapDownDetails(
|
||||||
|
globalPosition: down.position,
|
||||||
|
localPosition: down.localPosition,
|
||||||
|
kind: getKindForPointer(down.pointer),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (down.buttons == kBackMouseButton && onTapDown != null) {
|
||||||
|
invokeCallback<void>('onTapDown', () => onTapDown!(details));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void handleTapUp({
|
||||||
|
required PointerDownEvent down,
|
||||||
|
required PointerUpEvent up,
|
||||||
|
}) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
class MouseBackDetector extends StatelessWidget {
|
||||||
|
const MouseBackDetector({super.key, required this.onTapDown, required this.child});
|
||||||
|
|
||||||
|
final Widget child;
|
||||||
|
|
||||||
|
final GestureTapDownCallback onTapDown;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return RawGestureDetector(
|
||||||
|
gestures: <Type, GestureRecognizerFactory>{
|
||||||
|
MouseBackRecognizer: GestureRecognizerFactoryWithHandlers<MouseBackRecognizer>(
|
||||||
|
() => MouseBackRecognizer(),
|
||||||
|
(MouseBackRecognizer instance) {
|
||||||
|
instance.onTapDown = onTapDown;
|
||||||
|
},
|
||||||
|
),
|
||||||
|
},
|
||||||
|
behavior: HitTestBehavior.translucent,
|
||||||
|
child: child,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@@ -20,7 +20,7 @@ void main(List<String> args) {
|
|||||||
runZonedGuarded(() async {
|
runZonedGuarded(() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
await init();
|
await init();
|
||||||
if(App.isAndroid) {
|
if (App.isAndroid) {
|
||||||
handleLinks();
|
handleLinks();
|
||||||
}
|
}
|
||||||
FlutterError.onError = (details) {
|
FlutterError.onError = (details) {
|
||||||
@@ -73,6 +73,7 @@ class _MyAppState extends State<MyApp> {
|
|||||||
el.markNeedsBuild();
|
el.markNeedsBuild();
|
||||||
el.visitChildren(rebuild);
|
el.visitChildren(rebuild);
|
||||||
}
|
}
|
||||||
|
|
||||||
(context as Element).visitChildren(rebuild);
|
(context as Element).visitChildren(rebuild);
|
||||||
setState(() {});
|
setState(() {});
|
||||||
}
|
}
|
||||||
@@ -114,10 +115,10 @@ class _MyAppState extends State<MyApp> {
|
|||||||
],
|
],
|
||||||
locale: () {
|
locale: () {
|
||||||
var lang = appdata.settings['language'];
|
var lang = appdata.settings['language'];
|
||||||
if(lang == 'system') {
|
if (lang == 'system') {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return switch(lang) {
|
return switch (lang) {
|
||||||
'zh-CN' => const Locale('zh', 'CN'),
|
'zh-CN' => const Locale('zh', 'CN'),
|
||||||
'zh-TW' => const Locale('zh', 'TW'),
|
'zh-TW' => const Locale('zh', 'TW'),
|
||||||
'en-US' => const Locale('en'),
|
'en-US' => const Locale('en'),
|
||||||
@@ -148,7 +149,12 @@ class _MyAppState extends State<MyApp> {
|
|||||||
App.pop,
|
App.pop,
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
child: WindowFrame(widget),
|
child: MouseBackDetector(
|
||||||
|
onTapDown: (event) {
|
||||||
|
App.pop();
|
||||||
|
},
|
||||||
|
child: WindowFrame(widget),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return _SystemUiProvider(Material(
|
return _SystemUiProvider(Material(
|
||||||
|
Reference in New Issue
Block a user