Skip to content
This repository has been archived by the owner on May 22, 2020. It is now read-only.

Commit

Permalink
.31 release (#125)
Browse files Browse the repository at this point in the history
* RUN-3996 fixed a multi-runtime regression (#109)

* V bump.30.2 (#110) (#111)

* RUN-3996 fixed a multi-runtime regression (#109)

* Version bump to 30.2

* RUN-3999 multi runtime tests config update (#112)

* V bump.30.2 (#110)

* RUN-3996 fixed a multi-runtime regression (#109)

* Version bump to 30.2

* RUN-3999 Update multi runtime tests config

* Bug/run 3965 multi runtime cache clearing issue (#114)

* V bump.30.2 (#110)

* RUN-3996 fixed a multi-runtime regression (#109)

* Version bump to 30.2

* RUN-3965 Fix EPERM: operation not permitted

* RUN-3965 Fix some cache folders not deleted issue

* RUN-4017/services (#113)

* passing tests

* made changes

* RUN-4028 -  Async add listener (#115)

* V bump.30.2 (#110)

* RUN-3996 fixed a multi-runtime regression (#109)

* Version bump to 30.2

* some test fixes

* more timeouts in tests

* altered tests to check for awaiting newlistener

* undo unnecessary edit

* fix types of registereventlistener and unregister

* hold, fixed removeAllListeners but need to test

* added some tests

* added testing

* cleanup

* fix prependonce

*  bit more testing

* revert test changes

* changed class name, some cleanup

* make tests match new best practices

* name of test file

* tests cleanup

* back to arrows for tslint

* bind rawsend (#116)

* RUN-4045 register window name early in creation (#117)

* RUN-4033 plugin.import accepts a string (#118)

* Feature/test sledghammer (#119)

* sledghammer approach to fixing tests.

* taking a sledghammer to our Multi runtime tests.

* Moving back to es6 untill we hit a major version.

* A few items from the code review.

* code review items.

* code review items.

* V bump.30.2 (#110) (#121)

* RUN-3996 fixed a multi-runtime regression (#109)

* Version bump to 30.2

* RUN-3898 - External services tests (#120)

* hiold

* hold

* tests for external services re RUN-3898

* clean up

* Test fixed, no longer leaving around runtime (#122)

* test fixed, no longer leaving around runtime

* cleanup

* Fixed issue with the webpack grunt task where it was not reporting the errors correctly (#123)

* Fixed issue with the webpack grunt task where it was not reporting the errors correctly

* Passing error codes instead of arrays.

* version bump. (#124)
  • Loading branch information
rdepena authored May 16, 2018
1 parent 5afc443 commit 42de148
Show file tree
Hide file tree
Showing 47 changed files with 1,045 additions and 504 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
/src/.baseDir.ts
TODO
test/app.json
test/client.json
test/service.json
/docs
cache.dat
/cache
Expand Down
15 changes: 12 additions & 3 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,22 @@ module.exports = function (grunt) {
}
});

//using the node webpack API: https://webpack.js.org/api/node/
//will use Task Error or Warning grunt codes based on webpack results: https://gruntjs.com/exit-codes
grunt.registerTask('webpack', function () {
const done = this.async();
webpack(webpackConfig, (err, stats) => {
if (err || stats.hasErrors()) {
if (err) {
const error = err ? err.message : 'webpack error';
grunt.log.error(error);
done(err);
if (err.details) {
grunt.fail.fatal(err.details, 3);
}
} else if(stats.hasErrors()) {
const info = stats.toJson();
grunt.fail.fatal(info.errors, 3);
} else if(stats.hasWarnings()) {
const info = stats.toJson();
grunt.fail.warn(info.warnings, 6);
} else {
grunt.log.ok('webpack task done');
done();
Expand Down
23 changes: 23 additions & 0 deletions html/client.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<html>
<head>
<title>Service Client</title>
</head>
<body>

<h3>Service Client</h3>

<div id="result"></div>

<script>
fin.desktop.main(async () => {
fin.desktop.InterApplicationBus.subscribe("*", "start", async function(message, uuid, name) {
const client = await fin.desktop.Service.connect({uuid});
client.dispatch('test').then(res => {
fin.desktop.InterApplicationBus.publish("return", res);
})
});
});
</script>

</body>
</html>
24 changes: 24 additions & 0 deletions html/service.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<html>
<head>
<title>Service Provider</title>
</head>
<body>

<h3>Service Provider</h3>

<div id="result"></div>

<script>
fin.desktop.main(async () => {
const provider = await fin.desktop.Service.register();
provider.register('test', () => {
return 'return-test';
});
provider.onConnection(c => {
console.log('connection', c);
});
});
</script>

</body>
</html>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hadouken-js-adapter",
"version": "0.30.2",
"version": "0.31.1",
"license": "Apache-2.0",
"repository": "https://github.com/HadoukenIO/js-adapter",
"main": "./out/src/main.js",
Expand Down
52 changes: 20 additions & 32 deletions src/api/application/application.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Base, Bare, Reply, RuntimeEvent } from '../base';
import { EmitterBase, Bare, Reply, RuntimeEvent } from '../base';
import { Identity } from '../../identity';
import { _Window } from '../window/window';
import { Point } from '../system/point';
Expand Down Expand Up @@ -79,24 +79,11 @@ export default class ApplicationModule extends Bare {
* execute, show/close an application as well as listen to application events.
* @class
*/
export class Application extends Base {
// @ts-ignore: return types incompatible with EventEmitter (this)
export class Application extends EmitterBase {

constructor(wire: Transport, public identity: Identity) {
super(wire);

this.on('removeListener', eventType => {
this.deregisterEventListener(Object.assign({}, this.identity, {
type: eventType,
topic: this.topic
}));
});

this.on('newListener', eventType => {
this.registerEventListener(Object.assign({}, this.identity, {
type: eventType,
topic: this.topic
}));
});
}

protected runtimeEventComparator = (listener: RuntimeEvent): boolean => {
Expand Down Expand Up @@ -311,21 +298,22 @@ export class Application extends Base {

}

// @ts-ignore: return types incompatible with EventEmitter (this)
export interface Application {
on(type: 'closed', listener: (data: Reply<'application', 'closed'>) => void): this;
on(type: 'initialized', listener: (data: Reply<'application', 'initialized'>) => void): this;
on(type: 'connected', listener: (data: Reply<'application', 'connected'>) => void): this;
on(type: 'crashed', listener: (data: Reply<'application', 'crashed'>) => void): this;
on(type: 'error', listener: (data: Reply<'application', 'error'>) => void): this;
on(type: 'not-responding', listener: (data: Reply<'application', 'not-responding'>) => void): this;
on(type: 'out-of-memory', listener: (data: Reply<'application', 'out-of-memory'>) => void): this;
on(type: 'responding', listener: (data: Reply<'application', 'responding'>) => void): this;
on(type: 'started', listener: (data: Reply<'application', 'started'>) => void): this;
on(type: 'run-requested', listener: (data: Reply<'application', 'run-requested'>) => void): this;
on(type: 'window-navigation-rejected', listener: (data: NavigationRejectedReply) => void): this;
on(type: 'window-created', listener: (data: Reply<'application', 'window-created'>) => void): this;
on(type: 'window-closed', listener: (data: Reply<'application', 'window-closed'>) => void): this;
on(type: 'tray-icon-clicked', listener: (data: TrayIconClickReply) => void): this;
on(type: 'removeListener', listener: (eventType: string) => void): this;
on(type: 'newListener', listener: (eventType: string) => void): this;
on(type: 'closed', listener: (data: Reply<'application', 'closed'>) => void): Promise<void>;
on(type: 'initialized', listener: (data: Reply<'application', 'initialized'>) => void): Promise<void>;
on(type: 'connected', listener: (data: Reply<'application', 'connected'>) => void): Promise<void>;
on(type: 'crashed', listener: (data: Reply<'application', 'crashed'>) => void): Promise<void>;
on(type: 'error', listener: (data: Reply<'application', 'error'>) => void): Promise<void>;
on(type: 'not-responding', listener: (data: Reply<'application', 'not-responding'>) => void): Promise<void>;
on(type: 'out-of-memory', listener: (data: Reply<'application', 'out-of-memory'>) => void): Promise<void>;
on(type: 'responding', listener: (data: Reply<'application', 'responding'>) => void): Promise<void>;
on(type: 'started', listener: (data: Reply<'application', 'started'>) => void): Promise<void>;
on(type: 'run-requested', listener: (data: Reply<'application', 'run-requested'>) => void): Promise<void>;
on(type: 'window-navigation-rejected', listener: (data: NavigationRejectedReply) => void): Promise<void>;
on(type: 'window-created', listener: (data: Reply<'application', 'window-created'>) => void): Promise<void>;
on(type: 'window-closed', listener: (data: Reply<'application', 'window-closed'>) => void): Promise<void>;
on(type: 'tray-icon-clicked', listener: (data: TrayIconClickReply) => void): Promise<void>;
on(type: 'removeListener', listener: (eventType: string) => void): Promise<void>;
on(type: 'newListener', listener: (eventType: string) => void): Promise<void>;
}
106 changes: 99 additions & 7 deletions src/api/base.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import Transport, { Message } from '../transport/transport';
import { Identity } from '../identity';
import { EventEmitter } from 'events';
import { promiseMap } from '../util/promises';

export interface RuntimeEvent extends Identity {
topic: string;
type: string;
type: string|symbol;
}

export class Bare extends EventEmitter {
Expand Down Expand Up @@ -32,8 +33,6 @@ export class Bare extends EventEmitter {
}

export class Base extends Bare {
protected identity: Identity;

constructor(wire: Transport) {
super(wire);
wire.registerMessageHandler(this.onmessage.bind(this));
Expand All @@ -57,19 +56,20 @@ export class Base extends Bare {
}
}

protected registerEventListener = (listener: RuntimeEvent): void => {
protected registerEventListener = (listener: RuntimeEvent): Promise<void | Message<void>> => {
const key = createKey(listener);
const refCount = this.wire.topicRefMap.get(key);

if (!refCount) {
this.wire.topicRefMap.set(key, 1);
this.wire.sendAction('subscribe-to-desktop-event', listener);
return this.wire.sendAction('subscribe-to-desktop-event', listener);
} else {
this.wire.topicRefMap.set(key, refCount + 1);
return Promise.resolve();
}
}

protected deregisterEventListener = (listener: RuntimeEvent): void => {
protected deregisterEventListener = (listener: RuntimeEvent): Promise<void | Message<void>> => {
const key = createKey(listener);
const refCount = this.wire.topicRefMap.get(key);

Expand All @@ -79,12 +79,104 @@ export class Base extends Bare {
this.wire.topicRefMap.set(key, newRefCount);

if (newRefCount === 0) {
this.wire.sendAction('unsubscribe-to-desktop-event', listener);
return this.wire.sendAction('unsubscribe-to-desktop-event', listener);
}
return Promise.resolve();
}
}

}

// @ts-ignore: return types incompatible with EventEmitter (this)
export class EmitterBase extends Base {
protected identity: Identity;
// @ts-ignore: return types incompatible with EventEmitter (this)
public on(eventType: string, listener: (...args: any[]) => void): Promise<void> {
super.on(eventType, listener);
return this.registerEventListener(Object.assign({}, this.identity, {
type: eventType,
topic: this.topic
})).then(() => undefined);
}
// @ts-ignore: return types incompatible with EventEmitter (this)
public addListener = this.on;
//@ts-ignore: return types incompatible with EventEmitter (this)
public once(eventType: string, listener: (...args: any[]) => void): Promise<void> {
super.once(eventType, listener);
const deregister = () => {
this.deregisterEventListener(Object.assign({}, this.identity, {
type: eventType,
topic: this.topic
}));
};
super.once(eventType, deregister);
return this.registerEventListener(Object.assign({}, this.identity, {
type: eventType,
topic: this.topic
})).then(() => undefined);
}
// @ts-ignore: return types incompatible with EventEmitter (this)
public prependListener(eventType: string, listener: (...args: any[]) => void): Promise<void> {
super.prependListener(eventType, listener);
return this.registerEventListener(Object.assign({}, this.identity, {
type: eventType,
topic: this.topic
})).then(() => undefined);
}
// @ts-ignore: return types incompatible with EventEmitter (this)
public prependOnceListener(eventType: string, listener: (...args: any[]) => void): Promise<void> {
super.prependOnceListener(eventType, listener);
const deregister = () => {
this.deregisterEventListener(Object.assign({}, this.identity, {
type: eventType,
topic: this.topic
}));
};
super.once(eventType, deregister);
return this.registerEventListener(Object.assign({}, this.identity, {
type: eventType,
topic: this.topic
})).then(() => undefined);
}
// @ts-ignore: return types incompatible with EventEmitter (this)
public removeListener(eventType: string, listener: (...args: any[]) => void): Promise<void> {
super.removeListener(eventType, listener);
return this.deregisterEventListener(Object.assign({}, this.identity, {
type: eventType,
topic: this.topic
})).then(() => undefined);
}

protected deregisterAllListeners = (eventType: string|symbol): Promise<void | Message<void>> => {
const runtimeEvent = Object.assign({}, this.identity, {
type: eventType,
topic: this.topic
});
const key = createKey(runtimeEvent);
const refCount = this.wire.topicRefMap.get(key);

if (refCount) {
this.wire.topicRefMap.delete(key);
return this.wire.sendAction('unsubscribe-to-desktop-event', runtimeEvent);
} else {
return Promise.resolve();
}
}
// @ts-ignore: return types incompatible with EventEmitter (this)
public async removeAllListeners(eventType?: string): Promise<void> {

const removeByEvent = (event: string|symbol): Promise<void> => {
super.removeAllListeners(event);
return this.deregisterAllListeners(event).then(() => undefined);
};

if (eventType) {
return removeByEvent(eventType);
} else {
const events = this.eventNames();
await promiseMap(events, removeByEvent);
}
}
}

export class Reply<TOPIC extends string, TYPE extends string | void> implements Identity {
Expand Down
28 changes: 8 additions & 20 deletions src/api/external-application/external-application.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Bare, Base, Reply } from '../base';
import { Bare, EmitterBase, Reply } from '../base';
import { Identity } from '../../identity';
import Transport from '../../transport/transport';

Expand All @@ -23,24 +23,11 @@ export default class ExternalApplicationModule extends Bare {
* well as listen to application events.
* @class
*/
export class ExternalApplication extends Base {
// @ts-ignore: return types incompatible with EventEmitter (this)
export class ExternalApplication extends EmitterBase {

constructor(wire: Transport, public identity: Identity) {
super(wire);

this.on('removeListener', eventType => {
this.deregisterEventListener(Object.assign({}, this.identity, {
type: eventType,
topic : this.topic
}));
});

this.on('newListener', eventType => {
this.registerEventListener(Object.assign({}, this.identity, {
type: eventType,
topic : this.topic
}));
});
}

/**
Expand All @@ -53,9 +40,10 @@ export class ExternalApplication extends Base {
}
}

// @ts-ignore: return types incompatible with EventEmitter (this)
export interface ExternalApplication {
on(type: 'connected', listener: (data: Reply<'externalapplication', 'connected'>) => void): this;
on(type: 'disconnected', listener: (data: Reply<'externalapplication', 'disconnected'>) => void): this;
on(type: 'removeListener', listener: (eventType: string) => void): this;
on(type: 'newListener', listener: (eventType: string) => void): this;
on(type: 'connected', listener: (data: Reply<'externalapplication', 'connected'>) => void): Promise<void>;
on(type: 'disconnected', listener: (data: Reply<'externalapplication', 'disconnected'>) => void): Promise<void>;
on(type: 'removeListener', listener: (eventType: string) => void): Promise<void>;
on(type: 'newListener', listener: (eventType: string) => void): Promise<void>;
}
3 changes: 3 additions & 0 deletions src/api/fin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Clipbpard from './clipboard/clipboard';
import ExternalApplication from './external-application/external-application';
import _FrameModule from './frame/frame';
import Plugin from './plugin/plugin';
import { Service } from './services';

export default class Fin extends Bare {
public System: System;
Expand All @@ -20,6 +21,7 @@ export default class Fin extends Bare {
public ExternalApplication: ExternalApplication;
public Frame: _FrameModule;
public Plugin: Plugin;
public Service: Service;

constructor(wire: Transport, public token: string) {
super(wire);
Expand All @@ -32,6 +34,7 @@ export default class Fin extends Bare {
this.ExternalApplication = new ExternalApplication(wire);
this.Frame = new _FrameModule(wire);
this.Plugin = new Plugin(wire);
this.Service = new Service(wire);

//Handle disconnect events
wire.on('disconnected', () => {
Expand Down
Loading

0 comments on commit 42de148

Please sign in to comment.