Skip to content

Commit

Permalink
refactor: sidebar, popup 페이지 제거
Browse files Browse the repository at this point in the history
  • Loading branch information
jaem1n207 committed May 15, 2024
1 parent 5f194e0 commit 47f4940
Show file tree
Hide file tree
Showing 15 changed files with 18 additions and 121 deletions.
5 changes: 0 additions & 5 deletions e2e/basic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ test('example test', async ({ page }, testInfo) => {
await expect(page.locator(`#${name} h1`)).toHaveText('Dynamic Scrollbar WebExt');
});

test('popup page', async ({ page, extensionId }) => {
await page.goto(`chrome-extension://${extensionId}/dist/popup/index.html`);
await expect(page.locator('button')).toHaveText('Open Options');
});

test('options page', async ({ page, extensionId }) => {
await page.goto(`chrome-extension://${extensionId}/dist/options/index.html`);
await expect(page.locator('img')).toHaveAttribute('alt', 'extension icon');
Expand Down
2 changes: 1 addition & 1 deletion playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default defineConfig({
webServer: {
command: 'npm run dev',
// start e2e test after the Vite server is fully prepared
url: 'http://localhost:3303/popup/main.ts',
url: 'http://localhost:3303/options/main.ts',
reuseExistingServer: true,
},
});
2 changes: 1 addition & 1 deletion scripts/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { isDev, log, port, r } from './utils';
* Stub index.html to use Vite in development
*/
async function stubIndexHtml() {
const views = ['options', 'popup', 'background', 'sidebar'];
const views = ['options', 'background'];

for (const view of views) {
await fs.ensureDir(r(`extension/dist/${view}`));
Expand Down
4 changes: 4 additions & 0 deletions src/background/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ browser.runtime.onInstalled.addListener((): void => {
console.log('Extension installed');
});

browser.action.onClicked.addListener(() => {
browser.runtime.openOptionsPage();
});

let previousTabId = 0;

// communication example: send previous tab title from background page
Expand Down
2 changes: 1 addition & 1 deletion src/contentScripts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ import { renderApp } from './render';
shadowDOM.appendChild(root);
document.body.appendChild(container);
const appRoot = createRoot(root);
renderApp({ root: appRoot, frameUrl: browser.runtime.getURL('dist/sidebar/index.html') });
renderApp({ root: appRoot });
})();
33 changes: 8 additions & 25 deletions src/contentScripts/pages/App.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,16 @@
import IconPower from '~icons/pixelarticons/power';

import IconCat from '~icons/arcticons/cats-and-soup';
import 'uno.css';

export default function App({ frameUrl }: { frameUrl: string }) {
const [open, setOpen] = useState(false);
const [openedOnce, setOpenedOnce] = useState(false);
import { Button } from '~/shared/ui';

export const App = () => {
return (
<div>
<div className="fixed left-0 bottom-0 m-5 z-100 flex font-sans select-none leading-1em">
<div
className="flex justify-center items-center w-10 h-10 rounded-full shadow cursor-pointer bg-blue-400 hover:bg-blue-600"
onClick={() => {
setOpen((open) => !open);
setOpenedOnce(true);
}}
>
<IconPower />
</div>
<div className="fixed right-0 bottom-0 m-5 z-99999 select-none">
<Button className="rounded-full">
<IconCat />
</Button>
</div>
{openedOnce && (
<div
className={`fixed top-0 right-0 h-full w-1/4 z-50 drop-shadow-xl transition-transform ${
open ? 'translate-x-0' : 'translate-x-full'
}`}
>
<iframe src={frameUrl} className="w-full h-full border-0" />
</div>
)}
</div>
);
}
};
6 changes: 3 additions & 3 deletions src/contentScripts/render.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { StrictMode } from 'react';
import type { Root } from 'react-dom/client';

import App from './pages/App';
import { App } from './pages/App';

export const renderApp = ({ root, frameUrl }: { root: Root; frameUrl: string }) => {
export const renderApp = ({ root }: { root: Root }) => {
return root.render(
<StrictMode>
<App frameUrl={frameUrl} />
<App />
</StrictMode>,
);
};
1 change: 0 additions & 1 deletion src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export async function getManifest(): Promise<Manifest.WebExtensionManifest> {
default_locale: 'en',
action: {
default_icon: './assets/icon-512.png',
default_popup: './dist/popup/index.html',
},
options_ui: {
page: './dist/options/index.html',
Expand Down
12 changes: 0 additions & 12 deletions src/popup/index.html

This file was deleted.

13 changes: 0 additions & 13 deletions src/popup/main.tsx

This file was deleted.

23 changes: 0 additions & 23 deletions src/popup/popup.tsx

This file was deleted.

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

This file was deleted.

13 changes: 0 additions & 13 deletions src/sidebar/main.tsx

This file was deleted.

9 changes: 0 additions & 9 deletions src/sidebar/sidebar.tsx

This file was deleted.

2 changes: 0 additions & 2 deletions vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ export default defineConfig(({ command }) => ({
rollupOptions: {
input: {
options: r('src/options/index.html'),
popup: r('src/popup/index.html'),
sidebar: r('src/sidebar/index.html'),
},
},
},
Expand Down

0 comments on commit 47f4940

Please sign in to comment.