diff --git a/src/MyComponent.jsx b/src/MyComponent.jsx
deleted file mode 100644
index 1cb267f..0000000
--- a/src/MyComponent.jsx
+++ /dev/null
@@ -1,9 +0,0 @@
-import React from 'react';
-
-class MyComponent extends React.Component {
- render() {
- return
Hello, World!
;
- }
-}
-
-export default MyComponent;
\ No newline at end of file
diff --git a/src/background.js b/src/background/background.js
similarity index 91%
rename from src/background.js
rename to src/background/background.js
index a555e7e..9fc5e54 100644
--- a/src/background.js
+++ b/src/background/background.js
@@ -1,9 +1,9 @@
-import { storageGet, storageSet } from "./utils";
-import { Tab } from "./types";
+import { storageGet, storageSet } from "../utils";
+import { Tab } from "../types";
import { loadSignature, saveSignature } from "./signatureStorage";
-import { getLogger } from "./log";
+import { getLogger } from "../log";
import { startTheGarbageCollector } from "./garbageCollector";
-import { EVENT_OPEN_RENAME_DIALOG } from "./config";
+import { EVENT_OPEN_RENAME_DIALOG } from "../config";
const log = getLogger('background.js');
log.setLevel('DEBUG');
@@ -30,7 +30,10 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
} else if (message.command === "load_signature") {
loadSignature(sender.tab.id, sender.tab.url, sender.tab.index, false)
.then((resp) => {
- sendResponse(resp);
+ return sendResponse(resp);
+ }).catch(e => {
+ log.error('Error while loading signature:', e);
+ return sendResponse(null);
});
return true; // To indicate that the response will be asynchronous
}
diff --git a/src/garbageCollector.js b/src/background/garbageCollector.js
similarity index 94%
rename from src/garbageCollector.js
rename to src/background/garbageCollector.js
index 471d420..263d619 100644
--- a/src/garbageCollector.js
+++ b/src/background/garbageCollector.js
@@ -1,5 +1,5 @@
-import { storageGet, storageSet } from "./utils.js";
-import { Tab } from "./types";
+import { storageGet, storageSet } from "../utils.js";
+import { Tab } from "../types.js";
/** garbage collector (gc) logger */
const gcLog = require("loglevel").getLogger("module-one")
diff --git a/src/signatureStorage.js b/src/background/signatureStorage.js
similarity index 97%
rename from src/signatureStorage.js
rename to src/background/signatureStorage.js
index c8c2f73..270d438 100644
--- a/src/signatureStorage.js
+++ b/src/background/signatureStorage.js
@@ -1,6 +1,6 @@
-import { Tab, TabSignature } from "./types";
-import { storageGet, storageSet } from "./utils";
-import { getLogger } from "./log";
+import { Tab, TabSignature } from "../types";
+import { storageGet, storageSet } from "../utils";
+import { getLogger } from "../log";
const log = getLogger('signatureStorage.js')
// log.setLevel('DEBUG');
diff --git a/src/backgroundScriptApi.js b/src/contentScript/backgroundScriptApi.js
similarity index 97%
rename from src/backgroundScriptApi.js
rename to src/contentScript/backgroundScriptApi.js
index 02f431f..809d44f 100644
--- a/src/backgroundScriptApi.js
+++ b/src/contentScript/backgroundScriptApi.js
@@ -1,4 +1,4 @@
-import log from "./log";
+import log from "../log";
class BackgroundScriptAPI {
async saveSignature(title, favicon) {
diff --git a/src/components/App.js b/src/contentScript/components/App.js
similarity index 98%
rename from src/components/App.js
rename to src/contentScript/components/App.js
index f6f6e25..3d04b5e 100644
--- a/src/components/App.js
+++ b/src/contentScript/components/App.js
@@ -1,10 +1,10 @@
import React, { useEffect, useState } from 'react';
import EmojiPicker from './EmojiPicker';
import { setTabTitle, setTabFavicon } from '../contentScript';
-import { ROOT_ELEMENT_ID, INPUT_BOX_ID, OVERLAY_ID, MAIN_BAR_ID, EVENT_OPEN_RENAME_DIALOG } from '../config';
+import { ROOT_ELEMENT_ID, INPUT_BOX_ID, OVERLAY_ID, MAIN_BAR_ID, EVENT_OPEN_RENAME_DIALOG } from '../../config';
import PropTypes from 'prop-types';
import bgScriptApi from '../backgroundScriptApi';
-import log from "../log";
+import log from "../../log";
import SelectedEmoji from './SelectedEmoji';
export function App() {
diff --git a/src/components/EmojiPicker.js b/src/contentScript/components/EmojiPicker.js
similarity index 98%
rename from src/components/EmojiPicker.js
rename to src/contentScript/components/EmojiPicker.js
index ae11b05..1f4a932 100644
--- a/src/components/EmojiPicker.js
+++ b/src/contentScript/components/EmojiPicker.js
@@ -1,6 +1,6 @@
import React, { Component, useEffect, useRef } from 'react';
import PropTypes from 'prop-types';
-import { EMOJI_PICKER_ID } from '../config';
+import { EMOJI_PICKER_ID } from '../../config';
const SEARCH_RESULTS_ID = 'tab-renamer-extension-search-results-div';
const ALL_EMOJIS_ID = 'tab-renamer-extension-all-emojis-div';
diff --git a/src/components/SelectedEmoji.js b/src/contentScript/components/SelectedEmoji.js
similarity index 89%
rename from src/components/SelectedEmoji.js
rename to src/contentScript/components/SelectedEmoji.js
index 3bf060f..46e2b75 100644
--- a/src/components/SelectedEmoji.js
+++ b/src/contentScript/components/SelectedEmoji.js
@@ -1,8 +1,8 @@
import React from 'react';
-import { emojiToDataURL } from '../utils';
+import { emojiToDataURL } from '../../utils';
import PropTypes from 'prop-types';
-import { EMOJI_PICKER_IMAGE_ID, FAVICON_PICKER_ID, PICKED_EMOJI_ID } from '../config';
-import log from '../log';
+import { EMOJI_PICKER_IMAGE_ID, FAVICON_PICKER_ID, PICKED_EMOJI_ID } from '../../config';
+import log from '../../log';
function SelectedEmoji({ selectedEmoji, handleFaviconPickerClick }) {
log.debug('Rendering SelectedEmoji with emoji:', selectedEmoji);
diff --git a/src/contentScript.js b/src/contentScript/contentScript.js
similarity index 94%
rename from src/contentScript.js
rename to src/contentScript/contentScript.js
index 3ee283d..fa49643 100644
--- a/src/contentScript.js
+++ b/src/contentScript/contentScript.js
@@ -1,20 +1,17 @@
import { preserveFavicon, preserveTabTitle, disconnectTabTitlePreserver, disconnectFaviconPreserver } from "./preservers";
import listenerManager from "./listenerManager";
-import { EVENT_OPEN_RENAME_DIALOG, ROOT_ELEMENT_ID, ROOT_TAG_NAME } from "./config";
+import { EVENT_OPEN_RENAME_DIALOG, ROOT_ELEMENT_ID, ROOT_TAG_NAME } from "../config";
import { createRoot } from 'react-dom/client';
import { App } from './components/App';
-import { emojiToDataURL } from './utils';
+import { emojiToDataURL } from '../utils';
import bgScriptApi from "./backgroundScriptApi";
import React from 'react';
-import log from "./log";
+import log from "../log";
// Global variables:
let uiInsertedIntoDOM = false;
let root = null;
-// TODO: Separate your code into background and contentscript folders.
-// But maybe do that after React refactoring is finished.
-
export async function setTabTitle(newTabTitle) {
log.debug('setTabTitle called with newTabTitle:', newTabTitle);
preserveTabTitle(newTabTitle);
diff --git a/src/listenerManager.js b/src/contentScript/listenerManager.js
similarity index 97%
rename from src/listenerManager.js
rename to src/contentScript/listenerManager.js
index 18e52e1..bad5d91 100644
--- a/src/listenerManager.js
+++ b/src/contentScript/listenerManager.js
@@ -1,4 +1,4 @@
-import log from "./log";
+import log from "../log";
class ListenerManager {
constructor() {
diff --git a/src/preservers.js b/src/contentScript/preservers.js
similarity index 100%
rename from src/preservers.js
rename to src/contentScript/preservers.js
diff --git a/tests/unit/garbageCollector.test.js b/tests/unit/garbageCollector.test.js
index 7e03735..c103207 100644
--- a/tests/unit/garbageCollector.test.js
+++ b/tests/unit/garbageCollector.test.js
@@ -1,4 +1,4 @@
-const { garabageCollectionFilter } = require('../../src/garbageCollector');
+const { garabageCollectionFilter } = require('../../src/background/garbageCollector');
describe('garabageCollectionFilter', () => {
test('should keep the tab if it is not closed', () => {
diff --git a/tests/unit/signatureStorage.test.js b/tests/unit/signatureStorage.test.js
index 91a3bd6..4bc4fb8 100644
--- a/tests/unit/signatureStorage.test.js
+++ b/tests/unit/signatureStorage.test.js
@@ -1,4 +1,4 @@
-const { findMatchingTab, loadSignature, saveSignature } = require('../../src/signatureStorage.js');
+const { findMatchingTab, loadSignature, saveSignature } = require('../../src/background/signatureStorage.js');
const { Tab, TabSignature } = require('../../src/types.js');
const { storageSet, storageGet } = require('../../src/utils.js');
const { chromeStorageMock } = require('../chromeStorageMock.js');
diff --git a/webpack.config.js b/webpack.config.js
index d1165f1..2fc1302 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -8,8 +8,8 @@ module.exports = (_env, argv) => {
return {
entry: {
- contentScript: './src/contentScript.js',
- background: './src/background.js',
+ contentScript: './src/contentScript/contentScript.js',
+ background: './src/background/background.js',
},
output: {