Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/chrisvander/markdown-editor. A clean markdown editor written with Electron
Something went wrong. Try again.
markdown-editor main.js
4.7 kB · 241 lines
JavaScript
at master
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242// import {enableLiveReload} from 'electron-compile';//// enableLiveReload();
const {app, BrowserWindow, Menu} = require('electron')
let winapp.on('ready', () => { // Create the browser window. if (process.platform === 'darwin') { win = new BrowserWindow({ width: 800, height: 600, frame: 'false', titleBarStyle: 'hiddenInset', show: false }) } else { win = new BrowserWindow({ width: 800, height: 600, frame: false, show: false }) }
win.once('ready-to-show', () => { win.show() })
// and load the index.html of the app. win.loadFile('index.html')
// Emitted when the window is closed. win.on('closed', () => { // Dereference the window object, usually you would store windows // in an array if your app supports multi windows, this is the time // when you should delete the corresponding element. win = null }) setMainMenu();});
// This method will be called when Electron has finished// initialization and is ready to create browser windows.// Some APIs can only be used after this event occurs.
// Quit when all windows are closed.app.on('window-all-closed', () => { // On macOS it is common for applications and their menu bar // to stay active until the user quits explicitly with Cmd + Q if (process.platform !== 'darwin') { app.quit() }})
app.on('activate', () => { // On macOS it's common to re-create a window in the app when the // dock icon is clicked and there are no other windows open. if (win === null) { createWindow() }})
function setMainMenu() { const template = [ { label: 'Edit', submenu: [ { role: 'undo' }, { role: 'redo' }, { type: 'separator' }, { role: 'cut' }, { role: 'copy' }, { role: 'paste' }, { role: 'pasteandmatchstyle' }, { role: 'delete' }, { role: 'selectall' } ] }, { label: 'View', submenu: [ { role: 'togglefullscreen' }, { label: 'Developer', submenu: [ { role: 'reload' }, { role: 'forcereload' }, { role: 'toggledevtools' }, ] }, ] }, { role: 'window', submenu: [ { role: 'minimize' }, { role: 'close' } ] }, { role: 'help', submenu: [ { label: 'Learn More', click () { shell.openExternal('https://electron.atom.io') } }, { label: 'Documentation', click () { shell.openExternal( `https://github.com/electron/electron/tree/v${process.versions.electron}/docs#readme` ) } }, { label: 'Community Discussions', click () { shell.openExternal('https://discuss.atom.io/c/electron') } }, { label: 'Search Issues', click () { shell.openExternal('https://github.com/electron/electron/issues') } } ] } ]
if (process.platform === 'darwin') { template.unshift({ label: 'Electron', submenu: [ { role: 'about' }, { type: 'separator' }, { role: 'services', submenu: [] }, { type: 'separator' }, { role: 'hide' }, { role: 'hideothers' }, { role: 'unhide' }, { type: 'separator' }, { role: 'quit' } ] }) template[1].submenu.push( { type: 'separator' }, { label: 'Speech', submenu: [ { role: 'startspeaking' }, { role: 'stopspeaking' } ] } ) template[3].submenu = [ { role: 'close' }, { role: 'minimize' }, { type: 'separator' }, { role: 'front' } ] } else { template.unshift({ label: 'File', submenu: [ { role: 'quit' } ] }) } Menu.setApplicationMenu(Menu.buildFromTemplate(template));}