Skip to content

Commit 501bb7c

Browse files
authored
window - improved notify on focus (microsoft#255973)
1 parent f6545f3 commit 501bb7c

File tree

2 files changed

+20
-27
lines changed

2 files changed

+20
-27
lines changed

src/vs/platform/windows/electron-main/windowImpl.ts

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { DeferredPromise, RunOnceScheduler, timeout, Delayer } from '../../../ba
88
import { CancellationToken } from '../../../base/common/cancellation.js';
99
import { toErrorMessage } from '../../../base/common/errorMessage.js';
1010
import { Emitter, Event } from '../../../base/common/event.js';
11-
import { Disposable, IDisposable, MutableDisposable } from '../../../base/common/lifecycle.js';
11+
import { Disposable, DisposableStore, IDisposable, MutableDisposable, toDisposable } from '../../../base/common/lifecycle.js';
1212
import { FileAccess, Schemas } from '../../../base/common/network.js';
1313
import { getMarks, mark } from '../../../base/common/performance.js';
1414
import { isBigSurOrNewer, isLinux, isMacintosh, isWindows } from '../../../base/common/platform.js';
@@ -173,7 +173,7 @@ export abstract class BaseWindow extends Disposable implements IBaseWindow {
173173
this.dispose();
174174
}));
175175
this._register(Event.fromNodeEventEmitter(win, 'focus')(() => {
176-
this.clearFocusNotificationBadge();
176+
this.clearNotifyFocus();
177177

178178
this._lastFocusTime = Date.now();
179179
}));
@@ -347,23 +347,7 @@ export abstract class BaseWindow extends Disposable implements IBaseWindow {
347347
break;
348348

349349
case FocusMode.Notify:
350-
if (isMacintosh) {
351-
this.showFocusNotificationBadge();
352-
353-
// On macOS we have direct API to bounce the dock icon
354-
electron.app.dock?.bounce('informational');
355-
} else if (isWindows) {
356-
this.showFocusNotificationBadge();
357-
358-
// On Windows, calling focus() will bounce the taskbar icon
359-
// https://github.com/electron/electron/issues/2867
360-
this.win?.focus();
361-
} else if (isLinux) {
362-
this.showFocusNotificationBadge();
363-
364-
// On Linux, there seems to be no way to bounce the taskbar icon
365-
// as calling focus() will actually steal focus away.
366-
}
350+
this.showNotifyFocus();
367351
break;
368352

369353
case FocusMode.Force:
@@ -375,16 +359,26 @@ export abstract class BaseWindow extends Disposable implements IBaseWindow {
375359
}
376360
}
377361

378-
private readonly focusNotificationBadgeDisposable = this._register(new MutableDisposable());
362+
private readonly notifyFocusDisposable = this._register(new MutableDisposable());
363+
364+
private showNotifyFocus(): void {
365+
const disposables = new DisposableStore();
366+
this.notifyFocusDisposable.value = disposables;
367+
368+
// Badge
369+
disposables.add(DockBadgeManager.INSTANCE.acquireBadge(this));
379370

380-
private showFocusNotificationBadge(): void {
381-
if (!this.focusNotificationBadgeDisposable.value) {
382-
this.focusNotificationBadgeDisposable.value = DockBadgeManager.INSTANCE.acquireBadge(this);
371+
// Flash/Bounce
372+
if (isWindows) {
373+
this.win?.flashFrame(true);
374+
disposables.add(toDisposable(() => this.win?.flashFrame(false)));
375+
} else if (isMacintosh) {
376+
electron.app.dock?.bounce('informational');
383377
}
384378
}
385379

386-
private clearFocusNotificationBadge(): void {
387-
this.focusNotificationBadgeDisposable.clear();
380+
private clearNotifyFocus(): void {
381+
this.notifyFocusDisposable.clear();
388382
}
389383

390384
private doFocusWindow() {

src/vs/workbench/contrib/chat/browser/chatContentParts/chatConfirmationWidget.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,7 @@ abstract class BaseChatConfirmationWidget extends Disposable {
204204
const title = renderStringAsPlaintext(this.title);
205205
const notification = await dom.triggerNotification(title ? localize('notificationTitle', "Chat: {0}", title) : localize('defaultTitle', "Chat: Confirmation Required"),
206206
{
207-
detail: localize('notificationDetail', "The current chat session requires your confirmation to proceed."),
208-
sticky: true
207+
detail: localize('notificationDetail', "The current chat session requires your confirmation to proceed.")
209208
}
210209
);
211210
if (notification) {

0 commit comments

Comments
 (0)