mirror of
https://github.com/purocean/yn.git
synced 2026-10-25 10:04:39 +08:00
feat: add electron context menu
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"command-exists": "^1.2.9",
|
||||
"electron-context-menu": "^3.1.1",
|
||||
"electron-log": "^4.3.5",
|
||||
"electron-progressbar": "^2.0.1",
|
||||
"electron-store": "^5.2.0",
|
||||
|
||||
+13
-10
@@ -2,9 +2,10 @@ import { protocol, app, BrowserWindow, Menu, Tray, powerMonitor, dialog, OpenDia
|
||||
import * as path from 'path'
|
||||
import * as os from 'os'
|
||||
import * as yargs from 'yargs'
|
||||
import ElectronContextmenu from 'electron-context-menu'
|
||||
import server from './server'
|
||||
import { APP_NAME } from './constant'
|
||||
import { inputMenu, selectionMenu, getTrayMenus, getMainMenus } from './menus'
|
||||
import { getTrayMenus, getMainMenus } from './menus'
|
||||
import { transformProtocolRequest } from './protocol'
|
||||
import opn from 'opn'
|
||||
import startup from './startup'
|
||||
@@ -22,6 +23,17 @@ const trayEnabled = !(yargs.argv['disable-tray'])
|
||||
const backendPort = Number(yargs.argv.port) || 3044
|
||||
const devFrontendPort = 8066
|
||||
|
||||
ElectronContextmenu({
|
||||
showLookUpSelection: true,
|
||||
showSearchWithGoogle: false,
|
||||
showCopyImage: true,
|
||||
showCopyImageAddress: false,
|
||||
showSaveImage: false,
|
||||
showSaveImageAs: true,
|
||||
showSaveLinkAs: false,
|
||||
showInspectElement: false,
|
||||
showServices: true,
|
||||
})
|
||||
Menu.setApplicationMenu(getMainMenus())
|
||||
|
||||
let fullscreen = false
|
||||
@@ -287,15 +299,6 @@ if (!gotTheLock) {
|
||||
})
|
||||
|
||||
app.on('web-contents-created', (_, webContents) => {
|
||||
webContents.on('context-menu', (_, props) => {
|
||||
const { selectionText, isEditable } = props
|
||||
if (isEditable) {
|
||||
inputMenu.popup({ window: win || undefined })
|
||||
} else if (selectionText && selectionText.trim() !== '') {
|
||||
selectionMenu.popup({ window: win || undefined })
|
||||
}
|
||||
})
|
||||
|
||||
webContents.on('new-window', (e, url) => {
|
||||
const allowList = [
|
||||
`${APP_NAME}://`,
|
||||
|
||||
@@ -6,21 +6,6 @@ import { getAccelerator } from './shortcut'
|
||||
import { checkForUpdates } from './updater'
|
||||
import { $t } from './i18n'
|
||||
|
||||
export const selectionMenu = Menu.buildFromTemplate([
|
||||
{ role: 'copy' },
|
||||
])
|
||||
|
||||
export const inputMenu = Menu.buildFromTemplate([
|
||||
{ role: 'copy' },
|
||||
{ role: 'paste' },
|
||||
{ role: 'cut' },
|
||||
{ type: 'separator' },
|
||||
{ role: 'undo' },
|
||||
{ role: 'redo' },
|
||||
{ type: 'separator' },
|
||||
{ role: 'selectAll' },
|
||||
])
|
||||
|
||||
export const getMainMenus = () => process.platform === 'darwin' ? Menu.buildFromTemplate([
|
||||
{
|
||||
label: 'Application',
|
||||
|
||||
@@ -1579,6 +1579,14 @@ cli-truncate@^1.1.0:
|
||||
slice-ansi "^1.0.0"
|
||||
string-width "^2.0.0"
|
||||
|
||||
cli-truncate@^2.1.0:
|
||||
version "2.1.0"
|
||||
resolved "https://registry.yarnpkg.com/cli-truncate/-/cli-truncate-2.1.0.tgz#c39e28bf05edcde5be3b98992a22deed5a2b93c7"
|
||||
integrity sha512-n8fOixwDD6b/ObinzTrp1ZKFzbgvKZvuz/TvejnLn1aQfC6r52XEx85FmuC+3HI+JM7coBRXUvNqEU2PHVrHpg==
|
||||
dependencies:
|
||||
slice-ansi "^3.0.0"
|
||||
string-width "^4.2.0"
|
||||
|
||||
cliui@^6.0.0:
|
||||
version "6.0.0"
|
||||
resolved "https://registry.yarnpkg.com/cliui/-/cliui-6.0.0.tgz#511d702c0c4e41ca156d7d0e96021f23e13225b1"
|
||||
@@ -2740,6 +2748,29 @@ electron-builder@^22.11.7:
|
||||
update-notifier "^5.1.0"
|
||||
yargs "^17.0.1"
|
||||
|
||||
electron-context-menu@^3.1.1:
|
||||
version "3.1.1"
|
||||
resolved "https://registry.yarnpkg.com/electron-context-menu/-/electron-context-menu-3.1.1.tgz#109884e79df293f7e85effcbdbbe45d362987d94"
|
||||
integrity sha512-LJhwaKf6XHwk2LQ5SdwoGNODoA8lRwks9bbEeAqqMf4e3hsrT7pZtX6MaHKYNFZKxF14JjI/VR+VRjGvxmaQoA==
|
||||
dependencies:
|
||||
cli-truncate "^2.1.0"
|
||||
electron-dl "^3.2.1"
|
||||
electron-is-dev "^2.0.0"
|
||||
|
||||
electron-dl@^3.2.1:
|
||||
version "3.3.0"
|
||||
resolved "https://registry.yarnpkg.com/electron-dl/-/electron-dl-3.3.0.tgz#4e422e276c627373ba61fcf3f92ffa088988db1a"
|
||||
integrity sha512-Zwaz/OMGPIfBLV2SQH4sTsdDOs/U4y5AOHfremMBXEpjIxX+SiTx845DZAvJJwgb5hfowyWOBLiJhd/emBNLLQ==
|
||||
dependencies:
|
||||
ext-name "^5.0.0"
|
||||
pupa "^2.0.1"
|
||||
unused-filename "^2.1.0"
|
||||
|
||||
electron-is-dev@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/electron-is-dev/-/electron-is-dev-2.0.0.tgz#833487a069b8dad21425c67a19847d9064ab19bd"
|
||||
integrity sha512-3X99K852Yoqu9AcW50qz3ibYBWY79/pBhlMCab8ToEWS48R0T9tyxRiQhwylE7zQdXrMnx2JKqUJyMPmt5FBqA==
|
||||
|
||||
electron-log@^4.3.5:
|
||||
version "4.3.5"
|
||||
resolved "https://registry.yarnpkg.com/electron-log/-/electron-log-4.3.5.tgz#2aad5f93842b9b5214a1b4a10e47b5ac5c9ec104"
|
||||
@@ -3358,6 +3389,21 @@ execa@^5.0.0:
|
||||
signal-exit "^3.0.3"
|
||||
strip-final-newline "^2.0.0"
|
||||
|
||||
ext-list@^2.0.0:
|
||||
version "2.2.2"
|
||||
resolved "https://registry.yarnpkg.com/ext-list/-/ext-list-2.2.2.tgz#0b98e64ed82f5acf0f2931babf69212ef52ddd37"
|
||||
integrity sha512-u+SQgsubraE6zItfVA0tBuCBhfU9ogSRnsvygI7wht9TS510oLkBRXBsqopeUG/GBOIQyKZO9wjTqIu/sf5zFA==
|
||||
dependencies:
|
||||
mime-db "^1.28.0"
|
||||
|
||||
ext-name@^5.0.0:
|
||||
version "5.0.0"
|
||||
resolved "https://registry.yarnpkg.com/ext-name/-/ext-name-5.0.0.tgz#70781981d183ee15d13993c8822045c506c8f0a6"
|
||||
integrity sha512-yblEwXAbGv1VQDmow7s38W77hzAgJAO50ztBLMcUyUBfxv1HC+LGwtiEN+Co6LtlqT/5uwVOxsD4TNIilWhwdQ==
|
||||
dependencies:
|
||||
ext-list "^2.0.0"
|
||||
sort-keys-length "^1.0.0"
|
||||
|
||||
extend@^3.0.1, extend@~3.0.2:
|
||||
version "3.0.2"
|
||||
resolved "https://registry.yarnpkg.com/extend/-/extend-3.0.2.tgz#f8b1136b4071fbd8eb140aff858b1019ec2915fa"
|
||||
@@ -4190,7 +4236,7 @@ is-path-inside@^3.0.2:
|
||||
resolved "https://registry.yarnpkg.com/is-path-inside/-/is-path-inside-3.0.3.tgz#d231362e53a07ff2b0e0ea7fed049161ffd16283"
|
||||
integrity sha512-Fd4gABb+ycGAmKou8eMftCupSir5lRxqf4aD/vd0cD2qc4HL07OjCeuHMr8Ro4CoMaeCKDB0/ECBOVWjTwUvPQ==
|
||||
|
||||
is-plain-obj@^1.1.0:
|
||||
is-plain-obj@^1.0.0, is-plain-obj@^1.1.0:
|
||||
version "1.1.0"
|
||||
resolved "https://registry.yarnpkg.com/is-plain-obj/-/is-plain-obj-1.1.0.tgz#71a50c8429dfca773c92a390a4a03b39fcd51d3e"
|
||||
integrity sha1-caUMhCnfync8kqOQpKA7OfzVHT4=
|
||||
@@ -4859,6 +4905,11 @@ mime-db@1.48.0:
|
||||
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.48.0.tgz#e35b31045dd7eada3aaad537ed88a33afbef2d1d"
|
||||
integrity sha512-FM3QwxV+TnZYQ2aRqhlKBMHxk10lTbMt3bBkMAp54ddrNeVSfcQYOOKuGuy3Ddrm38I04If834fOUSq1yzslJQ==
|
||||
|
||||
mime-db@^1.28.0:
|
||||
version "1.51.0"
|
||||
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.51.0.tgz#d9ff62451859b18342d960850dc3cfb77e63fb0c"
|
||||
integrity sha512-5y8A56jg7XVQx2mbv1lu49NR4dokRnhZYTtL+KGfaa27uq4pSTXkwQkFJl4pkRMyNFz/EtYDSkiiEHx3F7UN6g==
|
||||
|
||||
mime-types@^2.1.12, mime-types@^2.1.18, mime-types@^2.1.31, mime-types@~2.1.19, mime-types@~2.1.24:
|
||||
version "2.1.31"
|
||||
resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.31.tgz#a00d76b74317c61f9c2db2218b8e9f8e9c5c9e6b"
|
||||
@@ -4919,6 +4970,11 @@ mkdirp@^0.5.4:
|
||||
dependencies:
|
||||
minimist "^1.2.5"
|
||||
|
||||
modify-filename@^1.1.0:
|
||||
version "1.1.0"
|
||||
resolved "https://registry.yarnpkg.com/modify-filename/-/modify-filename-1.1.0.tgz#9a2dec83806fbb2d975f22beec859ca26b393aa1"
|
||||
integrity sha1-mi3sg4Bvuy2XXyK+7IWcoms5OqE=
|
||||
|
||||
moment-mini@^2.24.0:
|
||||
version "2.24.0"
|
||||
resolved "https://registry.yarnpkg.com/moment-mini/-/moment-mini-2.24.0.tgz#fa68d98f7fe93ae65bf1262f6abb5fb6983d8d18"
|
||||
@@ -5542,7 +5598,7 @@ punycode@^2.1.0, punycode@^2.1.1:
|
||||
resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec"
|
||||
integrity sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==
|
||||
|
||||
pupa@^2.1.1:
|
||||
pupa@^2.0.1, pupa@^2.1.1:
|
||||
version "2.1.1"
|
||||
resolved "https://registry.yarnpkg.com/pupa/-/pupa-2.1.1.tgz#f5e8fd4afc2c5d97828faa523549ed8744a20d62"
|
||||
integrity sha512-l1jNAspIBSFqbT+y+5FosojNpVpF94nlI+wDUpqP9enwOTfHx9f0gh5nB96vl+6yTpsJsypeNrwfzPrKuHB41A==
|
||||
@@ -5972,6 +6028,15 @@ slice-ansi@^1.0.0:
|
||||
dependencies:
|
||||
is-fullwidth-code-point "^2.0.0"
|
||||
|
||||
slice-ansi@^3.0.0:
|
||||
version "3.0.0"
|
||||
resolved "https://registry.yarnpkg.com/slice-ansi/-/slice-ansi-3.0.0.tgz#31ddc10930a1b7e0b67b08c96c2f49b77a789787"
|
||||
integrity sha512-pSyv7bSTC7ig9Dcgbw9AuRNUb5k5V6oDudjZoMBSr13qpLBG7tB+zgCkARjq7xIUgdz5P1Qe8u+rSGdouOOIyQ==
|
||||
dependencies:
|
||||
ansi-styles "^4.0.0"
|
||||
astral-regex "^2.0.0"
|
||||
is-fullwidth-code-point "^3.0.0"
|
||||
|
||||
slice-ansi@^4.0.0:
|
||||
version "4.0.0"
|
||||
resolved "https://registry.yarnpkg.com/slice-ansi/-/slice-ansi-4.0.0.tgz#500e8dd0fd55b05815086255b3195adf2a45fe6b"
|
||||
@@ -6060,6 +6125,20 @@ socks@^2.6.1:
|
||||
ip "^1.1.5"
|
||||
smart-buffer "^4.1.0"
|
||||
|
||||
sort-keys-length@^1.0.0:
|
||||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/sort-keys-length/-/sort-keys-length-1.0.1.tgz#9cb6f4f4e9e48155a6aa0671edd336ff1479a188"
|
||||
integrity sha1-nLb09OnkgVWmqgZx7dM2/xR5oYg=
|
||||
dependencies:
|
||||
sort-keys "^1.0.0"
|
||||
|
||||
sort-keys@^1.0.0:
|
||||
version "1.1.2"
|
||||
resolved "https://registry.yarnpkg.com/sort-keys/-/sort-keys-1.1.2.tgz#441b6d4d346798f1b4e49e8920adfba0e543f9ad"
|
||||
integrity sha1-RBttTTRnmPG05J6JIK37oOVD+a0=
|
||||
dependencies:
|
||||
is-plain-obj "^1.0.0"
|
||||
|
||||
sortablejs@^1.13.0:
|
||||
version "1.13.0"
|
||||
resolved "https://registry.yarnpkg.com/sortablejs/-/sortablejs-1.13.0.tgz#3ab2473f8c69ca63569e80b1cd1b5669b51269e9"
|
||||
@@ -6638,6 +6717,14 @@ unpipe@1.0.0:
|
||||
resolved "https://registry.yarnpkg.com/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec"
|
||||
integrity sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw=
|
||||
|
||||
unused-filename@^2.1.0:
|
||||
version "2.1.0"
|
||||
resolved "https://registry.yarnpkg.com/unused-filename/-/unused-filename-2.1.0.tgz#33719c4e8d9644f32d2dec1bc8525c6aaeb4ba51"
|
||||
integrity sha512-BMiNwJbuWmqCpAM1FqxCTD7lXF97AvfQC8Kr/DIeA6VtvhJaMDupZ82+inbjl5yVP44PcxOuCSxye1QMS0wZyg==
|
||||
dependencies:
|
||||
modify-filename "^1.1.0"
|
||||
path-exists "^4.0.0"
|
||||
|
||||
upath@^2.0.1:
|
||||
version "2.0.1"
|
||||
resolved "https://registry.yarnpkg.com/upath/-/upath-2.0.1.tgz#50c73dea68d6f6b990f51d279ce6081665d61a8b"
|
||||
|
||||
Reference in New Issue
Block a user