mirror of
https://github.com/TangentFoxy/memex.git
synced 2024-11-22 04:54:23 +00:00
Refactor. Clean up and fixing electron version write functionality breaking web version.
This commit is contained in:
parent
dfc294ad86
commit
8d2eed7f3c
@ -5,15 +5,7 @@
|
|||||||
<title>memex</title>
|
<title>memex</title>
|
||||||
<link rel="stylesheet" href="asset/style.css">
|
<link rel="stylesheet" href="asset/style.css">
|
||||||
<link rel="stylesheet" href="asset/fontawesome/css/all.css">
|
<link rel="stylesheet" href="asset/fontawesome/css/all.css">
|
||||||
<!-- <meta name="viewport" content="width=device-width, initial-scale=1.0"> -->
|
|
||||||
|
|
||||||
<script>
|
|
||||||
window.nodeRequire = require;
|
|
||||||
delete window.require;
|
|
||||||
delete window.exports;
|
|
||||||
delete window.module;
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<script src="logic/lib/imagesloaded.js"></script>
|
<script src="logic/lib/imagesloaded.js"></script>
|
||||||
<script src="logic/lib/masonry.js"></script>
|
<script src="logic/lib/masonry.js"></script>
|
||||||
<script src="logic/lib/runic.js"></script>
|
<script src="logic/lib/runic.js"></script>
|
||||||
|
@ -7,18 +7,17 @@ function Main()
|
|||||||
this.queryPrev = '';
|
this.queryPrev = '';
|
||||||
this.queryCur = '';
|
this.queryCur = '';
|
||||||
var parent = this;
|
var parent = this;
|
||||||
|
const FILELOCATION = 'content/data.ndtl';
|
||||||
|
|
||||||
this.install = function()
|
this.install = function()
|
||||||
{
|
{
|
||||||
let dbLoaded = false;
|
|
||||||
const FILELOCATION = 'content/data.ndtl';
|
|
||||||
var client = new XMLHttpRequest();
|
var client = new XMLHttpRequest();
|
||||||
client.open('GET', FILELOCATION);
|
client.open('GET', FILELOCATION);
|
||||||
client.onreadystatechange = function()
|
client.onreadystatechange = function()
|
||||||
{
|
{
|
||||||
if (!dbLoaded && client.responseText.trim() != '')
|
if (client.responseText.trim() != '')
|
||||||
{
|
{
|
||||||
dbLoaded = true;
|
client.onreadystatechange = null;
|
||||||
parent.setup(client.responseText);
|
parent.setup(client.responseText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
89
main.js
89
main.js
@ -29,10 +29,27 @@ app.toggle_fullscreen = function()
|
|||||||
|
|
||||||
app.toggle_visible = function()
|
app.toggle_visible = function()
|
||||||
{
|
{
|
||||||
if(process.platform == "win32"){
|
if(process.platform == "win32")
|
||||||
if(!app.win.isMinimized()){ app.win.minimize(); } else{ app.win.restore(); }
|
{
|
||||||
} else {
|
if(!app.win.isMinimized())
|
||||||
if(is_shown){ app.win.hide(); } else{ app.win.show(); }
|
{
|
||||||
|
app.win.minimize();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
app.win.restore();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(is_shown)
|
||||||
|
{
|
||||||
|
app.win.hide();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
app.win.show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,34 +67,33 @@ app.win = null;
|
|||||||
|
|
||||||
app.on('ready', () =>
|
app.on('ready', () =>
|
||||||
{
|
{
|
||||||
app.win = new BrowserWindow({
|
app.win = new BrowserWindow(
|
||||||
webPreferences: {
|
{
|
||||||
nodeIntegration: true
|
webPreferences:
|
||||||
}, width: 950, height: 950, backgroundColor:"#ddd", minWidth: 587, minHeight: 540, frame:true, autoHideMenuBar: true, icon: __dirname + '/icon.ico'})
|
{
|
||||||
|
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'
|
||||||
|
})
|
||||||
|
|
||||||
app.win.loadURL(`file://${__dirname}/docs/index.html`);
|
app.win.loadURL(`file://${__dirname}/docs/index.html`);
|
||||||
// app.win.toggleDevTools();
|
|
||||||
|
|
||||||
app.win.on('closed', () => {
|
app.win.on('closed', () =>
|
||||||
|
{
|
||||||
win = null
|
win = null
|
||||||
app.quit()
|
app.quit()
|
||||||
})
|
})
|
||||||
|
|
||||||
app.win.on('hide',function() {
|
app.win.on('hide', function()
|
||||||
|
{
|
||||||
is_shown = false;
|
is_shown = false;
|
||||||
})
|
})
|
||||||
|
|
||||||
app.win.on('show',function() {
|
app.win.on('show', function()
|
||||||
|
{
|
||||||
is_shown = true;
|
is_shown = true;
|
||||||
})
|
})
|
||||||
|
|
||||||
// app.win.webContents.on('new-window', function(event, url){
|
|
||||||
// event.preventDefault();
|
|
||||||
// // open(url);
|
|
||||||
// console.log('CALLED NEW WIN');
|
|
||||||
// child_process.execSync('start ' + url)
|
|
||||||
// })
|
|
||||||
|
|
||||||
app.win.webContents.on('will-navigate', this.handleRedirect)
|
app.win.webContents.on('will-navigate', this.handleRedirect)
|
||||||
app.win.webContents.on('new-window', this.handleRedirect)
|
app.win.webContents.on('new-window', this.handleRedirect)
|
||||||
})
|
})
|
||||||
@ -87,7 +103,8 @@ app.on('window-all-closed', () =>
|
|||||||
app.quit()
|
app.quit()
|
||||||
})
|
})
|
||||||
|
|
||||||
app.on('activate', () => {
|
app.on('activate', () =>
|
||||||
|
{
|
||||||
if (app.win === null) {
|
if (app.win === null) {
|
||||||
createWindow()
|
createWindow()
|
||||||
}
|
}
|
||||||
@ -95,36 +112,8 @@ app.on('activate', () => {
|
|||||||
|
|
||||||
ipcMain.on('write', (event, arg) =>
|
ipcMain.on('write', (event, arg) =>
|
||||||
{
|
{
|
||||||
// var fileLength = fs.statSync(FILELOCATION)['size'];
|
fs.appendFile(FILELOCATION, arg, function (err)
|
||||||
// console.log('Write called! Length = ' + fileLength);
|
{
|
||||||
// console.log('Write called! Entry = ' + arg);
|
|
||||||
|
|
||||||
// const stream = fs.createReadStream(FILELOCATION, { encoding: 'utf8' });
|
|
||||||
// stream.on('data', data => {
|
|
||||||
// header = data.split(/\n/)[0];
|
|
||||||
// stream.destroy();
|
|
||||||
// });
|
|
||||||
// stream.on('close', () => {
|
|
||||||
// console.timeEnd(label);
|
|
||||||
// resolve();
|
|
||||||
// });
|
|
||||||
|
|
||||||
// fs.readFile(FILELOCATION, "utf8",
|
|
||||||
// function(err, data)
|
|
||||||
// {
|
|
||||||
// console.log(data);
|
|
||||||
// var position = data.lastIndexOf('`');
|
|
||||||
// console.log('Write called! position = ' + position);
|
|
||||||
|
|
||||||
// let fileStream = fs.openSync(FILELOCATION, 'r+');
|
|
||||||
// // let buf = new Buffer(arg);
|
|
||||||
// let buf = new Buffer('_____HERE_____');
|
|
||||||
// fs.writeSync(fileStream, buf, 0, buf.length, position);
|
|
||||||
// fs.close(fileStream);
|
|
||||||
// }
|
|
||||||
// );
|
|
||||||
|
|
||||||
fs.appendFile(FILELOCATION, arg, function (err) {
|
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
console.log('Saved!');
|
console.log('Saved!');
|
||||||
});
|
});
|
||||||
|
4
preload.js
Normal file
4
preload.js
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
window.nodeRequire = require;
|
||||||
|
delete window.require;
|
||||||
|
delete window.exports;
|
||||||
|
delete window.module;
|
Loading…
Reference in New Issue
Block a user