Skip to content

Commit

Permalink
Added history logging to the local
Browse files Browse the repository at this point in the history
  • Loading branch information
YomoSK committed Jun 6, 2024
1 parent a0f5768 commit 0c4bf0e
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
out
out
history.json
1 change: 1 addition & 0 deletions forge.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { FuseV1Options, FuseVersion } = require('@electron/fuses');
module.exports = {
packagerConfig: {
asar: true,
icon: './icon.png'
},
rebuildConfig: {},
makers: [
Expand Down
Binary file added icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 17 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
const { app, BrowserWindow, WebContentsView, ipcMain } = require('electron');
const fs = require('fs');
const path = require('path');
const historyFile = './history.json';

const winSize = { width: 1024, height: 600 };

function logHistory(url, date = Date.now()) {
if(!fs.existsSync(historyFile)) fs.writeFileSync(historyFile, '[]');
fs.readFile(historyFile, (err, data) => {
const history = JSON.parse(data);
history.push({ url, date });
fs.writeFile(historyFile, JSON.stringify(history), err => {
if(err) console.error(err);
});
});
}

function createWindow() {
const win = new BrowserWindow({
width: winSize.width,
Expand All @@ -15,7 +28,8 @@ function createWindow() {
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
},
icon: './icon.png'
});

const topbar = new BrowserWindow({
Expand Down Expand Up @@ -44,6 +58,7 @@ function createWindow() {
view.webContents.on('did-navigate', () => {
const url = view.webContents.getURL();
if(url.includes('about:blank')) return;
logHistory(url, Date.now() - 1);
topbar.webContents.send('navigate', url);
});
win.setContentView(view);
Expand All @@ -61,6 +76,7 @@ function createWindow() {
});

ipcMain.on('load-page', (_, url) => {
logHistory(url, Date.now());
view.webContents.loadURL(url);
win.setContentView(view);
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "yomea",
"version": "0.0.1",
"version": "0.0.2",
"description": "Chromium-based, Electron-powered private web browser",
"main": "index.js",
"scripts": {
Expand Down
1 change: 0 additions & 1 deletion public/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ nav > #tabs-wrapper > p {
font-family: 'Open Sans', sans-serif;
font-size: .85rem;
font-weight: 600;
max-width: 5.5rem;
text-wrap: nowrap;
position: relative;
}
Expand Down

0 comments on commit 0c4bf0e

Please sign in to comment.