feat(app): secrets kept out of screenshots on macOS and Windows too

The reading of the full reading's fixes noted that macOS and Windows can
keep a window out of screen captures, which SecretScreen didn't ask.

PlatformScreenGuard now asks the app's window on Android, macOS and
Windows (asksOn), and both apps' runners answer app.halkyon/screen_guard,
counting what shows: macOS's MainFlutterWindow sets sharingType = .none,
Windows' FlutterWindow WDA_EXCLUDEFROMCAPTURE (Windows 10 2004 on;
before, WDA_MONITOR, black in captures). Neither runner was built here
(Linux): to be tried on each system.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
This commit is contained in:
Tizian 「ティツィアーン」 2026-10-21 16:40:43 +02:00
commit b9bf9813c5
Signed by: raisondetredev
GPG key ID: 07F6FCF405488B64

View file

@ -1,5 +1,6 @@
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:material_ui/material_ui.dart';
@ -15,16 +16,29 @@ abstract interface class ScreenGuard() {
Future<void> release();
}
/// [ScreenGuard] through Android's `FLAG_SECURE`, which each app's
/// `MainActivity` sets while any is held (`ScreenGuard.kt`, counting them,
/// as several may show at once); nothing to do elsewhere: iOS has no such
/// flag (its app switcher's picture is covered by [SecretScreen] instead),
/// and desktops none either.
class const PlatformScreenGuard({final bool? android}) implements ScreenGuard {
/// The channel each app's activity answers.
/// [ScreenGuard] through the app's window, which each app's runner keeps
/// out while any is held, counting them, as several may show at once:
/// Android's `FLAG_SECURE` (`ScreenGuard.kt` in its `MainActivity`), macOS's
/// `sharingType = .none` (`MainFlutterWindow.swift`) and Windows'
/// `WDA_EXCLUDEFROMCAPTURE` (`flutter_window.cpp`; from Windows 10 2004 on).
/// Nothing to ask elsewhere: iOS has no such flag (its app switcher's
/// picture is covered by [SecretScreen] instead), and Linux's desktops
/// none either.
class const PlatformScreenGuard({final bool? asks}) implements ScreenGuard {
/// The channel each app's window answers.
static const channel = MethodChannel('app.halkyon/screen_guard');
bool get _android => android ?? Platform.isAndroid;
/// Whether the app's window on [platform] answers [channel].
static bool asksOn(TargetPlatform platform) => switch (platform) {
TargetPlatform.android ||
TargetPlatform.macOS ||
TargetPlatform.windows => true,
TargetPlatform.iOS ||
TargetPlatform.linux ||
TargetPlatform.fuchsia => false,
};
bool get _asks => asks ?? asksOn(defaultTargetPlatform);
@override
Future<void> hold() => _ask('hold');
@ -33,7 +47,7 @@ class const PlatformScreenGuard({final bool? android}) implements ScreenGuard {
Future<void> release() => _ask('release');
Future<void> _ask(String method) async {
if (!_android) {
if (!_asks) {
return;
}
try {