Skip to content

Commit

Permalink
Feat: Error modal and report option in context menu (#190)
Browse files Browse the repository at this point in the history
* fix: safeExecute working with functions

* fix: App version available in modal templating

* feat(interface): Error modal appearing when an error occurs during the export process

* refactor(tab): separately safeExecute scraping and post-scraping to avoid inconsistency

* feat(contextMenu): Adding option to report bugs

* fix(tab): Fix error not launching modal

* fix(tab): Also report issue

* docs: update notes
  • Loading branch information
Hugo-COLLIN authored Oct 20, 2024
1 parent 92d6f55 commit 404e3eb
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 11 deletions.
3 changes: 2 additions & 1 deletion esbuild.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const {watchStatic} = require("./config/esbuild/watchStatic");
const outdir = 'dist';
const targetBrowser = process.env.TARGET || 'chrome';
const appMode = process.env.APP_MODE || 'dev';
const appVersion = require('./package.json').version.toString();
const watchMode = process.env.WATCH_MODE || false; // Flag for watch mode

const options = {
Expand All @@ -27,7 +28,7 @@ const options = {
define: {
'APP_MODE': `"${appMode}"`,
'APP_TARGET': `"${targetBrowser}"`,
'APP_VERSION': `"${require('./package.json').version}"`,
'APP_VERSION': `"${appVersion}"`,
},
plugins: [
cleanDirectoryPlugin(outdir),
Expand Down
20 changes: 20 additions & 0 deletions public/files/modalMessages/modalError.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
title: "🤔 Well... The export didn't go as planned..."
buttons:
- { text: "I'll try again" }
- {
text: "🐞 Report this bug",
url: "${appInfos.URLS.REPORT}",
style: "btn-primary",
}

---
It seems like an error has occurred during the export process. Please try again. If the issue persists, please report this bug.
This information can help:
- The steps to reproduce the problem
- The URL of this page
- The app version: v${appInfos.APP_VERSION}
- Screenshots illustrating the problem

❤️ Thank you for your help and sorry for the inconvenience.

5 changes: 5 additions & 0 deletions public/files/updateNotes.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Update notes
# 3.3.0
🐞 Facilitating bug reports
When an error occurs during the export process, a modal will appear inviting you report the bug.
Plus, an option is available in the icon context menu.

# 3.2.6
🧩 Some bug fixes
Fixing ChatGPT sources export and the sources markdown formatting thanks to users feedback.
Expand Down
3 changes: 2 additions & 1 deletion src/data/infos.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"STORES": {
"CHROME": "https://chromewebstore.google.com/u/1/detail/agklnagmfeooogcppjccdnoallkhgkod",
"FIREFOX": "https://addons.mozilla.org/firefox/addon/save-my-phind"
}
},
"REPORT": "https://save.hugocollin.com/issue"
},
"CONTACT_EMAIL": "[email protected]",
"COPY_MODE": "tab"
Expand Down
8 changes: 6 additions & 2 deletions src/entrypoints/tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {domainChecker} from "../scripts/shared/checker/domainChecker";
import {getHostAndPath} from "../scripts/content/utils/getters";
import {getStorageData} from "../scripts/shared/utils/chromeStorage";
import {safeExecute} from "../scripts/shared/utils/jsShorteners";
import {SCRAPER_FALLBACK_ACTION} from "../scripts/content/utils/fallbackActions";

/**
* @description - Main function to handle action on the tab
Expand Down Expand Up @@ -44,8 +45,11 @@ export async function actionExtensionIconClicked() {
console.warn("Domain not allowed");
return;
}
launchScrapping(domainPage); // don't safeExecute because we don't want handleModalDisplay to increment count
await safeExecute(handleModalDisplay());

await safeExecute(async () => {
await launchScrapping(domainPage);
handleModalDisplay();
}, SCRAPER_FALLBACK_ACTION());
}

// Launch the main content script
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function buildContextMenu() {
});
chrome.contextMenus.create({
id: "tutorial",
title: (emojiSupported ? "❓ " : "") + "How-To-Use Tutorial",
title: (emojiSupported ? "❓ " : "") + "User's Guide",
contexts: ["action"]
});
chrome.contextMenus.create({
Expand All @@ -27,6 +27,11 @@ export function buildContextMenu() {
title: (emojiSupported ? "🤩 " : "") + "Share your feedback on the store",
contexts: ["action"]
});
chrome.contextMenus.create({
id: "bugReport",
title: (emojiSupported ? "🚀 " : "") + "Report a bug or suggest a feature",
contexts: ["action"]
});
chrome.contextMenus.create({
id: "donation",
title: (emojiSupported ? "❤️ " : "") + "Support the project",
Expand Down Expand Up @@ -56,6 +61,9 @@ export function buildContextMenu() {
case "exportPage":
await launchIconClickAction(tab);
break;
case "bugReport":
await chrome.tabs.create({url: appInfos.URLS.REPORT});
break;
// case "openIconPopup":
// setOneTimePopup("pages/popup.html");
// break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ export default class ModalMessage extends Modal {
const [yamlContent, markdownContent] = markdownWithYaml.split('---\n').slice(1, 3);

// Parse the YAML header
const yamlHeader = yaml.load(await replaceVariables(yamlContent, appInfos));
const variablesList = {...appInfos, APP_VERSION: APP_VERSION}; // include esbuild define variables
const yamlHeader = yaml.load(await replaceVariables(yamlContent, variablesList));

// Process Markdown content
const processedMarkdownContent = replaceLocalPath(await replaceVariables(markdownContent, appInfos));
const processedMarkdownContent = replaceLocalPath(await replaceVariables(markdownContent, variablesList));

// Title
const innerDivImage = document.createElement('span');
Expand Down
8 changes: 8 additions & 0 deletions src/scripts/content/utils/fallbackActions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import appInfos from "../../../data/infos.json";
import ModalMessage from "../interface/uiEnhancer/modals/types/ModalMessage";

export function EXTRACTOR_FALLBACK_ACTION() {
return (error) => {
Expand All @@ -13,3 +14,10 @@ export function EXPORTER_FALLBACK_ACTION() {
throw new Error("File conversion error:\n" + error.stack);
};
}

export function SCRAPER_FALLBACK_ACTION() {
return async (error) => {
await new ModalMessage('../files/modalMessages/modalError.md').appendModal();
throw error;
};
}
17 changes: 13 additions & 4 deletions src/scripts/shared/utils/jsShorteners.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,21 @@ export function dynamicCall(object, funcToCall, ...args) {
* @param catchAction
*/
export async function safeExecute(action, catchAction = null) {
if (APP_MODE === 'dev') {
// console.log("Action to execute:", action);
return await action;
async function executeAction() {
switch (typeof action) {
case 'function':
return await action();
default:
// console.log("Action to execute:", action);
return await action;
}
}

// if (APP_MODE === 'dev') {
// return await executeAction();
// }
try {
return await action;
return await executeAction();
} catch (error) {
catchAction
? catchAction(error)
Expand Down

0 comments on commit 404e3eb

Please sign in to comment.