1- const fs = require ( 'electron' ) . remote . require ( 'fs' ) ;
2- const os = require ( 'electron' ) . remote . require ( 'os' ) ;
3- const path = require ( 'electron' ) . remote . require ( 'path' ) ;
4- const { ipcRenderer} = require ( 'electron' ) ;
5- const { BrowserWindow} = require ( 'electron' ) . remote ;
6- const { clipboard} = require ( 'electron' ) ;
1+ const { ipcRenderer, remote, clipboard } = require ( 'electron' ) ;
2+ const { BrowserWindow } = remote ;
73
8- const SERVER_URL = 'https://hackmd.io' ;
4+ const fs = remote . require ( 'fs' ) ;
5+ const os = remote . require ( 'os' ) ;
6+ const path = remote . require ( 'path' ) ;
97
10- const isDarwin = os . platform ( ) === 'darwin' ;
8+ const ipcClient = require ( './ipc/client' ) ;
119
12- const winOption = {
13- width : 1024 ,
14- height : 768
15- }
10+ const menu = require ( './menu' ) ;
11+
12+ const SERVER_URL = 'https://hackmd.io' ;
13+
14+ const isMac = os . platform ( ) === 'darwin' ;
1615
1716onload = ( ) => {
17+ /* inject mac specific styles */
18+ if ( isMac ) {
19+ document . querySelector ( 'navbar' ) . style . paddingLeft = '75px' ;
20+ document . querySelector ( '#navbar-container .control-buttons:nth-child(3)' ) . style . display = 'none' ;
21+ document . querySelector ( '#navbar-container .more-menu' ) . style . display = 'none' ;
22+ }
23+
1824 if ( window . location . search !== '' ) {
1925 targetURL = window . location . search . match ( / \? t a r g e t = ( [ ^ ? ] + ) / ) [ 1 ] ;
2026 } else {
@@ -63,6 +69,29 @@ onload = () => {
6369 new Notification ( 'URL copied' , { title : 'URL copied' , body : webview . getURL ( ) } ) ;
6470 }
6571
72+ document . querySelector ( '#navbar-container .more-menu' ) . onclick = ( ) => {
73+ menu . popup ( require ( 'electron' ) . remote . getCurrentWindow ( ) ) ;
74+ }
75+
76+ document . querySelector ( '#navbar-container .minimize-window' ) . onclick = ( ) => {
77+ const win = BrowserWindow . getFocusedWindow ( ) ;
78+ win . minimize ( ) ;
79+ }
80+
81+ document . querySelector ( '#navbar-container .toggle-window' ) . onclick = ( ) => {
82+ const win = BrowserWindow . getFocusedWindow ( ) ;
83+ if ( win . isMaximized ( ) ) {
84+ win . unmaximize ( ) ;
85+ } else {
86+ win . maximize ( ) ;
87+ }
88+ }
89+
90+ document . querySelector ( '#navbar-container .close-window' ) . onclick = ( ) => {
91+ const win = BrowserWindow . getFocusedWindow ( ) ;
92+ win . close ( ) ;
93+ }
94+
6695 // webview.openDevTools();
6796 } ) ;
6897
@@ -73,10 +102,6 @@ onload = () => {
73102
74103 /* handle _target=blank pages */
75104 webview . addEventListener ( 'new-window' , ( event ) => {
76- new BrowserWindow (
77- ( isDarwin
78- ? Object . assign ( { } , winOption , { titleBarStyle : 'hidden' } )
79- : winOption )
80- ) . loadURL ( `file://${ path . join ( __dirname , `index.html?target=${ event . url } ` ) } ` ) ;
105+ ipcClient ( 'createWindow' , { url : `file://${ path . join ( __dirname , `index.html?target=${ event . url } ` ) } ` } ) ;
81106 } ) ;
82107}
0 commit comments