diff --git a/src/commands.ts b/src/commands.ts index 30ed20a..d7ef0c6 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -16,6 +16,7 @@ */ import * as deploy_contracts from './contracts'; +import * as deploy_events from './events'; import * as deploy_helpers from './helpers'; import * as deploy_log from './log'; import * as deploy_values from './values'; @@ -186,6 +187,7 @@ export async function reloadCommands(newCfg: deploy_contracts.Configuration) { const CTX: ScriptCommandExecutionContext = { button: btn, command: id, + globalEvents: deploy_events.EVENTS, globals: ME.globals, globalState: GLOBAL_STATE, logger: deploy_log.CONSOLE, diff --git a/src/contracts.ts b/src/contracts.ts index b182d51..e5c786c 100644 --- a/src/contracts.ts +++ b/src/contracts.ts @@ -365,6 +365,10 @@ export interface PlatformItem { * Arguments for a script. */ export interface ScriptArguments { + /** + * Gets the emitter for global extension events. + */ + readonly globalEvents: NodeJS.EventEmitter; /** * Global data. */ diff --git a/src/events.ts b/src/events.ts new file mode 100644 index 0000000..ef37489 --- /dev/null +++ b/src/events.ts @@ -0,0 +1,24 @@ +/** + * This file is part of the vscode-deploy-reloaded distribution. + * Copyright (c) Marcel Joachim Kloubert. + * + * vscode-deploy-reloaded is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, version 3. + * + * vscode-deploy-reloaded is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +import * as Events from 'events'; + + +/** + * Stores the global event emitter. + */ +export const EVENTS: NodeJS.EventEmitter = new Events.EventEmitter(); diff --git a/src/extension.ts b/src/extension.ts index 491f395..9ccc817 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -21,6 +21,7 @@ const CompareVersion = require('compare-versions'); import * as deploy_commands from './commands'; import * as deploy_compare from './compare'; import * as deploy_contracts from './contracts'; +import * as deploy_events from './events'; import * as deploy_gui from './gui'; import * as deploy_helpers from './helpers'; import * as deploy_html from './html'; @@ -652,6 +653,16 @@ async function activateExtension(context: vscode.ExtensionContext) { currentContext = context; }); + // events + WF.next(() => { + context.subscriptions.push({ + dispose: () => { + deploy_events.EVENTS + .removeAllListeners(); + } + }); + }); + // output channel WF.next(() => { context.subscriptions.push( diff --git a/src/plugins.ts b/src/plugins.ts index 8ae5aff..1524aac 100644 --- a/src/plugins.ts +++ b/src/plugins.ts @@ -17,6 +17,7 @@ import * as deploy_clients from './clients'; import * as deploy_contracts from './contracts'; +import * as deploy_events from './events'; import * as deploy_files from './files'; import * as deploy_helpers from './helpers'; import * as deploy_log from './log'; @@ -533,6 +534,7 @@ export abstract class FileToUploadBase implements FileToUpload { ); const CONTEXT: deploy_transformers.DataTransformerContext = { + globalEvents: deploy_events.EVENTS, globals: ME.workspace.globals, globalState: ME.workspace.sessionState['upload']['states']['global'], logger: deploy_log.CONSOLE, diff --git a/src/plugins/script.ts b/src/plugins/script.ts index 24a2621..f888429 100644 --- a/src/plugins/script.ts +++ b/src/plugins/script.ts @@ -16,6 +16,7 @@ */ import * as deploy_contracts from '../contracts'; +import * as deploy_events from '../events'; import * as deploy_files from '../files'; import * as deploy_helpers from '../helpers'; import * as deploy_log from '../log'; @@ -119,6 +120,7 @@ class ScriptPlugin extends deploy_plugins.PluginBase { cancellationToken: undefined, dir: context['dir'], files: context['files'], + globalEvents: deploy_events.EVENTS, globals: context.target.__workspace.globals, globalState: this._GLOBAL_STATE, isCancelling: undefined, diff --git a/src/pull.ts b/src/pull.ts index 2341497..c9e557c 100644 --- a/src/pull.ts +++ b/src/pull.ts @@ -16,6 +16,7 @@ */ import * as deploy_contracts from './contracts'; +import * as deploy_events from './events'; import * as deploy_helpers from './helpers'; import * as deploy_log from './log'; import * as deploy_packages from './packages'; @@ -267,6 +268,7 @@ export async function pullFilesFrom(files: string[], ); const CONTEXT: deploy_transformers.DataTransformerContext = { + globalEvents: deploy_events.EVENTS, globals: ME.globals, globalState: ME.sessionState['pull']['states']['global'], logger: deploy_log.CONSOLE, diff --git a/src/targets/operations/http.ts b/src/targets/operations/http.ts index d68fdf9..0f9c9bc 100644 --- a/src/targets/operations/http.ts +++ b/src/targets/operations/http.ts @@ -16,6 +16,7 @@ */ import * as deploy_contracts from '../../contracts'; +import * as deploy_events from '../../events'; import * as deploy_helpers from '../../helpers'; import * as deploy_http from '../../http'; import * as deploy_log from '../../log'; @@ -202,6 +203,7 @@ export async function execute(context: deploy_targets.TargetOperationExecutionCo getBodyToSend = async () => { const ARGS: HttpBodyModuleExecutionArguments = { context: context, + globalEvents: deploy_events.EVENTS, globals: WORKSPACE.globals, globalState: WORKSPACE.sessionState['target_operations']['http']['global'], logger: deploy_log.CONSOLE, diff --git a/src/targets/operations/script.ts b/src/targets/operations/script.ts index d103bb8..ab3993c 100644 --- a/src/targets/operations/script.ts +++ b/src/targets/operations/script.ts @@ -16,6 +16,7 @@ */ import * as deploy_contracts from '../../contracts'; +import * as deploy_events from '../../events'; import * as deploy_helpers from '../../helpers'; import * as deploy_log from '../../log'; import * as deploy_targets from '../../targets'; @@ -100,6 +101,7 @@ export async function execute(context: deploy_targets.TargetOperationExecutionCo if (EXECUTE) { const ARGS: ScriptTargetOperationExecutionArguments = { context: context, + globalEvents: deploy_events.EVENTS, globals: WORKSPACE.globals, globalState: WORKSPACE.sessionState['target_operations']['script']['global'], logger: deploy_log.CONSOLE, diff --git a/src/workspaces.ts b/src/workspaces.ts index 5e64593..2e67fe2 100644 --- a/src/workspaces.ts +++ b/src/workspaces.ts @@ -260,10 +260,6 @@ export class Workspace extends deploy_objects.DisposableBase implements deploy_c */ protected _startTime: Moment.Moment; private readonly _SWITCH_BUTTONS: TargetWithButton[] = []; - /** - * Stores the states for 'sync when open'. - */ - protected _syncWhenOpenStates: SyncWhenOpenStates; private _targets: deploy_targets.Target[]; /** * The current translation function. @@ -437,6 +433,10 @@ export class Workspace extends deploy_objects.DisposableBase implements deploy_c NEW_SESSION_STATE['pull']['states']['global'] = {}; NEW_SESSION_STATE['pull']['states']['data_transformers'] = {}; + NEW_SESSION_STATE['sync'] = {}; + NEW_SESSION_STATE['sync']['whenOpen'] = {}; + NEW_SESSION_STATE['sync']['whenOpen']['states'] = {}; + NEW_SESSION_STATE['upload'] = {}; NEW_SESSION_STATE['upload']['states'] = {}; NEW_SESSION_STATE['upload']['states']['global'] = {}; @@ -1625,12 +1625,6 @@ export class Workspace extends deploy_objects.DisposableBase implements deploy_c await this.deployOnSave(e.fileName); } - - /** @inheritdoc */ - protected onDispose() { - this._syncWhenOpenStates = null; - } - /** * Gets the name of that workspace. */ @@ -1883,8 +1877,6 @@ export class Workspace extends deploy_objects.DisposableBase implements deploy_c } finalizer = async () => { - ME._syncWhenOpenStates = {}; - // runBuildTaskOnStartup try { await deploy_tasks.runBuildTaskOnStartup @@ -2519,7 +2511,7 @@ export class Workspace extends deploy_objects.DisposableBase implements deploy_c * Gets the states for 'sync when open'. */ public get syncWhenOpenStates(): SyncWhenOpenStates { - return this._syncWhenOpenStates; + return this.sessionState['sync']['whenOpen']['states']; } /** @inheritdoc */