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

Replace content script notifications #2102

Merged
merged 11 commits into from
Dec 13, 2021
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
53 changes: 38 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@
"lodash-es": "^4.17.21",
"marked": "^4.0.3",
"mustache": "^4.2.0",
"notifyjs-browser": "^0.4.2",
"nunjucks": "^3.2.3",
"object-hash": "^2.2.0",
"one-mutation": "^2.0.0",
Expand All @@ -104,6 +103,7 @@
"react-beautiful-dnd": "^13.1.0",
"react-bootstrap": "^1.6.1",
"react-dom": "^17.0.2",
"react-hot-toast": "^2.1.1",
"react-hotkeys": "^2.0.0",
"react-json-tree": "^0.15.0",
"react-outside-click-handler": "^1.3.0",
Expand Down
5 changes: 2 additions & 3 deletions src/background/contextMenus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,19 @@ async function dispatchMenu(
});
void showNotification(target, {
message: "Ran content menu item action",
className: "success",
type: "success",
});
} catch (error) {
if (hasCancelRootCause(error)) {
void showNotification(target, {
message: "The action was cancelled",
className: "info",
});
} else {
const message = `Error handling context menu action: ${getErrorMessage(
error
)}`;
reportError(new Error(message));
void showNotification(target, { message, className: "error" });
void showNotification(target, { message, type: "error" });
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/contentScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ import registerBuiltinBlocks from "@/blocks/registerBuiltinBlocks";
import registerContribBlocks from "@/contrib/registerContribBlocks";
import { handleNavigate } from "@/contentScript/lifecycle";
import "@/messaging/external";
import "@/vendors/notify";
import { markReady, updateTabInfo } from "@/contentScript/context";
import { initTelemetry } from "@/telemetry/events";
import { markTabAsReady, whoAmI } from "@/background/messenger/api";
import { showConnectionLost } from "@/contentScript/connection";
import { isConnectionError } from "@/errors";
import { ENSURE_CONTENT_SCRIPT_READY } from "@/messaging/constants";
import { addListenerForUpdateSelectedElement } from "@/devTools/getSelectedElement";
import { initToaster } from "@/contentScript/notify";

const PIXIEBRIX_SYMBOL = Symbol.for("pixiebrix-content-script");
const uuid = uuidv4();
Expand Down Expand Up @@ -63,6 +63,7 @@ declare global {
async function init(): Promise<void> {
addListenerForUpdateSelectedElement();
initTelemetry();
initToaster();

const sender = await whoAmI();

Expand Down
36 changes: 9 additions & 27 deletions src/contentScript/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,19 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { NotificationCallbacks } from "@/contentScript/notify";
import { hideNotification, showNotification } from "@/contentScript/notify";

let _hooks: NotificationCallbacks = null;
const id = "connection-lost";

export function showConnectionLost(): void {
if (_hooks) {
// Don't show connection notification if it's already being displayed
return null;
}

const element = $.notify(
"Connection to PixieBrix lost. Please reload the page",
{
autoHide: false,
clickToHide: false,
className: "error",
}
);

const $element = $(element);

_hooks = {
hide: () => {
$element.trigger("notify-hide");
},
};
showNotification({
id,
message: "Connection to PixieBrix lost. Please reload the page",
type: "error",
duration: Number.POSITIVE_INFINITY,
});
}

export function hideConnectionLost(): void {
if (_hooks) {
_hooks.hide();
_hooks = null;
}
hideNotification(id);
}
100 changes: 0 additions & 100 deletions src/contentScript/notify.ts

This file was deleted.

Loading