Skip to content

Commit

Permalink
[desktop] Add context menu
Browse files Browse the repository at this point in the history
Summary:
[ENG-4407](https://linear.app/comm/issue/ENG-4407/no-way-to-right-click-in-electron#comment-0e8041e9)

Adds a right click context menu to the electron app. Uses `electron-context-menu` for that, because it comes with some nice defaults and window handling.

The [github page readme](https://github.com/sindresorhus/electron-context-menu) contains a nice explanation of available options, so if anyone thinks we should change the list I'm open to that.

Adding ashoat as there's a new dependency

Test Plan:
Right click on text and images and check if context menu is displayed:

{F645098}

{F645099}

I checked if all visibile options work as expected.

On windows it should work the same way, it will just show an additional "Select All" option.

Reviewers: kamil, inka, ashoat

Reviewed By: inka

Subscribers: tomek

Differential Revision: https://phab.comm.dev/D8573
  • Loading branch information
MichalGniadek committed Aug 2, 2023
1 parent 7df7998 commit f5fdef7
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 2 deletions.
3 changes: 2 additions & 1 deletion desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"clean-build": "rm -rf out/"
},
"dependencies": {
"@babel/runtime": "^7.20.1"
"@babel/runtime": "^7.20.1",
"electron-context-menu": "^3.6.1"
},
"optionalDependencies": {
"@commapp/windowspush": "file:addons/windows-pushnotifications"
Expand Down
5 changes: 5 additions & 0 deletions desktop/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
autoUpdater,
// eslint-disable-next-line import/extensions
} from 'electron/main';
import contextMenu from 'electron-context-menu';
import fs from 'fs';
import path from 'path';

Expand Down Expand Up @@ -263,6 +264,10 @@ const show = (urlPath?: string) => {

const run = () => {
app.setName('Comm');
contextMenu({
showSaveImageAs: true,
showSaveVideoAs: true,
});
if (process.platform === 'win32') {
app.setAppUserModelId('Comm');
}
Expand Down
72 changes: 71 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10238,6 +10238,24 @@ [email protected]:
dependencies:
"@json-rpc-tools/provider" "^1.5.5"

electron-context-menu@^3.6.1:
version "3.6.1"
resolved "https://registry.yarnpkg.com/electron-context-menu/-/electron-context-menu-3.6.1.tgz#42f117e15309687b22283e6f8f7a0d95a19afe84"
integrity sha512-lcpO6tzzKUROeirhzBjdBWNqayEThmdW+2I2s6H6QMrwqTVyT3EK47jW3Nxm60KTxl5/bWfEoIruoUNn57/QkQ==
dependencies:
cli-truncate "^2.1.0"
electron-dl "^3.2.1"
electron-is-dev "^2.0.0"

electron-dl@^3.2.1:
version "3.5.0"
resolved "https://registry.yarnpkg.com/electron-dl/-/electron-dl-3.5.0.tgz#7a80bf13f168f7e5204774eee89dbc7c86de957b"
integrity sha512-Oj+VSuScVx8hEKM2HEvTQswTX6G3MLh7UoAz/oZuvKyNDfudNi1zY6PK/UnFoK1nCl9DF6k+3PFwElKbtZlDig==
dependencies:
ext-name "^5.0.0"
pupa "^2.0.1"
unused-filename "^2.1.0"

electron-installer-dmg@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/electron-installer-dmg/-/electron-installer-dmg-4.0.0.tgz#0520bcc8a928e559b3f16fc5cbc12b182a66ea1c"
Expand All @@ -10248,6 +10266,11 @@ electron-installer-dmg@^4.0.0:
optionalDependencies:
appdmg "^0.6.4"

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-packager@^17.1.1:
version "17.1.1"
resolved "https://registry.yarnpkg.com/electron-packager/-/electron-packager-17.1.1.tgz#f156fc63d3a66f4e902e4b42992550a172982d59"
Expand Down Expand Up @@ -11535,6 +11558,21 @@ express@^4.17.3:
utils-merge "1.0.1"
vary "~1.1.2"

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-shallow@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/extend-shallow/-/extend-shallow-2.0.1.tgz#51af7d614ad9a9f610ea1bafbb989d6b1c56890f"
Expand Down Expand Up @@ -14085,6 +14123,11 @@ 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.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/is-plain-obj/-/is-plain-obj-1.1.0.tgz#71a50c8429dfca773c92a390a4a03b39fcd51d3e"
integrity sha512-yvkRyxmFKEOQ4pNXCmJG5AEQNlXJS5LaONXo5/cLdTZdWvsZ1ioJEonLGAosKlMWE8lwUy/bJzMjcw8az73+Fg==

is-plain-obj@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/is-plain-obj/-/is-plain-obj-2.1.0.tgz#45e42e37fccf1f40da8e5f76ee21515840c09287"
Expand Down Expand Up @@ -17054,7 +17097,7 @@ micromatch@^4.0.2, micromatch@^4.0.4:
braces "^3.0.1"
picomatch "^2.2.3"

[email protected], "mime-db@>= 1.43.0 < 2":
[email protected], "mime-db@>= 1.43.0 < 2", mime-db@^1.28.0:
version "1.52.0"
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.52.0.tgz#bbabcdc02859f4987301c856e3387ce5ec43bf70"
integrity sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==
Expand Down Expand Up @@ -17315,6 +17358,11 @@ mkdirp@^1.0.3:
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-1.0.3.tgz#4cf2e30ad45959dddea53ad97d518b6c8205e1ea"
integrity sha512-6uCP4Qc0sWsgMLy1EOqqS/3rjDHOEnsStVr/4vtAIK2Y5i2kA7lFFejYrpIyiN9w0pYf4ckeCYT9f1r1P9KX5g==

modify-filename@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/modify-filename/-/modify-filename-1.1.0.tgz#9a2dec83806fbb2d975f22beec859ca26b393aa1"
integrity sha512-EickqnKq3kVVaZisYuCxhtKbZjInCuwgwZWyAmRIp1NTMhri7r3380/uqwrUHfaDiPzLVTuoNy4whX66bxPVog==

morgan@^1.10.0:
version "1.10.0"
resolved "https://registry.yarnpkg.com/morgan/-/morgan-1.10.0.tgz#091778abc1fc47cd3509824653dae1faab6b17d7"
Expand Down Expand Up @@ -21784,6 +21832,20 @@ sonic-boom@^2.2.1:
dependencies:
atomic-sleep "^1.0.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 sha512-GRbEOUqCxemTAk/b32F2xa8wDTs+Z1QHOkbhJDQTvv/6G3ZkbJ+frYWsTcc7cBB3Fu4wy4XlLCuNtJuMn7Gsvw==
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 sha512-vzn8aSqKgytVik0iwdBEi+zevbTYZogewTUM6dtpmGwEcdzbub/TX4bCzRhebDCRC3QzXgJsLRKB2V/Oof7HXg==
dependencies:
is-plain-obj "^1.0.0"

sorted-array-functions@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/sorted-array-functions/-/sorted-array-functions-1.3.0.tgz#8605695563294dffb2c9796d602bd8459f7a0dd5"
Expand Down Expand Up @@ -23402,6 +23464,14 @@ unset-value@^1.0.0:
has-value "^0.3.1"
isobject "^3.0.0"

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"

unzip-response@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/unzip-response/-/unzip-response-2.0.1.tgz#d2f0f737d16b0615e72a6935ed04214572d56f97"
Expand Down

0 comments on commit f5fdef7

Please sign in to comment.