Skip to content

Commit

Permalink
feat(command): add shortcut for adding notebook
Browse files Browse the repository at this point in the history
Closes #785
  • Loading branch information
crimx committed May 15, 2020
1 parent 70150fd commit 524dd6c
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/_locales/manifest/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,8 @@
},
"command_profile_5": {
"message": "Fifth Profile"
},
"command_add_notebook": {
"message": "Add to Notebook"
}
}
3 changes: 3 additions & 0 deletions src/_locales/manifest/zh_CN/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,8 @@
},
"command_profile_5": {
"message": "第五个情景模式"
},
"command_add_notebook": {
"message": "加入生词本"
}
}
3 changes: 3 additions & 0 deletions src/_locales/manifest/zh_TW/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,8 @@
},
"command_profile_5": {
"message": "第五個情景模式"
},
"command_add_notebook": {
"message": "加入生詞本"
}
}
23 changes: 23 additions & 0 deletions src/background/initialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ function onCommand(command: string) {
}
}
break
case 'add-notebook':
addNotebook()
break
}
}

Expand Down Expand Up @@ -305,3 +308,23 @@ async function searchTextBox() {
}
message.send(tabs[0].id, { type: 'SEARCH_TEXT_BOX' })
}

async function addNotebook() {
if (
await message.send<'ADD_NOTEBOOK'>({
type: 'ADD_NOTEBOOK',
payload: { popup: true }
})
) {
return // popup page received
}

const tabs = await browser.tabs.query({
active: true,
currentWindow: true
})
if (tabs.length <= 0 || tabs[0].id == null) {
return
}
message.send(tabs[0].id, { type: 'ADD_NOTEBOOK', payload: { popup: false } })
}
8 changes: 8 additions & 0 deletions src/content/redux/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ export const init = (
return isPopupPage() ? Promise.resolve(true) : Promise.resolve()
}

case 'ADD_NOTEBOOK': {
if (msg.payload.popup === isPopupPage()) {
dispatch({ type: 'ADD_TO_NOTEBOOK' })
return Promise.resolve(true)
}
return
}

case 'QS_PANEL_SEARCH_TEXT':
if (isQuickSearchPage()) {
// request searching text, from other tabs
Expand Down
3 changes: 3 additions & 0 deletions src/manifest/common.manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ module.exports = {
},
'profile-5': {
description: '__MSG_command_profile_5__'
},
'add-notebook': {
description: '__MSG_command_add_notebook__'
}
},

Expand Down
10 changes: 10 additions & 0 deletions src/typings/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,16 @@ export type MessageConfig = MessageConfigType<{
}
}

/** From backend to active panel */
ADD_NOTEBOOK: {
payload: {
/** to browser action page */
popup: boolean
}
/** is received */
response?: boolean
}

/** send to the current active tab for selection */
PRELOAD_SELECTION: {
response: Word
Expand Down

0 comments on commit 524dd6c

Please sign in to comment.