Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix proxy this for emittery #196

Merged
merged 4 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ jobs:
uses: actions/checkout@v3

- name: Install nix
uses: cachix/install-nix-action@v19
uses: cachix/install-nix-action@v22
with:
install_url: https://releases.nixos.org/nix/nix-2.13.3/install
install_url: https://releases.nixos.org/nix/nix-2.17.0/install

- name: Set up cachix
uses: cachix/cachix-action@v12
Expand Down
9 changes: 9 additions & 0 deletions src/api/app-agent/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ export class AppAgentWebsocket implements AppAgentClient {
this.appWebsocket = appWebsocket;
this.emitter = new Emittery<AppAgentEvents>();

// Ensure all super methods are bound to this instance because Emittery relies on `this` being the instance.
// Please retain until the upstream is fixed https://github.com/sindresorhus/emittery/issues/86.
Object.getOwnPropertyNames(Emittery.prototype).forEach((name) => {
const to_bind = (this.emitter as unknown as {[key: string]: unknown})[name];
if (typeof to_bind === 'function') {
(this.emitter as unknown as {[key: string]: unknown})[name] = to_bind.bind(this.emitter);
}
});

const env = getLauncherEnvironment();
this.installedAppId = env?.INSTALLED_APP_ID || installedAppId;

Expand Down
9 changes: 9 additions & 0 deletions src/api/app/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ export class AppWebsocket extends Emittery implements AppApi {
overrideInstalledAppId?: InstalledAppId
) {
super();
// Ensure all super methods are bound to this instance because Emittery relies on `this` being the instance.
// Please retain until the upstream is fixed https://github.com/sindresorhus/emittery/issues/86.
Object.getOwnPropertyNames(Emittery.prototype).forEach((name) => {
const to_bind = (this as unknown as {[key: string]: unknown})[name];
if (typeof to_bind === 'function') {
(this as unknown as {[key: string]: unknown})[name] = to_bind.bind(this);
}
});

this.client = client;
this.defaultTimeout =
defaultTimeout === undefined ? DEFAULT_TIMEOUT : defaultTimeout;
Expand Down