Copy and paste: the desktop's universal copy key works; Ctrl+C at the terminal login keeps the terminal
Omarchy's Super+C sends Ctrl+C by setting the modifier state with no Ctrl key event while Super is held. Flutter's web engine only presses a modifier on its own key event, so the app saw a plain "c": the chat selection was not copied and the terminal typed the letter. A key modifier sync in front of the framework's key handler now presses the modifiers the browser event's flags hold (and outside Apple platforms lets go of a held Meta for Ctrl+C/V/X/A/ Insert), installed by the app's binding. The terminal copies a selection on Ctrl+C without sending ^C, treats the injected copy key as copy only, and pastes on Shift+Insert. A refused clipboard write or read now shows a message instead of failing silently. Server: before the login completes, Ctrl+C and Ctrl+\ erase the typed password (Ctrl+U) and Ctrl+Z is dropped, so su is not killed and the terminal no longer ends. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -4,6 +4,8 @@ import '../ui/theme/app_theme.dart';
|
||||
import '../ui/scale/ui_scale.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'clipboard_failures.dart';
|
||||
|
||||
import '../shell/adaptive_shell.dart';
|
||||
import '../shell/destination.dart';
|
||||
|
||||
@@ -54,6 +56,7 @@ class MyApp extends StatelessWidget {
|
||||
if (router != null) {
|
||||
return MaterialApp.router(
|
||||
title: 'Pipelines',
|
||||
scaffoldMessengerKey: appScaffoldMessengerKey,
|
||||
builder: _scaled,
|
||||
theme: appLightTheme(fontFamily: fontFamily),
|
||||
darkTheme: appDarkTheme(fontFamily: fontFamily),
|
||||
@@ -63,6 +66,7 @@ class MyApp extends StatelessWidget {
|
||||
}
|
||||
return MaterialApp(
|
||||
title: 'Pipelines',
|
||||
scaffoldMessengerKey: appScaffoldMessengerKey,
|
||||
builder: _scaled,
|
||||
theme: appLightTheme(fontFamily: fontFamily),
|
||||
darkTheme: appDarkTheme(fontFamily: fontFamily),
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import 'app_url_strategy.dart';
|
||||
import 'pipelines_binding.dart';
|
||||
import 'pipelines_root.dart';
|
||||
import 'server_endpoint.dart';
|
||||
import '../features/settings/settings_store.dart';
|
||||
@@ -55,7 +56,7 @@ Future<void> runPipelinesApp({
|
||||
SettingsStore? settingsStore,
|
||||
}) async {
|
||||
useAppUrlStrategy();
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
PipelinesBinding.ensureInitialized();
|
||||
registerAppFontLicenses();
|
||||
// The device's chosen font loads beside the session; a slow download does
|
||||
// not hold the first frame, and applies when it lands.
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
/// The app's root messenger, for messages no screen owns.
|
||||
final GlobalKey<ScaffoldMessengerState> appScaffoldMessengerKey = GlobalKey();
|
||||
|
||||
/// The message for a failed clipboard call [method] ([error]), or null for
|
||||
/// a call whose failure is not the operator's to hear about.
|
||||
///
|
||||
/// The web reports a refused clipboard write or read (no permission, an
|
||||
/// insecure page, a browser without the clipboard API) as an error reply.
|
||||
String? clipboardFailureMessage(String method, PlatformException error) {
|
||||
// The web's own reason ("Clipboard is not available in the context." on a
|
||||
// page that is not secure) helps; its generic "Clipboard.setData failed."
|
||||
// does not.
|
||||
final detail = error.message?.trim() ?? '';
|
||||
final why = detail.isEmpty || detail.startsWith('Clipboard.')
|
||||
? 'the browser refused access to the clipboard'
|
||||
: detail;
|
||||
return switch (method) {
|
||||
'Clipboard.setData' => 'Could not copy: $why',
|
||||
'Clipboard.getData' => 'Could not paste: $why',
|
||||
_ => null,
|
||||
};
|
||||
}
|
||||
|
||||
/// Shows [message] in the app's root messenger; false when there is none.
|
||||
bool showAppMessage(String message) {
|
||||
final messenger = appScaffoldMessengerKey.currentState;
|
||||
if (messenger == null) return false;
|
||||
messenger
|
||||
..hideCurrentSnackBar()
|
||||
..showSnackBar(SnackBar(content: Text(message)));
|
||||
return true;
|
||||
}
|
||||
|
||||
/// A [BinaryMessenger] that reports failed clipboard writes and reads.
|
||||
///
|
||||
/// Every copy in the app (the selection's copy keys and menu, copy buttons,
|
||||
/// the terminal) writes through [Clipboard] on the platform channel, and
|
||||
/// most never look at the result: a refusal would otherwise only reach the
|
||||
/// console. The reply still reaches the caller unchanged.
|
||||
class ClipboardReportingMessenger implements BinaryMessenger {
|
||||
ClipboardReportingMessenger(this._inner, {void Function(String)? report})
|
||||
: _report = report ?? _show;
|
||||
|
||||
final BinaryMessenger _inner;
|
||||
final void Function(String message) _report;
|
||||
|
||||
static void _show(String message) => showAppMessage(message);
|
||||
|
||||
static const _codec = JSONMethodCodec();
|
||||
|
||||
@override
|
||||
Future<ByteData?>? send(String channel, ByteData? message) {
|
||||
final reply = _inner.send(channel, message);
|
||||
if (reply == null ||
|
||||
channel != SystemChannels.platform.name ||
|
||||
message == null) {
|
||||
return reply;
|
||||
}
|
||||
final String method;
|
||||
try {
|
||||
method = _codec.decodeMethodCall(message).method;
|
||||
} on Object {
|
||||
return reply;
|
||||
}
|
||||
if (!method.startsWith('Clipboard.')) return reply;
|
||||
return reply.then((data) {
|
||||
_check(method, data);
|
||||
return data;
|
||||
});
|
||||
}
|
||||
|
||||
void _check(String method, ByteData? data) {
|
||||
if (data == null) return;
|
||||
try {
|
||||
_codec.decodeEnvelope(data);
|
||||
} on PlatformException catch (error) {
|
||||
final message = clipboardFailureMessage(method, error);
|
||||
if (message != null) _report(message);
|
||||
} on Object {
|
||||
// Not a reply this messenger understands; the caller decodes it.
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
// ignore: deprecated_member_use
|
||||
Future<void> handlePlatformMessage(
|
||||
String channel,
|
||||
ByteData? data,
|
||||
PlatformMessageResponseCallback? callback,
|
||||
) =>
|
||||
// ignore: deprecated_member_use
|
||||
_inner.handlePlatformMessage(channel, data, callback);
|
||||
|
||||
@override
|
||||
void setMessageHandler(String channel, MessageHandler? handler) =>
|
||||
_inner.setMessageHandler(channel, handler);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import '../core/keyboard/key_modifier_sync.dart';
|
||||
import 'clipboard_failures.dart';
|
||||
|
||||
/// The app's binding: Flutter's, with clipboard failures reported
|
||||
/// ([ClipboardReportingMessenger]) and, on the web, key events carrying the
|
||||
/// modifiers their browser events hold ([KeyModifierSync]).
|
||||
///
|
||||
/// An entry point calls [ensureInitialized] before anything else creates a
|
||||
/// binding.
|
||||
class PipelinesBinding extends WidgetsFlutterBinding {
|
||||
PipelinesBinding._();
|
||||
|
||||
static bool _created = false;
|
||||
|
||||
/// The binding, created on the first call.
|
||||
static WidgetsBinding ensureInitialized() {
|
||||
if (!_created) {
|
||||
_created = true;
|
||||
PipelinesBinding._();
|
||||
}
|
||||
return WidgetsBinding.instance;
|
||||
}
|
||||
|
||||
@override
|
||||
void initInstances() {
|
||||
super.initInstances();
|
||||
// The services binding hands key data to the framework only once the
|
||||
// keyboard state is synced; the modifier sync goes in front of it then.
|
||||
keyboard.syncKeyboardState().then((_) => installKeyModifierSync());
|
||||
}
|
||||
|
||||
@override
|
||||
BinaryMessenger createBinaryMessenger() =>
|
||||
ClipboardReportingMessenger(super.createBinaryMessenger());
|
||||
}
|
||||
Reference in New Issue
Block a user