@@ -7,7 +7,6 @@ import { PreferenceActorProxy } from '../firefox/actorProxy/preference';
77import { FirefoxDebugSession } from '../firefoxDebugSession' ;
88import { PopupAutohideEventBody } from '../../common/customEvents' ;
99import { isWindowsPlatform } from '../../common/util' ;
10- import { TargetActorProxy } from '../firefox/actorProxy/target' ;
1110import { DescriptorActorProxy } from '../firefox/actorProxy/descriptor' ;
1211
1312const log = Log . create ( 'AddonManager' ) ;
@@ -21,11 +20,12 @@ export const popupAutohidePreferenceKey = 'ui.popup.disable_autohide';
2120 */
2221export class AddonManager {
2322
23+ private resolveAddonId ! : ( addonId : string ) => void ;
24+ public readonly addonId = new Promise < string > ( resolve => this . resolveAddonId = resolve ) ;
25+
2426 private readonly config : ParsedAddonConfiguration ;
2527
26- private addonAttached = false ;
2728 private descriptorActor : DescriptorActorProxy | undefined = undefined ;
28- private targetActor : TargetActorProxy | undefined = undefined ;
2929
3030 constructor (
3131 private readonly debugSession : FirefoxDebugSession
@@ -41,11 +41,9 @@ export class AddonManager {
4141
4242 const addonPath = isWindowsPlatform ( ) ? path . normalize ( this . config . path ) : this . config . path ;
4343 let result = await addonsActor . installAddon ( addonPath ) ;
44- if ( ! this . config . id ) {
45- this . config . id = result . addon . id ;
46- }
44+ this . resolveAddonId ( result . addon . id ) ;
4745
48- this . fetchAddonsAndAttach ( rootActor ) ;
46+ await this . fetchDescriptor ( rootActor ) ;
4947
5048 if ( this . config . popupAutohideButton ) {
5149 const popupAutohide = ! ( await preferenceActor . getBoolPref ( popupAutohidePreferenceKey ) ) ;
@@ -54,34 +52,29 @@ export class AddonManager {
5452 }
5553
5654 public async reloadAddon ( ) : Promise < void > {
57- if ( ! this . targetActor ) {
55+ if ( ! this . descriptorActor ) {
5856 throw 'Addon isn\'t attached' ;
5957 }
6058
61- await this . descriptorActor ? .reload ( ) ;
59+ await this . descriptorActor . reload ( ) ;
6260 }
6361
64- private async fetchAddonsAndAttach ( rootActor : RootActorProxy ) : Promise < void > {
65-
66- if ( this . addonAttached ) return ;
67-
68- let addons = await rootActor . fetchAddons ( ) ;
69-
70- if ( this . addonAttached ) return ;
71-
72- addons . forEach ( ( addon ) => {
73- if ( addon . id === this . config . id ) {
74- ( async ( ) => {
62+ private async fetchDescriptor ( rootActor : RootActorProxy ) : Promise < void > {
7563
76- this . descriptorActor = new DescriptorActorProxy (
77- addon . actor ,
78- this . debugSession . firefoxDebugConnection
79- ) ;
64+ const addons = await rootActor . fetchAddons ( ) ;
8065
81- await this . debugSession . attachDescriptor ( this . descriptorActor , false ) ;
66+ addons . forEach ( async addon => {
67+ if ( addon . id === await this . addonId ) {
68+ this . descriptorActor = new DescriptorActorProxy (
69+ addon . actor ,
70+ 'webExtension' ,
71+ this . debugSession . firefoxDebugConnection
72+ ) ;
8273
83- this . addonAttached = true ;
84- } ) ( ) ;
74+ if ( ! this . debugSession . processDescriptorMode ) {
75+ const adapter = await this . debugSession . attachDescriptor ( this . descriptorActor ) ;
76+ await adapter . watcherActor . watchResources ( [ 'console-message' , 'error-message' , 'source' , 'thread-state' ] ) ;
77+ }
8578 }
8679 } ) ;
8780 }
0 commit comments