Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/notifications/attention_host.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';

import '../platform/app_platform.dart';
import '../platform/event_log.dart';
import '../workspace/window_controls.dart';
import 'system_sounds_stub.dart'
if (dart.library.io) 'system_sounds_io.dart'
Expand Down Expand Up @@ -110,7 +111,13 @@ class ChannelAttentionHost implements AttentionHost {
set onOpen(void Function(String? id)? handler) => _onOpen = handler;

Future<Object?> _handle(MethodCall call) async {
if (call.method == 'open') _onOpen?.call(call.arguments as String?);
switch (call.method) {
case 'open':
_onOpen?.call(call.arguments as String?);
// Windows: the tray icon could not go up (Shell_NotifyIcon's error).
case 'trayFailed':
appEvent('tray', 'icon not added: error ${call.arguments}');
}
return null;
}

Expand Down
19 changes: 18 additions & 1 deletion windows/runner/attention.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,13 @@ std::optional<LRESULT> Attention::HandleMessage(HWND window, UINT message,
return std::nullopt;
}
if (tray_) {
::ShowWindow(window, SW_HIDE);
// Hidden only with the icon up to bring it back: with none (it could
// not go up), minimized, its taskbar button left (#1107).
if (!icon_added_ || !IconThere()) {
icon_added_ = false;
ShowIcon();
}
::ShowWindow(window, icon_added_ ? SW_HIDE : SW_MINIMIZE);
return 0;
}
return std::nullopt;
Expand Down Expand Up @@ -557,9 +563,20 @@ void Attention::ShowIcon() {
data.uVersion = NOTIFYICON_VERSION_4;
::Shell_NotifyIconW(NIM_SETVERSION, &data);
} else {
const DWORD error = ::GetLastError();
shown = ::Shell_NotifyIconW(NIM_MODIFY, &data) != FALSE;
if (!shown && tray_ && !told_tray_failed_) {
// In events.log, to find why (#1107).
told_tray_failed_ = true;
channel_->InvokeMethod(
"trayFailed", std::make_unique<flutter::EncodableValue>(
static_cast<int64_t>(error)));
}
}
}
if (shown) {
told_tray_failed_ = false;
}
icon_added_ = shown;
if (tray_) {
::SetTimer(window_, kTrayTimer, kTrayCheckMilliseconds, nullptr);
Expand Down
3 changes: 3 additions & 0 deletions windows/runner/attention.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ class Attention {
// Whether the tray icon is up, and whether Flutter asked for it (it is up
// without, for a notification's sake, until the notification goes).
bool icon_added_ = false;
// Whether Flutter was told the icon could not go up: once, until it does
// (the 15-second check tries again).
bool told_tray_failed_ = false;
std::optional<TrayState> tray_;
HICON icon_ = nullptr;

Expand Down