-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from chrisknepper/feature/add-context-menu-and…
…-changelog -Add right-click/context menu a la normal browser would have (Fixes #38)
- Loading branch information
Showing
8 changed files
with
203 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
## [0.4.0] - 2018-07-14 | ||
### Added | ||
- Right-click context menu with support for cut/copy/paste/undo/redo/save image/save video | ||
- Builds for pacman package manager (used by Arch Linux and related distros) | ||
- Changelog (with shortcut to changelog in Help menu) | ||
|
||
### Changed | ||
- Update README.md | ||
- On launch, open dev tools for the webview when in dev mode | ||
|
||
### Fixed | ||
- App icon not showing or showing sporadically on Linux | ||
|
||
### Removed | ||
- Some dead code/comments | ||
|
||
## [0.3.0] - 2018-07-08 | ||
### Added | ||
- Tray icon support for macOS and Linux | ||
- Show/hide toggle to tray context menu | ||
- File menu with items to manually check for updates and quit the app | ||
- Standard Window menu provided by electron (with proper minimize/hide items and keyboard shortcuts) | ||
- One-time notification about minimizing to tray on Windows | ||
- Build scripts to only build instead of building and attempting to publish a release | ||
|
||
### Changed | ||
- Minimize/close behavior on Windows and Linux (minimizing now minimizes, closing now minimizes to tray) | ||
- Refactor menu code | ||
|
||
### Fixed | ||
- Command+H app hiding behavior on macOS (now defocuses app when hiding window) | ||
|
||
## [0.2.0] - 2018-07-05 | ||
### Added | ||
- Setting to auto-hide menu bar (and toggle its appearance via the standard Alt+H shortcut) on Windows and Linux | ||
- electron-settings dependency for managing the above and future user settings | ||
- Screenshots of Windows tray and macOS dock functionality | ||
|
||
### Changed | ||
- Update README.md | ||
|
||
### Removed | ||
- "Hello World" code and unit/e2e tests from boilerplate | ||
|
||
## [0.1.0] - 2018-06-27 | ||
### Added | ||
- Notification count badge in dock on macOS (clears on window focus/app.activate) | ||
- Tray icon and minimizing to tray for Windows | ||
- Command+H shortcut to hide app on macOS | ||
|
||
### Changed | ||
- Closing window on macOS now doesn't quit app (expected UX on macOS) | ||
- Prevent multiple instances of app being able to launch (for example, when minimized to tray on Windows without pinning to taskbar, then clicking a shortcut from the Start menu) | ||
- Update README.md | ||
|
||
## [0.0.5] - 2018-06-26 | ||
### Changed | ||
- Update README.md | ||
- Update shape of chat bubble in icon | ||
- Use different combination of scripts to generate icons | ||
|
||
### Fixed | ||
- Corrupt icons in Windows Taskbar and macOS Spotlight | ||
|
||
## [0.0.4] - 2018-06-24 | ||
### Changed | ||
- README.md even more complete | ||
|
||
### Fixed | ||
- Hyperlinks in text messages now open in system default browser when clicked | ||
|
||
## [0.0.3] - 2018-06-22 | ||
### Changed | ||
- Nothing besides the version number, just created this version to test auto-update functionality | ||
|
||
## [0.0.2] - 2018-06-22 | ||
### Added | ||
- Signed app binary for macOS | ||
- Notifications on Windows | ||
- Builds for various Linux distros/package managers | ||
- A real icon | ||
- Auto-update mechanism via electron-updater | ||
- TODOs | ||
|
||
### Changed | ||
- README.md more complete | ||
- package.json more complete | ||
- Values and code elements from boilerplate updates | ||
- Automatically pop-up dev tools in dev mode | ||
- Generate icons via a script | ||
|
||
## 0.0.1 - 2018-06-21 | ||
### Added | ||
- Project files (initial release) | ||
|
||
### Changed | ||
- It works! (I think hope) | ||
- No Linux binary, no signing certs for Mac/Windows, no actual icon...but it's a start. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,97 @@ | ||
// This gives you default context menu (cut, copy, paste) | ||
// in all input fields and textareas across your app. | ||
// Provide context menus (copy, paste, save image, etc...) for right-click interaction. | ||
// Must not contain certain newer JS syntaxes to allow use inside a webview. | ||
|
||
import { remote } from "electron"; | ||
const remote = require('electron').remote; | ||
|
||
const Menu = remote.Menu; | ||
const MenuItem = remote.MenuItem; | ||
|
||
const isAnyTextSelected = () => { | ||
return window.getSelection().toString() !== ""; | ||
}; | ||
|
||
const cut = new MenuItem({ | ||
label: "Cut", | ||
click: () => { | ||
document.execCommand("cut"); | ||
} | ||
}); | ||
|
||
const copy = new MenuItem({ | ||
label: "Copy", | ||
click: () => { | ||
document.execCommand("copy"); | ||
const standardMenuTemplate = [ | ||
{ | ||
label: 'Copy', | ||
role: 'copy', | ||
}, | ||
{ | ||
type: 'separator', | ||
}, | ||
{ | ||
label: 'Select All', | ||
role: 'selectall', | ||
} | ||
}); | ||
]; | ||
|
||
const paste = new MenuItem({ | ||
label: "Paste", | ||
click: () => { | ||
document.execCommand("paste"); | ||
const textMenuTemplate = [ | ||
{ | ||
label: 'Undo', | ||
role: 'undo', | ||
}, | ||
{ | ||
label: 'Redo', | ||
role: 'redo', | ||
}, | ||
{ | ||
type: 'separator', | ||
}, | ||
{ | ||
label: 'Cut', | ||
role: 'cut', | ||
}, | ||
{ | ||
label: 'Copy', | ||
role: 'copy', | ||
}, | ||
{ | ||
label: 'Paste', | ||
role: 'paste', | ||
}, | ||
{ | ||
type: 'separator', | ||
}, | ||
{ | ||
label: 'Select All', | ||
role: 'selectall', | ||
} | ||
}); | ||
]; | ||
|
||
const normalMenu = new Menu(); | ||
normalMenu.append(copy); | ||
const standardInputMenu = Menu.buildFromTemplate(standardMenuTemplate); | ||
const textInputMenu = Menu.buildFromTemplate(textMenuTemplate); | ||
|
||
const textEditingMenu = new Menu(); | ||
textEditingMenu.append(cut); | ||
textEditingMenu.append(copy); | ||
textEditingMenu.append(paste); | ||
const popupContextMenu = (event) => { | ||
switch (event.target.nodeName) { | ||
case 'VIDEO': | ||
case 'IMG': | ||
if (event.target.src && event.target.src.length) { | ||
let mediaType = event.target.nodeName === 'IMG' ? 'Image' : 'Video'; | ||
const mediaInputMenu = Menu.buildFromTemplate([{ | ||
label: `Save ${mediaType} As...`, | ||
click: () => { | ||
// This call *would* do this in one line, but is only a thing in IE (???) | ||
// document.execCommand('SaveAs', true, event.target.src); | ||
const link = document.createElement('a'); | ||
link.href = event.target.src; | ||
// Leaving the URL root results in the file extension being truncated. | ||
// The resulting filename from this also appears to be consistent with | ||
// saving the image via dragging or the Chrome context menu...winning! | ||
link.download = event.target.src.replace('blob:https://messages.android.com/', ''); | ||
document.body.appendChild(link); | ||
link.click(); | ||
document.body.removeChild(link); | ||
} | ||
}]); | ||
mediaInputMenu.popup({ | ||
window: remote.getCurrentWindow(), | ||
callback: () => { | ||
mediaInputMenu = null; // Unsure if memory would leak without this (Clean up, clean up, everybody do your share) | ||
} | ||
}); | ||
} | ||
break; | ||
default: | ||
if (event.target.isContentEditable) { | ||
textInputMenu.popup(remote.getCurrentWindow()); | ||
} else { // Omit options pertaining to input fields if this isn't one | ||
standardInputMenu.popup(remote.getCurrentWindow()); | ||
} | ||
} | ||
}; | ||
|
||
document.addEventListener( | ||
"contextmenu", | ||
event => { | ||
switch (event.target.nodeName) { | ||
case "TEXTAREA": | ||
case "INPUT": | ||
event.preventDefault(); | ||
textEditingMenu.popup(remote.getCurrentWindow()); | ||
break; | ||
default: | ||
if (isAnyTextSelected()) { | ||
event.preventDefault(); | ||
normalMenu.popup(remote.getCurrentWindow()); | ||
} | ||
} | ||
}, | ||
false | ||
); | ||
module.exports = popupContextMenu; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// This script is injected into the webview. | ||
// Newer ES6 features (import/export syntax etc...) are not allowed here nor in any JS which this imports. | ||
|
||
const popupContextMenu = require('./context_menu.js'); | ||
|
||
// Electron (or the build of Chromium it uses?) does not seem to have any default right-click menu, this adds our own. | ||
window.addEventListener('contextmenu', popupContextMenu); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters