Skip to content

Commit

Permalink
Fix + formatting (#391)
Browse files Browse the repository at this point in the history
  • Loading branch information
remusao authored Jan 16, 2025
1 parent b50bb5c commit 6f50c6f
Show file tree
Hide file tree
Showing 86 changed files with 736 additions and 689 deletions.
2 changes: 1 addition & 1 deletion modules/content-script-tests/sources/content.es
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ registerContentScript({
action1: (...args) =>
WDP.app.modules["content-script-tests"].action(
"getSomeValue",
...args
...args,
),
};
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default function () {
"content-script-tests",
"action1",
{ windowId: tabId },
...args
...args,
);

// Wait for window to exist
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

import {
expect,
sleep,
Events,
} from "../../../tests/core/integration/helpers";
import { expect, sleep, Events } from "../../../tests/core/integration/helpers";

export default function () {
describe.skip("content-script", () => {
Expand All @@ -26,7 +22,7 @@ export default function () {
document.body.dispatchEvent(
new MouseEvent("mousedown", {
bubbles: true,
})
}),
);
}

Expand Down
14 changes: 7 additions & 7 deletions modules/core/sources/app.es
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export default class App {
this.prefchangeEventListener = subscribe(
"prefchange",
this.onPrefChange,
this
this,
);
}

Expand All @@ -184,8 +184,8 @@ export default class App {
console.error("App", "cannot load service", serviceName, e);
throw e;
}
}
)
},
),
);
}

Expand Down Expand Up @@ -213,8 +213,8 @@ export default class App {
const services = {};
const scopedServices = await Promise.all(
module.requiredServices.map((serviceName) =>
this.services[serviceName].moduleFactory(module.name)
)
this.services[serviceName].moduleFactory(module.name),
),
);
module.requiredServices.forEach((serviceName, i) => {
services[serviceName] = scopedServices[i];
Expand All @@ -236,10 +236,10 @@ export default class App {
const allModules = this.moduleList;
const core = allModules.find((x) => x.name === "core");
const modules = allModules.filter(
(x) => x.name !== "core" && shouldEnableModule(x.name)
(x) => x.name !== "core" && shouldEnableModule(x.name),
);
const disabledModules = allModules.filter(
(x) => !shouldEnableModule(x.name)
(x) => !shouldEnableModule(x.name),
);

// all modules start in undefined state
Expand Down
4 changes: 2 additions & 2 deletions modules/core/sources/app/module.es
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class Module extends LifeCycle {
Logger.get("life-cycle", {
level: "log",
prefix: `[lifecycle:${name}]`,
})
}),
);

this._init = (...args) => this.background.init(...args);
Expand All @@ -36,7 +36,7 @@ export default class Module extends LifeCycle {
(serviceName) => {
const initializer = this.background.providesServices[serviceName];
this._services[serviceName] = new Service(initializer);
}
},
);

return this._services;
Expand Down
2 changes: 1 addition & 1 deletion modules/core/sources/app/service.es
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default class Service {
},
(e) => {
this._readyDefer.reject(e);
}
},
);

return this._readyDefer.promise;
Expand Down
2 changes: 1 addition & 1 deletion modules/core/sources/background.es
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export default background({
{ url },
selector,
attribute,
options
options,
);
},

Expand Down
16 changes: 10 additions & 6 deletions modules/core/sources/content.es
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function recordMouseDown(ev, WDP) {
"recordMouseDown",
event,
getContextHTML(ev),
href
href,
);
}

Expand All @@ -90,7 +90,7 @@ function click(selector) {
function queryHTML(
selector,
attribute,
{ shadowRootSelector = null, attributeType = "property" } = {}
{ shadowRootSelector = null, attributeType = "property" } = {},
) {
const root = shadowRootSelector
? window.document.querySelector(shadowRootSelector).shadowRoot
Expand All @@ -112,7 +112,7 @@ function queryHTML(
...hash,
[attr]: getAttr(el, attr),
}),
{}
{},
);
}
return getAttr(el, attribute);
Expand All @@ -130,9 +130,13 @@ registerContentScript({
recordMouseDown(ev, WDP);
};
window.addEventListener("mousedown", throttle(window, onMouseDown, 250));
window.addEventListener("pagehide", () => {
window.removeEventListener("mousedown", onMouseDown);
}, { once: true });
window.addEventListener(
"pagehide",
() => {
window.removeEventListener("mousedown", onMouseDown);
},
{ once: true },
);

// Expose content actions
return {
Expand Down
4 changes: 2 additions & 2 deletions modules/core/sources/content/actions-manager.es
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ class RemoteMessagesBuffer {

return Promise.reject(
new Error(
`content-script actions buffer limit exceeded: ${this.buffer.length} ${this.MAX_BUFFER_LEN}`
)
`content-script actions buffer limit exceeded: ${this.buffer.length} ${this.MAX_BUFFER_LEN}`,
),
);
};
}
Expand Down
2 changes: 1 addition & 1 deletion modules/core/sources/content/console.es
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ export default config.environment === "development"
get() {
return noop;
},
}
},
);
2 changes: 1 addition & 1 deletion modules/core/sources/content/match-patterns.es
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function createHostMatcher(scheme, host) {

if (host[1] !== ".") {
throw new Error(
'<host> only "*" and "*." followed by hostname parts are valid'
'<host> only "*" and "*." followed by hostname parts are valid',
);
}

Expand Down
2 changes: 1 addition & 1 deletion modules/core/sources/content/register.es
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export function registerContentScript(spec) {
) {
console.error(
'"excludeMatches" should either be undefined or an array of match patterns',
spec
spec,
);
return;
}
Expand Down
4 changes: 2 additions & 2 deletions modules/core/sources/content/run.es
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export default function () {
// Inject enabled content-scripts and register content-script actions so that
// background can request actions from them.
contentScriptActions.setActionCallbacks(
runContentScripts(window, chrome, WDP)
runContentScripts(window, chrome, WDP),
);

// Stop listening for messages on window unload
Expand All @@ -108,7 +108,7 @@ export default function () {
() => {
contentScriptActions.unload();
},
{ once: true }
{ once: true },
);
});
}
4 changes: 2 additions & 2 deletions modules/core/sources/crypto/pkcs-conversion.es
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function padIfSigned(array) {
export function exportPublicKey(key) {
const origValues = [key.n, key.e];
const values = origValues.map((x) =>
padIfSigned(fromBase64(fromBase64url(x)))
padIfSigned(fromBase64(fromBase64url(x))),
);
const numBytes = values.reduce((a, x) => a + bytesToEncode(x.length), 0);

Expand All @@ -107,7 +107,7 @@ export function exportPublicKey(key) {
new Uint8Array([
0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01,
0x01, 0x05, 0x00,
])
]),
);
buffer.pushByte(0x03); // BIT STRING
pushLength(buffer, bytesToEncode(numBytes) + 1);
Expand Down
26 changes: 10 additions & 16 deletions modules/core/sources/crypto/utils.es
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

