Skip to content

Commit

Permalink
Improve error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
younesaassila committed Aug 21, 2024
1 parent 1bfed7c commit bb8078d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 19 deletions.
26 changes: 12 additions & 14 deletions src/background/handlers/onResponseStarted.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,21 +87,19 @@ export default async function onResponseStarted(
const stats = streamStatus?.stats ?? { proxied: 0, notProxied: 0 };

if (!proxy) {
let reason = errorMessage ?? streamStatus?.reason ?? "";
if (isChromium) {
try {
const proxySettings = await browser.proxy.settings.get({});
switch (proxySettings.levelOfControl) {
case "controlled_by_other_extensions":
reason = "Proxy settings controlled by other extension";
break;
case "not_controllable":
reason = "Proxy settings not controllable";
break;
}
} catch {}
}
stats.notProxied++;
let reason = errorMessage ?? streamStatus?.reason ?? "";
try {
const proxySettings = await browser.proxy.settings.get({});
switch (proxySettings.levelOfControl) {
case "controlled_by_other_extensions":
reason = "Proxy settings controlled by other extension";
break;
case "not_controllable":
reason = "Proxy settings not controllable";
break;
}
} catch {}
setStreamStatus(channelName, {
proxied: false,
proxyHost: streamStatus?.proxyHost ? streamStatus.proxyHost : undefined,
Expand Down
10 changes: 10 additions & 0 deletions src/content/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import workerScriptURL from "url:../page/worker.ts";
import browser, { Storage } from "webextension-polyfill";
import findChannelFromTwitchTvUrl from "../common/ts/findChannelFromTwitchTvUrl";
import isChromium from "../common/ts/isChromium";
import { getStreamStatus, setStreamStatus } from "../common/ts/streamStatus";
import store from "../store";
import type { State } from "../store/types";
import { MessageType } from "../types";
Expand Down Expand Up @@ -145,6 +146,15 @@ function onPageMessage(event: MessageEvent) {
);
}
break;
case MessageType.MultipleAdBlockersInUse:
const channelName = findChannelFromTwitchTvUrl(location.href);
if (!channelName) break;
const streamStatus = getStreamStatus(channelName);
setStreamStatus(channelName, {
...(streamStatus ?? { proxied: false }),
reason: "Another Twitch ad blocker is in use",
});
break;
case MessageType.ClearStats:
clearStats(message.channelName);
break;
Expand Down
5 changes: 4 additions & 1 deletion src/page/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ window.Worker = class Worker extends NATIVE_WORKER {
// Required for VAFT (>=12.0.0) compatibility.
const isAlreadyHooked = NATIVE_WORKER.toString().includes("twitch");
if (isAlreadyHooked) {
console.error("[TTV LOL PRO] Twitch worker is already hooked.");
console.info("[TTV LOL PRO] Another Twitch ad blocker is in use.");
sendMessageToContentScript({
type: MessageType.MultipleAdBlockersInUse,
});
super(scriptURL, options);
return;
}
Expand Down
5 changes: 1 addition & 4 deletions src/popup/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
import { alpha2 } from "../common/ts/countryCodes";
import findChannelFromTwitchTvUrl from "../common/ts/findChannelFromTwitchTvUrl";
import isChannelWhitelisted from "../common/ts/isChannelWhitelisted";
import isChromium from "../common/ts/isChromium";
import store from "../store";
import type { StreamStatus } from "../types";

Expand Down Expand Up @@ -243,9 +242,7 @@ copyDebugInfoButtonElement.addEventListener("click", async e => {
`- Country: ${status.proxyCountry ?? "N/A"}\n`,
].join("")
: "",
isChromium
? `Proxy level of control: ${proxySettings.levelOfControl}\n`
: "",
`Proxy level of control: ${proxySettings.levelOfControl}\n`,
].join("")
: "",
store.state.adLog.length > 0
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export const enum MessageType {
UsherResponse = "TLP_UsherResponse",
NewPlaybackAccessToken = "TLP_NewPlaybackAccessToken",
NewPlaybackAccessTokenResponse = "TLP_NewPlaybackAccessTokenResponse",
MultipleAdBlockersInUse = "TLP_MultipleAdBlockersInUse",
ClearStats = "TLP_ClearStats",
}

Expand Down

0 comments on commit bb8078d

Please sign in to comment.