1

I am creating an intranet web application using the Angular framework with Typescript.

The application needs to work with the client's machine so I have implemented some COM functionality called using ActiveX technology (we use Internet Explorer so it works fine).

I have 2 functions:

openApp - which copies a file from the server to the local machine

getInstalledVersion - reads version information from the local coy of the file

What I would like to do is after openApp is called I would like to call getInstalledVersion (to get the version info for the newly copied file). Obviously I want to ensure the copy process is complete before I call getInstalledVersion.

This sounds like a case for either wrapping openApp in a Promise, or finding some other way to call getInstalledVersion only once openApp has completed.

Could somebody point me in a direction for how I might achieve this?

Existing code below:

export class AppService implements IAppService {

    private _appServiceClass: any;

    constructor() {
        this._appServiceClass = new ActiveXObject("BeaufortAppStoreClientProcessing.Services.AppServiceJsonWrapper");
    }

    openApp(app: IApp, sourceRootFolder: string, destinationRootFolder: string): void {
        var jsonApp = JSON.stringify(app);
        this._appServiceClass.OpenApp(jsonApp, app.AppType.AppTypeID, sourceRootFolder, destinationRootFolder);

    // Want to call getInstalledVersion here after openApp succeeds.

    }

    getInstalledVersion(app: IApp): string {
        var version: string;
        var appType = app.AppType.AppTypeID;
        switch (appType) {
            case 1:
                var jsonApp = JSON.stringify(app);
                version = this._appServiceClass.GetInstalledVersion(jsonApp).toString();
                break;
            case 2:
                version = "n/a";
                break;
            default:
                version = "Incorrect AppType";
                break;
            }
        return version;
    }
}
The Dumb Radish
  • 886
  • 7
  • 18
  • Does OpenApp (1) return immediately when called, or (2) does it wait for the copy to be completed? If (1), you'll have to enable passing some callback into `OpenApp`, that `OpenApp` will invoke when it is finished, (ideally you might consider an event, but handling ActiveX events in Javascript is a bit of a mess), or poll some property on the ActiveX control within a `setInterval` loop until it succeeds. – Zev Spitz Jun 27 '16 at 19:02
  • It waits for the copy to be finished. In this case I think I can just call the second function afterwards. I have looked into events and yes it seems tricky to handle the COM event in JavaScript. I still have a feeling I can use angular promises but not sure how. Thanks for the pointer. – The Dumb Radish Jun 28 '16 at 10:36
  • I've written a [library](https://github.com/zspitz/activex-js-helpers) that makes it much simpler to handle COM events in Javascript. – Zev Spitz Feb 06 '18 at 00:19

0 Answers0