import crypto from "../../platform/crypto";
import {
toBase64,
fromBase64,
toHex,
fromHex,
toUTF8,
} from "../encoding";
import { toBase64, fromBase64, toHex, fromHex, toUTF8 } from "../encoding";

import { exportPublicKey } from "./pkcs-conversion";

Expand Down Expand Up @@ -57,7 +51,7 @@ async function importAESKey(key) {
toArrayBuffer(key, "hex"),
{ name: "AES-GCM", length: 256 },
true,
["encrypt", "decrypt"]
["encrypt", "decrypt"],
);
}

Expand All @@ -71,7 +65,7 @@ async function encryptAES(data, key, iv) {
.then((encrypted) => [
fromArrayBuffer(_iv, "b64"),
fromArrayBuffer(encrypted, "b64"),
])
]),
);
}

Expand All @@ -83,15 +77,15 @@ async function decryptAES(encrypted, key) {
return Promise.resolve()
.then(() => (typeof key === "string" ? importAESKey(key) : key))
.then((importedKey) =>
crypto.subtle.decrypt({ name: "AES-GCM", iv }, importedKey, encryptedMsg)
crypto.subtle.decrypt({ name: "AES-GCM", iv }, importedKey, encryptedMsg),
);
}

async function importRSAKey(
pk,
pub = true,
h = "SHA-256",
algorithm = "RSA-OAEP"
algorithm = "RSA-OAEP",
) {
let uses;
if (pub) {
Expand All @@ -113,7 +107,7 @@ async function importRSAKey(
hash: { name: h },
},
true,
uses
uses,
);
}

Expand All @@ -131,13 +125,13 @@ async function generateRSAKeypair(bits = 2048, hashName = "SHA-256") {
hash: { name: hashName },
},
true,
["sign", "verify"]
["sign", "verify"],
)
.then((key) =>
Promise.all([
crypto.subtle.exportKey("spki", key.publicKey).then(toBase64),
crypto.subtle.exportKey("pkcs8", key.privateKey).then(toBase64),
])
]),
);
}

Expand All @@ -147,8 +141,8 @@ async function signRSA(privateKey, data) {
await crypto.subtle.sign(
{ name: "RSASSA-PKCS1-v1_5", hash: { name: "SHA-256" } },
privateKey,
_data
)
_data,
),
);
}

Expand Down
2 changes: 1 addition & 1 deletion modules/core/sources/decorators.es
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export async function withTimeout(promise, timeoutInMs) {
setTimeout(
() =>
reject(new Error(`Timed out after ${timeoutInMs / 1000} seconds`)),
timeoutInMs
timeoutInMs,
);
});
return await Promise.race([promise, timer]);
Expand Down
6 changes: 3 additions & 3 deletions modules/core/sources/http.es
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export function defaultHttpHandler(
data,
sync,
encoding,
background
background,
) {
const XMLHttpRequest = XMLHttpRequestFactory();
const req = new XMLHttpRequest();
Expand Down Expand Up @@ -204,7 +204,7 @@ export function promiseHttpHandler(method, url, data, timeout, compressedPost) {
`Compressed request to ${url}, bytes saved = ${
dataLength - data.length
} (${((100 * (dataLength - data.length)) / dataLength).toFixed(1)}%)`,
"WDP.httpHandler"
"WDP.httpHandler",
);
httpHandler(
method,
Expand All @@ -214,7 +214,7 @@ export function promiseHttpHandler(method, url, data, timeout, compressedPost) {
timeout,
data,
undefined,
"gzip"
"gzip",
);
} else {
httpHandler(method, url, resolve, reject, timeout, data);
Expand Down
6 changes: 3 additions & 3 deletions modules/core/sources/kord/inject.es
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function ifModuleEnabled(promise) {
"Ignoring disabled module exception while calling action," +
" the following exception can be safely ignored. This log" +
' is only printed in "debug" mode.',
err
err,
);
return Promise.resolve();
}
Expand Down Expand Up @@ -100,13 +100,13 @@ export default {
}
if (!api[prop]) {
throw new Error(
`Could not access '${prop}' from service: ${serviceName}.`
`Could not access '${prop}' from service: ${serviceName}.`,
);
}
return api[prop](...args);
},
}),
{}
{},
),
};

Expand Down
Loading

0 comments on commit 6f50c6f

Please sign in to comment.