mirror of
https://github.com/jambonz/chrome-extension-dialer.git
synced 2026-10-04 02:04:28 +00:00
fix open phone window by clicking to chrome extension icon
This commit is contained in:
@@ -4,8 +4,10 @@
|
|||||||
"name": "Webrtc Chrome Extension",
|
"name": "Webrtc Chrome Extension",
|
||||||
"description": "Webrtc Chrome Extension",
|
"description": "Webrtc Chrome Extension",
|
||||||
"action": {
|
"action": {
|
||||||
"default_popup": "js/index.html",
|
|
||||||
"default_title": "Webrtc Chrome Extension"
|
"default_title": "Webrtc Chrome Extension"
|
||||||
},
|
},
|
||||||
|
"background": {
|
||||||
|
"service_worker": "background/index.js"
|
||||||
|
},
|
||||||
"permissions": ["activeTab", "storage"]
|
"permissions": ["activeTab", "storage"]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import React from "react";
|
|||||||
import "./styles.scss";
|
import "./styles.scss";
|
||||||
import { Button, Flex, Text } from "@chakra-ui/react";
|
import { Button, Flex, Text } from "@chakra-ui/react";
|
||||||
import { openPhonePopup } from "./utils";
|
import { openPhonePopup } from "./utils";
|
||||||
import { DEFAULT_COLOR_SCHEME } from "./common/constants";
|
|
||||||
export const App = () => {
|
export const App = () => {
|
||||||
const handleClick = () => {
|
const handleClick = () => {
|
||||||
openPhonePopup();
|
openPhonePopup();
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
chrome.action.onClicked.addListener(async (tab) => {
|
||||||
|
const windowId = await getWindowKey();
|
||||||
|
if (windowId) {
|
||||||
|
if (windowId) {
|
||||||
|
chrome.windows.update(windowId, { focused: true }, (w) => {
|
||||||
|
if (!w) {
|
||||||
|
initiateNewPhonePopup();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
initiateNewPhonePopup();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
initiateNewPhonePopup();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const initiateNewPhonePopup = () => {
|
||||||
|
chrome.windows.create(
|
||||||
|
{
|
||||||
|
url: chrome.runtime.getURL("window/index.html"),
|
||||||
|
width: 440,
|
||||||
|
height: 720,
|
||||||
|
focused: true,
|
||||||
|
type: "panel",
|
||||||
|
state: "normal",
|
||||||
|
},
|
||||||
|
function (window) {
|
||||||
|
if (window?.id) {
|
||||||
|
saveWindowKey(window?.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const saveWindowKey = async (id: number) => {
|
||||||
|
await chrome.storage.local.set({
|
||||||
|
WindowKey: id,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const getWindowKey = async (): Promise<number> => {
|
||||||
|
const result = await chrome.storage.local.get(["WindowKey"]);
|
||||||
|
return result.WindowKey as number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export {};
|
||||||
@@ -31,6 +31,34 @@ module.exports = [
|
|||||||
extensions: [".ts", ".tsx", ".js"],
|
extensions: [".ts", ".tsx", ".js"],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
entry: "./src/background/index.ts",
|
||||||
|
target: "web",
|
||||||
|
mode: "production",
|
||||||
|
output: {
|
||||||
|
path: path.join(__dirname, "dist"),
|
||||||
|
filename: "background/index.js",
|
||||||
|
},
|
||||||
|
module: {
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
test: /\.tsx?$/,
|
||||||
|
use: [
|
||||||
|
{
|
||||||
|
loader: "ts-loader",
|
||||||
|
options: {
|
||||||
|
compilerOptions: { noEmit: false },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
exclude: /node_modules/,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
resolve: {
|
||||||
|
extensions: [".ts", ".tsx", ".js"],
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
entry: {
|
entry: {
|
||||||
index: "./src/index.tsx",
|
index: "./src/index.tsx",
|
||||||
|
|||||||
Reference in New Issue
Block a user