Skip to content

Commit

Permalink
feat: add popup UI, change ext icon with background script, handle ho…
Browse files Browse the repository at this point in the history
…st app reload for devtools page
  • Loading branch information
maitrungduc1410 committed Jun 2, 2023
1 parent 6d39726 commit d2e97d5
Show file tree
Hide file tree
Showing 43 changed files with 335 additions and 445 deletions.
35 changes: 16 additions & 19 deletions manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ const manifest: chrome.runtime.ManifestV3 = {
version: packageJson.version,
description: packageJson.description,
// options_page: "src/pages/options/index.html",
// background: {
// service_worker: "src/pages/background/index.js",
// type: "module",
// },
// action: {
// default_popup: "src/pages/popup/index.html",
// default_icon: "icon-34.png",
// },
background: {
service_worker: "src/pages/background/index.js",
type: "module",
},
action: {
default_popup: "src/pages/popup/index.html",
default_icon: "icon32_black.png",
},
// chrome_url_overrides: {
// newtab: "src/pages/newtab/index.html",
// },
Expand All @@ -27,24 +27,21 @@ const manifest: chrome.runtime.ManifestV3 = {
"128": "icon128.png",
},
content_scripts: [
// {
// matches: ["http://*/*", "https://*/*", "<all_urls>"],
// js: ["src/pages/content/index.js"],
// // KEY for cache invalidation
// css: ["assets/css/contentStyle<KEY>.chunk.css"],
// },
{
matches: ["http://*/*", "https://*/*", "<all_urls>"],
js: ["src/pages/content/index.js"],
css: [],
// KEY for cache invalidation
// css: ["assets/css/contentStyle<KEY>.chunk.css"],
},
],
devtools_page: "src/pages/devtools/index.html",
web_accessible_resources: [
{
resources: [
"assets/js/*.js",
"assets/css/*.css",
"icon-16.png",
"icon-19.png",
"icon-38.png",
"icon-48.png",
"icon-128.png",
"src/pages/detector/index.js",
],
matches: ["*://*/*"],
},
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "konva-inspector",
"version": "0.0.2",
"version": "0.0.4",
"description": "Devtools for your Konva App",
"license": "MIT",
"repository": {
Expand All @@ -23,19 +23,19 @@
},
"devDependencies": {
"@rollup/plugin-typescript": "^8.5.0",
"@testing-library/react": "13.4.0",
"@types/chrome": "0.0.224",
"@testing-library/react": "^13.4.0",
"@types/chrome": "^0.0.224",
"@types/jest": "29.0.3",
"@types/node": "18.15.11",
"@types/react": "18.0.21",
"@types/react-dom": "18.0.11",
"@types/ws": "^8.5.4",
"@typescript-eslint/eslint-plugin": "5.56.0",
"@typescript-eslint/eslint-plugin": "^5.56.0",
"@typescript-eslint/parser": "5.38.1",
"@vitejs/plugin-react": "2.2.0",
"chokidar": "^3.5.3",
"cross-env": "^7.0.3",
"eslint": "8.36.0",
"eslint": "^8.36.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "4.2.1",
"eslint-plugin-react": "7.32.2",
Expand All @@ -46,7 +46,7 @@
"prettier": "2.8.8",
"rollup": "2.79.1",
"sass": "1.55.0",
"ts-jest": "29.0.2",
"ts-jest": "^29.0.2",
"ts-loader": "9.4.2",
"typescript": "4.8.3",
"vite": "3.1.3",
Expand Down
Binary file added public/icon128_black.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/icon16_black.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/icon32_black.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/icon48_black.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/konva_logo_black.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/konva_logo_blue.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/assets/images/check-mark-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/images/icon128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions src/pages/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,12 @@ reloadOnUpdate("pages/background");
reloadOnUpdate("pages/content/style.scss");

console.log("background loaded");

chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
if (message.type === "__KONVA_DEVTOOLS__BROADCAST_RESULT") {
chrome.action.setIcon({
path: `../../../icon32${!message.result ? "_black" : ""}.png`,
tabId: sender.tab.id,
});
}
});
15 changes: 0 additions & 15 deletions src/pages/content/components/Demo/app.test.tsx

This file was deleted.

9 changes: 0 additions & 9 deletions src/pages/content/components/Demo/app.tsx

This file was deleted.

11 changes: 0 additions & 11 deletions src/pages/content/components/Demo/index.tsx

This file was deleted.

15 changes: 15 additions & 0 deletions src/pages/content/detector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type Konva from "konva";

declare global {
interface Window {
Konva: typeof Konva;
}
}

document.addEventListener("__KONVA_DEVTOOLS__DETECT_KONVA", function (e) {
document.dispatchEvent(
new CustomEvent("__KONVA_DEVTOOLS__DETECTION_RESULT", {
detail: !!window.Konva,
})
);
});
43 changes: 37 additions & 6 deletions src/pages/content/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,38 @@
console.log("content loaded");
let lastResult = false;

/**
* @description
* Chrome extensions don't support modules in content scripts.
*/
import("./components/Demo");
detect();
const interval = setInterval(detect, 5000);

function detect() {
try {
const s = document.createElement("script");
s.src = chrome.runtime.getURL("src/pages/detector/index.js");
document.body.appendChild(s);
s.onload = () => {
document.addEventListener(
"__KONVA_DEVTOOLS__DETECTION_RESULT",
function (e: CustomEvent) {
lastResult = e.detail;

chrome.runtime.sendMessage({
type: "__KONVA_DEVTOOLS__BROADCAST_RESULT",
result: lastResult,
});
s.remove();
}
);

document.dispatchEvent(new CustomEvent("__KONVA_DEVTOOLS__DETECT_KONVA"));
};
} catch (error) {
clearInterval(interval);
console.log(error);
}
}

chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
if (request["type"] == "__KONVA_DEVTOOLS__REQUEST_DETECTION") {
sendResponse(lastResult);
}
return true; // this make sure sendResponse will work asynchronously
});
3 changes: 0 additions & 3 deletions src/pages/content/style.scss

This file was deleted.

2 changes: 1 addition & 1 deletion src/pages/devtools/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="ko">
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Devtools</title>
Expand Down
38 changes: 0 additions & 38 deletions src/pages/newtab/Newtab.css

This file was deleted.

10 changes: 0 additions & 10 deletions src/pages/newtab/Newtab.scss

This file was deleted.

26 changes: 0 additions & 26 deletions src/pages/newtab/Newtab.tsx

This file was deleted.

13 changes: 0 additions & 13 deletions src/pages/newtab/index.css

This file was deleted.

12 changes: 0 additions & 12 deletions src/pages/newtab/index.html

This file was deleted.

18 changes: 0 additions & 18 deletions src/pages/newtab/index.tsx

This file was deleted.

8 changes: 0 additions & 8 deletions src/pages/options/Options.css

This file was deleted.

8 changes: 0 additions & 8 deletions src/pages/options/Options.tsx

This file was deleted.

Empty file removed src/pages/options/index.css
Empty file.
12 changes: 0 additions & 12 deletions src/pages/options/index.html

This file was deleted.

Loading

0 comments on commit d2e97d5

Please sign in to comment.