File tree Expand file tree Collapse file tree 5 files changed +194
-14
lines changed
Expand file tree Collapse file tree 5 files changed +194
-14
lines changed Original file line number Diff line number Diff line change 1- const { app, BrowserWindow } = require ( 'electron' ) ;
1+ const { app, BrowserWindow, Menu } = require ( 'electron' ) ;
22const os = require ( 'os' ) ;
33const fs = require ( 'fs' ) ;
44const path = require ( 'path' ) ;
5+ const menu = require ( './menu' ) ;
6+ const { createWindow } = require ( './window' ) ;
57
68let mainWin ;
79
8- const winOption = {
9- width : 1024 ,
10- height : 768
11- }
12-
13- const isDarwin = os . platform ( ) === 'darwin' ;
14-
1510function initializeApp ( ) {
16- mainWin = new BrowserWindow (
17- ( isDarwin
18- ? Object . assign ( { } , winOption , { titleBarStyle : 'hidden' } )
19- : winOption )
20- ) ;
11+ Menu . setApplicationMenu ( menu ) ;
2112
22- mainWin . loadURL ( `file://${ path . join ( __dirname , 'index.html' ) } ` ) ;
13+ mainWin = createWindow ( { url : `file://${ path . join ( __dirname , 'index.html' ) } ` } ) ;
2314}
2415
2516app . on ( 'ready' , ( ) => {
Original file line number Diff line number Diff line change 1+ const { app, Menu, BrowserWindow} = require ( 'electron' ) ;
2+ const path = require ( 'path' ) ;
3+ const { createWindow } = require ( './window' ) ;
4+
5+ const template = [
6+ {
7+ label : 'File' ,
8+ submenu : [
9+ {
10+ label : 'New File' ,
11+ accelerator : 'CmdOrCtrl+N' ,
12+ click ( ) {
13+ createWindow ( { url : `file://${ path . join ( __dirname , 'index.html?target=https://hackmd.io/new' ) } ` } ) ;
14+ }
15+ } ,
16+ {
17+ label : 'New Window' ,
18+ accelerator : 'CmdOrCtrl+Shift+N' ,
19+ click ( ) {
20+ createWindow ( { url : `file://${ path . join ( __dirname , 'index.html' ) } ` } ) ;
21+ }
22+ } ,
23+ {
24+ type : 'separator'
25+ }
26+ ]
27+ } ,
28+ {
29+ label : 'Edit' ,
30+ submenu : [
31+ {
32+ role : 'undo'
33+ } ,
34+ {
35+ role : 'redo'
36+ } ,
37+ {
38+ type : 'separator'
39+ } ,
40+ {
41+ role : 'cut'
42+ } ,
43+ {
44+ role : 'copy'
45+ } ,
46+ {
47+ role : 'paste'
48+ } ,
49+ {
50+ role : 'pasteandmatchstyle'
51+ } ,
52+ {
53+ role : 'delete'
54+ } ,
55+ {
56+ role : 'selectall'
57+ }
58+ ]
59+ } ,
60+ {
61+ role : 'window' ,
62+ submenu : [
63+ {
64+ role : 'minimize'
65+ } ,
66+ {
67+ role : 'close'
68+ } ,
69+ {
70+ label : 'Refresh' ,
71+ accelerator : 'CmdOrCtrl+R' ,
72+ click ( ) {
73+ const win = BrowserWindow . getFocusedWindow ( ) ;
74+ win . webContents . send ( 'web:refresh' ) ;
75+ }
76+ } ,
77+ {
78+ type : 'separator'
79+ } ,
80+ {
81+ role : 'togglefullscreen'
82+ } ,
83+ {
84+ role : 'toggledevtools'
85+ } ,
86+ ]
87+ } ,
88+ {
89+ role : 'help' ,
90+ submenu : [
91+ {
92+ label : 'Learn More' ,
93+ click ( ) { require ( 'electron' ) . shell . openExternal ( 'https://hackmd.io' ) }
94+ }
95+ ]
96+ }
97+ ]
98+
99+ if ( process . platform === 'darwin' ) {
100+ template . unshift ( {
101+ label : app . getName ( ) ,
102+ submenu : [
103+ {
104+ role : 'about'
105+ } ,
106+ {
107+ type : 'separator'
108+ } ,
109+ {
110+ role : 'services' ,
111+ submenu : [ ]
112+ } ,
113+ {
114+ type : 'separator'
115+ } ,
116+ {
117+ role : 'hide'
118+ } ,
119+ {
120+ role : 'hideothers'
121+ } ,
122+ {
123+ role : 'unhide'
124+ } ,
125+ {
126+ type : 'separator'
127+ } ,
128+ {
129+ role : 'quit'
130+ }
131+ ]
132+ } )
133+ // Edit menu.
134+ template [ 2 ] . submenu . push (
135+ {
136+ type : 'separator'
137+ } ,
138+ {
139+ label : 'Speech' ,
140+ submenu : [
141+ {
142+ role : 'startspeaking'
143+ } ,
144+ {
145+ role : 'stopspeaking'
146+ }
147+ ]
148+ }
149+ )
150+ }
151+
152+ module . exports = Menu . buildFromTemplate ( template ) ;
Original file line number Diff line number Diff line change 11{
22 "name" : " hackmd-desktop" ,
3+ "productName" : " HackMD Desktop" ,
34 "version" : " 0.0.1" ,
45 "description" : " HackMD desktop client" ,
56 "main" : " main.js" ,
Original file line number Diff line number Diff line change 11const fs = require ( 'electron' ) . remote . require ( 'fs' ) ;
22const os = require ( 'electron' ) . remote . require ( 'os' ) ;
33const path = require ( 'electron' ) . remote . require ( 'path' ) ;
4+ const { ipcRenderer} = require ( 'electron' ) ;
45const { BrowserWindow} = require ( 'electron' ) . remote ;
56const { clipboard} = require ( 'electron' ) ;
67
@@ -27,6 +28,7 @@ onload = () => {
2728 webview . addEventListener ( 'dom-ready' , function ( ) {
2829 // set webview title
2930 document . querySelector ( '#navbar-container .title' ) . innerHTML = webview . getTitle ( ) ;
31+ document . querySelector ( 'title' ) . innerHTML = webview . getTitle ( ) ;
3032
3133 // set dark theme if in home page
3234 if ( webview . getURL ( ) . split ( '?' ) [ 0 ] . split ( '#' ) [ 0 ] . match ( / h t t p s : \/ \/ h a c k m d .i o \/ $ / ) ) {
@@ -64,6 +66,11 @@ onload = () => {
6466 // webview.openDevTools();
6567 } ) ;
6668
69+ /* handle ipc actions */
70+ ipcRenderer . on ( 'web:refresh' , ( event , message ) => {
71+ webview . loadURL ( webview . getURL ( ) ) ;
72+ } ) ;
73+
6774 /* handle _target=blank pages */
6875 webview . addEventListener ( 'new-window' , ( event ) => {
6976 new BrowserWindow (
Original file line number Diff line number Diff line change 1+ const { BrowserWindow} = require ( 'electron' ) ;
2+ const os = require ( 'os' ) ;
3+
4+ const winOption = {
5+ width : 1100 ,
6+ height : 768 ,
7+ minWidth : 522 ,
8+ minHeight : 400
9+ }
10+
11+ const isDarwin = os . platform ( ) === 'darwin' ;
12+
13+ function createWindow ( opts = { } ) {
14+ const win = new BrowserWindow (
15+ ( isDarwin
16+ ? Object . assign ( { } , winOption , { titleBarStyle : 'hidden' } )
17+ : winOption )
18+ ) ;
19+
20+ if ( opts . hasOwnProperty ( 'url' ) ) {
21+ win . loadURL ( opts . url )
22+ }
23+
24+ return win ;
25+ }
26+
27+ module . exports = {
28+ createWindow
29+ } ;
You can’t perform that action at this time.
0 commit comments