Skip to content

Commit

Permalink
chore: Bump to 3.7.1 and refactor menu creation IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
gyng committed Feb 12, 2023
1 parent 01a8c09 commit bc0b7b1
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 25 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 3.7.1

* Fix invalid default menu configuration
* Now notifies by default for successful downloads
* Fix light mode icon for last used menu item being white
* Refactor context menu creation, might help with #200

# 3.7.0

This update might require a change in your muscle memories. Previously all submenus of the same depth would have their shortcut keys increment even if they had different parents. That's now been fixed. Thanks,
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 2,
"name": "__MSG_extensionName__",
"description": "__MSG_extensionDescription__",
"version": "3.7.0",
"version": "3.7.1",
"default_locale": "en",

"applications": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "save-in",
"version": "3.7.0",
"version": "3.7.1",
"license": "MIT",
"scripts": {
"build": "env -u WEB_EXT_API_KEY -u WEB_EXT_API_SECRET web-ext build --overwrite-dest -i test docs yarn.lock yarn-error.log",
Expand Down
2 changes: 1 addition & 1 deletion src/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const Download = {
.filter((x) => x != null)
.join("/");

return finalFullPath.replace(/^\.\//, "");
return finalFullPath.replace(/^\.\//, "").replace(/^\//, "");
},

getFilenameFromContentDisposition: (disposition) => {
Expand Down
58 changes: 36 additions & 22 deletions src/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@ let lastUsedPath = null; // global variable
const Menus = {
IDS: {
TABSTRIP: {
SELECTED_TAB: "save-in-_-_-SI-selected-tab",
SELECTED_MULTIPLE_TABS: "save-in-_-_-SI-selected-multiple-tabs",
TO_RIGHT: "save-in-_-_-SI-to-right",
TO_RIGHT_MATCH: "save-in-_-_-SI-to-right-match",
OPENED_FROM_TAB: "save-in-_-_-SI-opened-from-tab",
SELECTED_TAB: "save-in-SI-selected-tab",
SELECTED_MULTIPLE_TABS: "save-in-SI-selected-multiple-tabs",
TO_RIGHT: "save-in-SI-to-right",
TO_RIGHT_MATCH: "save-in-SI-to-right-match",
OPENED_FROM_TAB: "save-in-SI-opened-from-tab",
},
ROOT: "save-in-_-_-root",
LAST_USED: "save-in-_-_-last-used",
ROUTE_EXCLUSIVE: "save-in-route-exclusive",
ROOT: "save-in-root",
LAST_USED: "save-in-last-used",
},

titles: {},
pathMappings: {}, // key: ID, val: actual path

makeSeparator: (() => {
let separatorCounter = 0;
Expand Down Expand Up @@ -58,7 +60,7 @@ const Menus = {

addRouteExclusive: (contexts) => {
browser.contextMenus.create({
id: "save-in-_-_-route-exclusive",
id: Menus.IDS.ROUTE_EXCLUSIVE,
title: Menus.setAccesskey(
browser.i18n.getMessage("contextMenuExclusive"),
options.keyRoot
Expand Down Expand Up @@ -112,7 +114,7 @@ const Menus = {
id: "options",
title: browser.i18n.getMessage("contextMenuItemOptions"),
contexts,
parentId: "save-in-_-_-root",
parentId: "save-in-root",
});

browser.contextMenus.onClicked.addListener((info) => {
Expand Down Expand Up @@ -154,7 +156,9 @@ const Menus = {
browser.contextMenus.create(
Object.assign({}, lastUsedMenuOptions, {
icons: {
16: "icons/ic_update_black_24px.svg",
16: OptionsManagement.isDarkMode()
? "icons/ic_update_light_24px.svg"
: "icons/ic_update_black_24px.svg",
},
})
);
Expand Down Expand Up @@ -205,6 +209,7 @@ const Menus = {

addPaths: (pathsArray, contexts) => {
const menuItemCounter = [0]; // key: depth, val: index
Menus.pathMappings = {};

// Create a stack for nested menus
let pathsNestingStack = [];
Expand Down Expand Up @@ -242,9 +247,14 @@ const Menus = {
} else {
menuItemCounter[depth] = 1;
}
const id = `save-in-${menuItemCounter.join(
"."
)}-${`${i}${comment.replace("-", "_")}`}-${parsedDir}`;
const id = `save-in-${i}`;
Menus.pathMappings[id] = {
parsedDir,
comment: `${i}${comment.replace("-", "_")}`,
menuIndex: menuItemCounter.join("."),
title,
depth,
};

let parentId;
if (depth === 0) {
Expand Down Expand Up @@ -290,12 +300,16 @@ const Menus = {
return;
}

const matchSave = info.menuItemId.match(/save-in-(\d|_)+-(.*?)-(.*)/);
const menuInfo = Menus.pathMappings[info.menuItemId];

if (matchSave && matchSave.length === 4) {
let menuIndex = matchSave[1];
let comment = matchSave[2];
const matchedDir = matchSave[3];
if (
menuInfo ||
[Menus.IDS.ROUTE_EXCLUSIVE, Menus.IDS.LAST_USED].includes(
info.menuItemId
)
) {
let menuIndex = menuInfo && menuInfo.menuIndex;
let comment = menuInfo && menuInfo.comment;

let url;
let suggestedFilename = null;
Expand Down Expand Up @@ -373,16 +387,16 @@ const Menus = {

let saveIntoPath;

if (matchedDir === "route-exclusive") {
if (info.menuItemId === Menus.IDS.ROUTE_EXCLUSIVE) {
saveIntoPath = ".";
} else if (matchedDir === "last-used") {
} else if (info.menuItemId === Menus.IDS.LAST_USED) {
saveIntoPath = lastUsedPath;
comment = window.lastDownloadState.info.comment;
menuIndex = window.lastDownloadState.info.menuIndex;
} else {
saveIntoPath = matchedDir;
saveIntoPath = menuInfo.parsedDir;
lastUsedPath = saveIntoPath;
const title = Menus.titles[info.menuItemId] || lastUsedPath;
const title = menuInfo.title || lastUsedPath;

if (options.enableLastLocation) {
browser.contextMenus.update(Menus.IDS.LAST_USED, {
Expand Down

0 comments on commit bc0b7b1

Please sign in to comment.