11const { ipcRenderer, remote, clipboard } = require ( 'electron' )
2- const { BrowserWindow } = remote
2+ const { BrowserWindow, Menu } = remote
33
44const os = remote . require ( 'os' )
55const 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