memex/main.js

120 lines
2.0 KiB
JavaScript
Raw Normal View History

2018-07-21 11:23:06 +00:00
const {app, BrowserWindow, webFrame, Menu} = require('electron')
const path = require('path')
const url = require('url')
const shell = require('electron').shell;
const fs = require('fs');
2018-08-05 15:19:05 +00:00
const { ipcMain } = require('electron');
const FILELOCATION = 'docs/content/data.ndtl';
2018-07-21 11:23:06 +00:00
let is_shown = true;
this.handleRedirect = (e, url) =>
{
if(url != app.win.webContents.getURL())
{
e.preventDefault()
require('electron').shell.openExternal(url)
}
}
app.inspect = function()
{
app.win.toggleDevTools();
}
app.toggle_fullscreen = function()
{
app.win.setFullScreen(app.win.isFullScreen() ? false : true);
}
app.toggle_visible = function()
{
if(process.platform == "win32")
{
if(!app.win.isMinimized())
{
app.win.minimize();
}
else
{
app.win.restore();
}
}
else
{
if(is_shown)
{
app.win.hide();
}
else
{
app.win.show();
}
2018-07-21 11:23:06 +00:00
}
}
app.inject_menu = function(m)
{
Menu.setApplicationMenu(Menu.buildFromTemplate(m));
}
app.path = function()
{
return __dirname
}
app.win = null;
app.on('ready', () =>
{
app.win = new BrowserWindow(
{
webPreferences:
{
nodeIntegration: true,
preload: path.join(__dirname, 'preload.js')
}, width: 950, height: 950, backgroundColor:"#ddd", minWidth: 587, minHeight: 540, frame:true, autoHideMenuBar: true, icon: __dirname + '/icon.ico'
})
2018-07-21 11:23:06 +00:00
app.win.loadURL(`file://${__dirname}/docs/index.html`);
2018-07-21 11:23:06 +00:00
app.win.on('closed', () =>
{
2018-07-21 11:23:06 +00:00
win = null
app.quit()
})
app.win.on('hide', function()
{
2018-07-21 11:23:06 +00:00
is_shown = false;
})
app.win.on('show', function()
{
2018-07-21 11:23:06 +00:00
is_shown = true;
})
app.win.webContents.on('will-navigate', this.handleRedirect)
app.win.webContents.on('new-window', this.handleRedirect)
})
app.on('window-all-closed', () =>
{
app.quit()
})
app.on('activate', () =>
{
2018-07-21 11:23:06 +00:00
if (app.win === null) {
createWindow()
}
})
2018-08-05 15:19:05 +00:00
ipcMain.on('write', (event, arg) =>
{
fs.appendFile(FILELOCATION, arg, function (err)
{
if (err) throw err;
console.log('Saved!');
});
});