Skip to content

Commit 9dfce7a

Browse files
committed
Add copy url menu item / context menu
1 parent 66f10fa commit 9dfce7a

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

ipc/consumer.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ module.exports = function (commandId, args = {}) {
4040
})
4141
}
4242
}).catch(err => console.log(err))
43+
case 'copyUrl':
44+
BrowserWindow.getFocusedWindow().webContents.send('copy-url')
45+
break
4346
default:
4447
break
4548
}

menu.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ const template = [
4646
{
4747
role: 'copy'
4848
},
49+
{
50+
label: 'Copy URL',
51+
click () {
52+
exec('copyUrl')
53+
}
54+
},
4955
{
5056
role: 'paste'
5157
},

renderer.js

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const { ipcRenderer, remote, clipboard } = require('electron')
2-
const { BrowserWindow } = remote
2+
const { BrowserWindow, Menu } = remote
33

44
const os = remote.require('os')
55
const path = remote.require('path')
@@ -22,7 +22,9 @@ window.onload = () => {
2222
if (isMac) {
2323
document.querySelector('navbar').style.paddingLeft = '75px'
2424
document.querySelector('#navbar-container .control-buttons:nth-child(3)').style.display = 'none'
25-
document.querySelector('#navbar-container .more-menu').style.display = 'none'
25+
if (process.env.NODE_ENV !== 'development') {
26+
document.querySelector('#navbar-container .more-menu').style.display = 'none'
27+
}
2628
}
2729

2830
let targetURL
@@ -36,6 +38,18 @@ window.onload = () => {
3638

3739
const webview = document.getElementById('main-window')
3840

41+
function copyUrl () {
42+
clipboard.writeText(webview.getURL())
43+
new Notification('URL copied', { title: 'URL copied', body: webview.getURL() }) // eslint-disable-line no-new
44+
}
45+
46+
const navbarMenu = Menu.buildFromTemplate([{
47+
label: 'Copy URL',
48+
click () {
49+
copyUrl()
50+
}
51+
}])
52+
3953
webview.addEventListener('dom-ready', function () {
4054
// set webview title
4155
document.querySelector('#navbar-container .title').innerHTML = webview.getTitle()
@@ -69,13 +83,8 @@ window.onload = () => {
6983
webview.loadURL(webview.getURL())
7084
}
7185

72-
document.querySelector('#navbar-container .title').onclick = () => {
73-
clipboard.writeText(webview.getURL())
74-
Notification('URL copied', { title: 'URL copied', body: webview.getURL() })
75-
}
76-
7786
document.querySelector('#navbar-container .more-menu').onclick = () => {
78-
menu.popup(require('electron').remote.getCurrentWindow())
87+
menu.popup(remote.getCurrentWindow())
7988
}
8089

8190
document.querySelector('#navbar-container .minimize-window').onclick = () => {
@@ -97,6 +106,10 @@ window.onload = () => {
97106
win.close()
98107
}
99108

109+
document.querySelector('#navbar-container').addEventListener('contextmenu', () => {
110+
navbarMenu.popup(remote.getCurrentWindow())
111+
})
112+
100113
if (process.env.NODE_ENV === 'development') {
101114
webview.openDevTools()
102115
}
@@ -141,6 +154,11 @@ window.onload = () => {
141154
ipcRenderer.on('supported-version', () => {
142155
$('navbar').removeClass('unsupported')
143156
})
157+
158+
ipcRenderer.on('copy-url', () => {
159+
copyUrl()
160+
})
161+
144162
$('#serverurl-config-modal.modal #submit-serverurl').click(function () {
145163
let serverurl = $('#serverurl-config-modal.modal input[type="text"]').val()
146164

0 commit comments

Comments
 (0)