Skip to content
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
3 changes: 2 additions & 1 deletion src/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
DEFAULT_FONT_WEIGHT,
} from "./constants";
import { initCommandListeners } from "./listeners/commandListeners";
import { handleModalToggle } from "./listeners/modalCommandHandler";

Check warning on line 11 in src/background/index.ts

View workflow job for this annotation

GitHub Actions / lint-and-test

'handleModalToggle' is defined but never used. Allowed unused vars must match /^_/u
import { handleIconToggle } from "./listeners/iconHandler";

/**
* 백그라운드 스크립트 초기화
Expand Down Expand Up @@ -272,7 +273,7 @@
);
}

const parsedList = Object.entries(raw || {})

Check warning on line 276 in src/background/index.ts

View workflow job for this annotation

GitHub Actions / lint-and-test

'parsedList' is assigned a value but never used. Allowed unused vars must match /^_/u
.filter(([_, v]) => v === true)
.map(([k]) => k);

Expand Down Expand Up @@ -417,10 +418,10 @@
}
});

chrome.action.onClicked.addListener(async (tab) => {

Check warning on line 421 in src/background/index.ts

View workflow job for this annotation

GitHub Actions / lint-and-test

'tab' is defined but never used. Allowed unused args must match /^_/u
try {
logger.debug("툴바 아이콘 클릭됨");
await handleModalToggle();
await handleIconToggle();
} catch (error) {
logger.error("툴바 아이콘 클릭 처리 중 오류 발생:", error);
}
Expand Down
124 changes: 124 additions & 0 deletions src/background/listeners/iconHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
export async function handleIconToggle(): Promise<void> {
const tabs = await chrome.tabs.query({
active: true,
currentWindow: true,
});

if (tabs[0]?.id) {
await chrome.scripting.executeScript({
target: { tabId: tabs[0].id },
func: function () {
const iframeId = "floating-button-extension-iframe";
let iframe = document.getElementById(
iframeId,
) as HTMLIFrameElement;

// 항상 iframeHiddenByAltA 먼저 검사
chrome.storage.local.get(
[
"iframeInvisible",
"iframeHiddenByAltA",
"iframeHiddenByAltV",
],
(result) => {
const isInvisible = result.iframeInvisible ?? false;
const hiddenByAltV = result.iframeHiddenByAltV ?? false;
const hiddenByAltA = result.iframeHiddenByAltA ?? false;

if (!iframe) {
// Alt+V로 숨겨진 상태일 때만 iframe 생성
if (isInvisible) {
iframe = document.createElement("iframe");
iframe.id = iframeId;
iframe.src =
chrome.runtime.getURL("iframe.html");
iframe.setAttribute("tabindex", "1");

iframe.style.position = "fixed";
iframe.style.top = "70px";
iframe.style.right = "20px";
iframe.style.width = "65px";
iframe.style.height = "130px";
iframe.style.border = "none";
iframe.style.background = "transparent";
iframe.style.zIndex = "2147483647";

iframe.onload = () => {
iframe.focus();
iframe.contentWindow?.document
.getElementById("root")
?.focus();
};

const handleMessage = function (
event: MessageEvent,
) {
if (event.source !== iframe.contentWindow)
return;

if (event.data.type === "RESIZE_IFRAME") {
if (event.data.isOpen) {
iframe.style.width = "100%";
iframe.style.height = "100%";
iframe.style.top = "0";
iframe.style.right = "0";
} else {
iframe.style.width = "65px";
iframe.style.height = "130px";
iframe.style.top = "70px";
iframe.style.right = "20px";
}
}
};
window.addEventListener(
"message",
handleMessage,
);
document.body.appendChild(iframe);

chrome.storage.local.set({
iframeInvisible: false,
iframeHiddenByAltA: false,
iframeHiddenByAltV: true,
});

iframe.onload = function () {
if (iframe.contentWindow) {
iframe.contentWindow.postMessage(
{ type: "TOGGLE_MODAL" },
"*",
);
}
};
}
} else {
// iframe이 이미 존재할 때
if (iframe.contentWindow) {
iframe.contentWindow.postMessage(
{ type: "TOGGLE_MODAL" },
"*",
);

if (hiddenByAltV) {
iframe.remove();
chrome.storage.local.set({
iframeInvisible: true,
iframeHiddenByAltA: false,
iframeHiddenByAltV: false,
});
}
}
}
if (isInvisible && hiddenByAltA) {
chrome.storage.local.set({
iframeInvisible: false,
iframeHiddenByAltA: false,
iframeHiddenByAltV: false,
});
}
},
);
},
});
}
}
9 changes: 8 additions & 1 deletion src/background/listeners/iframeCommandHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,22 @@
chrome.storage.local.get(
["iframeInvisible", "iframeHiddenByAltA"],
function (result) {
const isInvisible =

Check warning on line 25 in src/background/listeners/iframeCommandHandler.ts

View workflow job for this annotation

GitHub Actions / lint-and-test

'isInvisible' is assigned a value but never used. Allowed unused vars must match /^_/u
result.iframeInvisible ?? false;
const hiddenByAltA =
result.iframeHiddenByAltA ?? false;

if (hiddenByAltA) {
// ALT+A로 숨긴 경우에는 iframe을 생성하지 않음
return;
}

if (existingIframe) {
existingIframe.remove();
chrome.storage.local.set({
iframeInvisible: true,
iframeHiddenByAltA: true,
iframeHiddenByAltA: false,
iframeHiddenByAltV: true,
});
} else if (!hiddenByAltA) {
// hiddenByAltA가 false일 때만 iframe 생성
Expand Down Expand Up @@ -93,6 +99,7 @@
chrome.storage.local.set({
iframeInvisible: false,
iframeHiddenByAltA: false,
iframeHiddenByAltV: false,
});
}
},
Expand Down
6 changes: 4 additions & 2 deletions src/background/listeners/sidebarCommandHandler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { logger } from "@src/utils/logger";

export async function handleSidebarToggle(): Promise<void> {
const tabs = await chrome.tabs.query({
active: true,
Expand All @@ -26,6 +24,10 @@ export async function handleSidebarToggle(): Promise<void> {
const isInvisible = result.iframeInvisible ?? false;
const hiddenByAltA =
result.iframeHiddenByAltA ?? false;
if (hiddenByAltA) {
// ALT+A로 숨긴 경우에는 iframe을 생성하지 않음
return;
}

// ALT+V로 숨긴 경우에만 iframe 생성하고 사이드바 띄우기
if (isInvisible) {
Expand Down
20 changes: 16 additions & 4 deletions src/background/listeners/styleCommandHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,29 @@ export async function handleStyleToggle(): Promise<void> {
});

if (tabs[0]?.id) {
const currentStyleState = await chrome.storage.local.get([
const result = await chrome.storage.local.get([
"iframeHiddenByAltV",
"stylesEnabled",
]);
const isStylesEnabled = currentStyleState.stylesEnabled ?? true;
const isStylesEnabled = result.stylesEnabled ?? true;
const wasHiddenByAltV = result.iframeHiddenByAltV ?? false;

settingsService.setStylesEnabled(isStylesEnabled);

await chrome.scripting.executeScript({
target: { tabId: tabs[0].id },
func: function () {
func: (wasHiddenByAltV: boolean) => {
const iframeId = "floating-button-extension-iframe";
const existingIframe = document.getElementById(iframeId);

if (!existingIframe && wasHiddenByAltV) {
// ALT+V로 숨겨진 경우에는 iframe을 생성하지 않음
chrome.storage.local.set({
iframeInvisible: true,
iframeHiddenByAltA: true,
iframeHiddenByAltV: false,
});
return;
}
if (existingIframe) {
existingIframe.remove();
chrome.storage.local.set({
Expand Down Expand Up @@ -74,9 +84,11 @@ export async function handleStyleToggle(): Promise<void> {
chrome.storage.local.set({
iframeInvisible: false,
iframeHiddenByAltA: false,
iframeHiddenByAltV: false,
});
}
},
args: [wasHiddenByAltV],
});

if (isStylesEnabled) {
Expand Down
Loading