@@ -54,6 +54,8 @@ function logUpdated(...args) {
54
54
internalLogger ( 'common/tabs-update' , ...args ) ;
55
55
}
56
56
57
+ let mAppIsActive = false ;
58
+
57
59
export function init ( ) {
58
60
browser . tabs . onActivated . addListener ( onActivated ) ;
59
61
browser . tabs . onUpdated . addListener ( onUpdated ) ;
@@ -65,6 +67,10 @@ export function init() {
65
67
browser . tabs . onDetached . addListener ( onDetached ) ;
66
68
browser . windows . onCreated . addListener ( onWindowCreated ) ;
67
69
browser . windows . onRemoved . addListener ( onWindowRemoved ) ;
70
+
71
+ browser . windows . getAll ( { } ) . then ( windows => {
72
+ mAppIsActive = windows . some ( window => window . focused ) ;
73
+ } ) ;
68
74
}
69
75
70
76
let mPromisedStartedResolver ;
@@ -324,6 +330,7 @@ async function onNewTabTracked(tab, info) {
324
330
const duplicatedInternally = window . duplicatingTabsCount > 0 ;
325
331
const maybeOrphan = window . toBeOpenedOrphanTabs > 0 ;
326
332
const activeTab = Tab . getActiveTab ( window . id ) ;
333
+ const fromExternalApplication = ! mAppIsActive ;
327
334
328
335
// New tab's index can become invalid because the value of "index" is same to
329
336
// the one given to browser.tabs.create() (new tab) or the original index
@@ -354,7 +361,8 @@ async function onNewTabTracked(tab, info) {
354
361
positionedBySelf,
355
362
mayBeReplacedWithContainer,
356
363
maybeOrphan,
357
- activeTab
364
+ activeTab,
365
+ fromExternalApplication
358
366
} ) ;
359
367
360
368
if ( Tab . needToWaitTracked ( tab . windowId , { exceptionTabId : tab . id } ) )
@@ -462,7 +470,8 @@ async function onNewTabTracked(tab, info) {
462
470
restored,
463
471
duplicated,
464
472
duplicatedInternally,
465
- activeTab
473
+ activeTab,
474
+ fromExternalApplication
466
475
} ) ;
467
476
// don't do await if not needed, to process things synchronously
468
477
if ( moved instanceof Promise )
@@ -506,7 +515,8 @@ async function onNewTabTracked(tab, info) {
506
515
duplicated,
507
516
duplicatedInternally,
508
517
originalTab : duplicated && Tab . get ( uniqueId . originalTabId ) ,
509
- treeForActionDetection
518
+ treeForActionDetection,
519
+ fromExternalApplication
510
520
} ) ;
511
521
tab . $TST . resolveOpened ( ) ;
512
522
@@ -967,3 +977,7 @@ async function onWindowRemoved(windowId) {
967
977
}
968
978
}
969
979
980
+
981
+ browser . windows . onFocusChanged . addListener ( windowId => {
982
+ mAppIsActive = windowId > 0 ;
983
+ } ) ;
0 commit comments