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

Use Messenger in more content script places (Native Editor, Dev Tools) #1460

Merged
merged 5 commits into from
Sep 27, 2021

Conversation

fregante
Copy link
Contributor

@fregante fregante commented Sep 24, 2021

Copy link
Contributor Author

@fregante fregante left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Diff best seen without whitespace changes

DETECT_FRAMEWORK_VERSIONS
);
export const withDetectFrameworkVersions = createSendScriptMessage<
FrameworkMeta[]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: This type was changed because withDetectFrameworkVersions had an assertion to FrameworkMeta in the only place where it was used.

queueReactivateTab,
"Reactivation queue failed for some tabs"
);
void forEachTab(queueReactivateTab);
Copy link
Contributor Author

@fregante fregante Sep 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the messenger now supports notifications natively (pixiebrix/webext-messenger#24), notifyTabs was replaced by a simple loop + call of the method, which means the errors are no longer logged together.

Comment on lines -27 to -37
import "@/contentScript/devTools";
import "@/contentScript/contextMenus";
import addContentScriptListener from "@/contentScript/backgroundProtocol";
import { handleNavigate } from "@/contentScript/lifecycle";
import addExecutorListener from "@/contentScript/executor";
import "@/messaging/external";
import "@/contentScript/script";
import "@/vendors/notify";
import { markReady, updateTabInfo } from "@/contentScript/context";
import { initTelemetry } from "@/telemetry/events";
import "@/contentScript/uipath";
Copy link
Contributor Author

@fregante fregante Sep 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the unassigned imports removed by this PR were only used to register the listeners and have been double-checked for other side-effects (but not their sub-dependencies)

import { BlockConfig } from "@/blocks/types";
import { cloneDeep } from "lodash";
import ConsoleLogger from "@/tests/ConsoleLogger";
import { SerializableResponse } from "@/messaging/protocol";

if (isContentScript()) {
addListenerForUpdateSelectedElement();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be the only "active" code and it's been moved to @/contentScript.ts

Comment on lines -329 to -331
if (openerTabId != null) {
console.debug(`Setting opener tabId: ${openerTabId}`);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused, removed

Comment on lines -34 to +39
"QUEUE_REACTIVATE_TAB"
"QUEUE_REACTIVATE_TAB",
{ isNotification: true }
);
export const reactivateTab = getContentScriptMethod("REACTIVATE_TAB");
export const reactivateTab = getContentScriptMethod("REACTIVATE_TAB", {
isNotification: true,
});
Copy link
Contributor Author

@fregante fregante Sep 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These methods were added in #1329 but now they're real "notifications" 🎉

export async function updateDynamicElement({
extensionPoint: extensionPointConfig,
extension: extensionConfig,
}: DynamicDefinition): Promise<void> {
Copy link
Contributor Author

@fregante fregante Sep 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where possible, I also added return values for https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/explicit-module-boundary-types.md

The rule is useful because it ensures we don't change a function’s signature by mistake.

INSTALLED_EXTENSIONS: getInstalledIds,
CHECK_AVAILABLE: checkAvailable,
HANDLE_NAVIGATE: handleNavigate,
SHOW_NOTIFICATION: showNotification,
Copy link
Contributor Author

@fregante fregante Sep 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test report

Seen in the console

  • REACTIVATE_TAB
  • RUN_SINGLE_BLOCK
  • READ_SELECTED
  • DETECT_FRAMEWORKS
  • CLEAR_DYNAMIC_ELEMENTS - seen in console but I'm not sure I saw it working
  • UPDATE_DYNAMIC_ELEMENT
  • ENABLE_OVERLAY - I don't know what this does 🤔
  • DISABLE_OVERLAY
  • INSTALLED_EXTENSIONS
  • CHECK_AVAILABLE
  • HANDLE_NAVIGATE
  • SHOW_NOTIFICATION
  • RUN_READER

Unable to test

  • INSERT_PANEL - behind beta flag?
  • INSERT_BUTTON - behind beta flag?
  • UIPATH_INIT - I'm not sure whether I can use this
  • UIPATH_GET_PROCESSES - Same
  • SEARCH_WINDOW - Unused. It appears in devTools/Locator but that file isn't used anywhere.
  • RUN_READER_BLOCK - unused

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The beta flag you can always fake by hard-coding the check for the beta flag

INSERT_BUTTON: this is what is used when adding a button the add Menu Item / Button flow in the page editor

I'll add the UiPath ones to the testing list for 1.4.0. They have to be tested on Windows with a UiPath local install

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ENABLE_OVERLAY is used to show an overlay over an element you have selected when using SelectorSelectorWidget

@fregante fregante changed the title WIP: Use Messenger in more places (Native Editor, Dev Tools) Use Messenger in more content script places (Native Editor, Dev Tools) Sep 25, 2021
@fregante fregante marked this pull request as ready for review September 25, 2021 19:45
message: "Ran content menu item action",
className: "success",
});
void showNotification(target, "Ran content menu item action", "success");
Copy link
Contributor

@twschiller twschiller Sep 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer not to change the API of the showNotification method. Having multiple arguments of the same type is error prone (if the arguments are swapped, TypeScript won't complain). Also, using the object will allow us to expose more options in the future

Could we go back to the object-based method signature? Alternatively, we could have the message as an argument and then put className in an options object parameter

  • Avoid error-prone method signature

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

multiple arguments of the same type is error prone

Agreed, but this is not the case, className has a union type:

export async function showNotification(
message: string,
className: "error" | "info" | "success"
): Promise<void> {

I reverted the change anyway though

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

argh sorry the commit push had failed somehow and I merged without the change. I included the change in the next PR https://github.com/pixiebrix/pixiebrix-extension/pull/1477/files#diff-660a48b387ef0f402e92201cc396679f79e0a52a43b6e6960f5ff07ef756d5b3

Copy link
Contributor

@twschiller twschiller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fregante see comment about the showNotification API

Otherwise, let's get this merged in so we'll get some days of testing amongst the dev team before the 1.4.0 submission

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants