Skip to content
This repository has been archived by the owner on Dec 16, 2020. It is now read-only.

Commit

Permalink
v1.4.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Beelink committed Jun 26, 2019
1 parent 16855da commit 94e0d53
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 114 deletions.
3 changes: 2 additions & 1 deletion css/browser.css
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,8 @@
}

.notif-text {
word-break: break-all;
word-break: break-word;
word-wrap: break-word;
color: var(--color-top);
}

Expand Down
8 changes: 4 additions & 4 deletions js/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,10 @@ function installUpdate() {
removeNotifById('update-0');
}

function downloadUpdate() {
ipcRenderer.send('request-download-update');
loader('Downloading update', 'update-0');
}
// function downloadUpdate() {
// ipcRenderer.send('request-download-update');
// loader('Downloading update', 'update-0');
// }

// system pages
function goToBookmarksTab() {
Expand Down
70 changes: 43 additions & 27 deletions js/history.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
const { ipcRenderer } = require('electron');
const getTitleAtUrl = require('get-title-at-url');
const readline = require('readline');
const ppath = require('persist-path')('ArrowBrowser');
const fs = require("fs");

let rl = readline.createInterface({
input: fs.createReadStream(ppath + "\\json\\history.json")
});

var historyLineNumber = 0;

rl.on('line', function(line) {
var obj = JSON.parse(line);
createHistoryItem(historyLineNumber, obj.url, obj.time);
historyLineNumber++;
});

/*
.########.##.....##.##....##..######..########.####..#######..##....##..######.
Expand Down Expand Up @@ -94,25 +109,17 @@ function changeBorderRadius(size) {

// history
function clearHistory() {
var container = document.getElementById('history');
container.innerHTML = "";
ipcRenderer.send('request-clear-history');
notif('History cleared', 'success')
}

function loadHistory() {
var fs = require("fs");
var ppath = require('persist-path')('ArrowBrowser');

try {
var jsonstr = fs.readFileSync(ppath + "\\json\\history.json");
var arr = JSON.parse(jsonstr);
var i;
for (i = 0; i < arr.length; i++) {
createHistoryItem(arr[i].index, arr[i].url, arr[i].time);
fs.writeFileSync(ppath + "\\json\\history.json", "");
var container = document.getElementById('history');
if(container.innerHTML == "") {
notif('History is already empty!', 'info');
} else {
container.innerHTML = "";
notif('History cleared!', 'success');
}
} catch (e) {

} catch (error) {
notif('Error: ' + error, 'error')
}
}

Expand All @@ -132,11 +139,13 @@ function createHistoryItem(index, url, time) {
<img class="nav-btn-icon theme-icon" name="tab">
<label>New tab</label>
</div>
<div class="nav-btn" onclick="removeHistoryItem(` + index + `)">
<img class="nav-btn-icon theme-icon" name="delete">
<label>Remove</label>
</div>
</center>`;

// <div class="nav-btn" onclick="removeHistoryItem(` + index + `)">
// <img class="nav-btn-icon theme-icon" name="delete">
// <label>Remove</label>
// </div>
div.addEventListener('auxclick', (e) => {
e.preventDefault();
if(e.which == 2) {
Expand All @@ -151,11 +160,19 @@ function createHistoryItem(index, url, time) {
loadTheme();
}

function removeHistoryItem(index) {
var div = document.getElementById('history-' + index);
div.parentNode.removeChild(div);
ipcRenderer.send('request-remove-history-item', index);
}
// function removeHistoryItem(index) {
// var div = document.getElementById('history-' + index);
// div.parentNode.removeChild(div);

// replace({ files: ppath + "\\json\\history.json", from: , to: }, (error, results) => {
// if (error) {
// return console.error('Error occurred:', error);
// } else {

// }
// console.log('Replacement results:', results);
// });
// }

function applyTitle(url, index) {
getTitleAtUrl(url, function(title) {
Expand Down Expand Up @@ -253,7 +270,6 @@ ipcRenderer.on('action-load-border-radius', (event, arg) => {
*/

function init() {
loadHistory();
loadTheme();
loadBorderRadius();

Expand Down
4 changes: 2 additions & 2 deletions js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ function toggleBookmarksBar() {
var bookmarksBar = fs.readFileSync(ppath + "\\json\\bookmarksbar.json");
if(bookmarksBar == 1) {
ipcRenderer.send('request-set-bookmarks-bar', 0);
notif("Bookmarks bar turned off", "info");
notif("Bookmarks bar turned off!", "info");
} else {
ipcRenderer.send('request-set-bookmarks-bar', 1);
notif("Bookmarks bar turned on", "success");
notif("Bookmarks bar turned on!", "success");
}
} catch (e) {

Expand Down
86 changes: 22 additions & 64 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,6 @@ var borderRadius = '4';
var downloadsArray = [];
var curDownloadNum = 0;

var historyArray = [];
var curHistoryNum = 0;

var welcomeOn = 1;
var bookmarksBarOn = 0;

var startPage = "https://duckduckgo.com/";
Expand Down Expand Up @@ -185,7 +181,8 @@ app.on('ready', function() {
mainWindow.webContents.send('action-notif', { type: "success", text: "App is up to date!" });
});
autoUpdater.on('update-available', (info) => {
mainWindow.webContents.send('action-notif', { type: "info", text: "New version " + info.version +" is available! Download started..." });
// mainWindow.webContents.send('action-notif', { type: "info", text: "New version " + info.version +" is available! Download started..." });
mainWindow.webContents.send('action-loader', { text: "Downloading update: v" + info.version, id: "update-0" });
// mainWindow.webContents.send('action-quest', { text: "New version " + event.info.version, ops: [{ text:'Download', icon:'check', click:'downloadUpdate(); removeNotif(this.parentNode.parentNode);' }] });
});
autoUpdater.on('update-downloaded', () => {
Expand Down Expand Up @@ -448,30 +445,24 @@ ipcMain.on('request-show-certificate-info', (event, arg) => {
showPageInfoWindow(arg);
});

ipcMain.on('request-clear-history', (event, arg) => {
historyArray = [];
saveHistory();
});

ipcMain.on('request-remove-history-item', (event, arg) => {
for(var i = 0; i < historyArray.length; i++) {
if(historyArray[i].index == arg) {
historyArray.splice(i, 1);
break;
}
}
saveHistory();
});

ipcMain.on('request-add-history-item', (event, arg) => {
let Data = {
index: ++curHistoryNum,
url: arg,
time: Math.floor(Date.now() / 1000)
};
historyArray.push(Data);
saveHistory();
mainWindow.webContents.send('action-add-history-item', Data);

var fs = require('fs');

try {
fs.appendFile(app.getPath('userData') + "\\json\\history.json", JSON.stringify(Data) + "\n", function (err) {
if (err) throw err;
});
} catch (error) {
fs.writeFileSync(app.getPath('userData') + "\\json\\history.json", "");
fs.appendFile(app.getPath('userData') + "\\json\\history.json", JSON.stringify(Data), function (err) {
if (err) throw err;
});
}
});


Expand All @@ -494,7 +485,6 @@ ipcMain.on('request-set-search-engine', (event, arg) => {
});

ipcMain.on('request-show-welcome-screen', (event, arg) => {
welcomeOn = 1;
showWelcomeWindow();
});

Expand Down Expand Up @@ -532,9 +522,9 @@ ipcMain.on('request-check-for-updates', (event, arg) => {
checkForUpdates();
});

ipcMain.on('request-download-update', (event, arg) => {
downloadUpdate();
});
// ipcMain.on('request-download-update', (event, arg) => {
// downloadUpdate();
// });

ipcMain.on('request-tabs-list', (event, arg) => {
let m = new Menu();
Expand Down Expand Up @@ -691,9 +681,9 @@ function checkForUpdates() {
autoUpdater.checkForUpdates();
}

function downloadUpdate() {
autoUpdater.downloadUpdate();
}
// function downloadUpdate() {
// autoUpdater.downloadUpdate();
// }

function showWelcomeWindow() {
welcomeWindow = new BrowserWindow({
Expand Down Expand Up @@ -809,7 +799,6 @@ function showPageInfoWindow(certificate) {

function saveAllData() {
saveDownloads();
saveHistory();
saveTheme();
saveBorderRadius();
saveStartPage();
Expand All @@ -823,13 +812,6 @@ function saveDownloads() {
console.log("saved DOWNLOADS: " + downloadsArray.length);
}

function saveHistory() {
var fs = require('fs');
fs.writeFileSync(app.getPath('userData') + "\\json\\curhistorynum.json", curHistoryNum);
fs.writeFileSync(app.getPath('userData') + "\\json\\history.json", JSON.stringify(historyArray));
console.log("saved HISTORY: " + historyArray.length);
}

function saveBorderRadius() {
var fs = require('fs');
fs.writeFileSync(app.getPath('userData') + "\\json\\radius.json", borderRadius);
Expand Down Expand Up @@ -896,7 +878,6 @@ function loadAllData() {
loadBookmarksBar();
loadSearchEngine();
loadDownloads();
loadHistory();
} else {
fs.mkdirSync(app.getPath('userData') + "\\json");
saveAllData();
Expand Down Expand Up @@ -926,29 +907,6 @@ function loadSearchEngine() {
mainWindow.webContents.send('action-set-search-engine', searchEngine);
}

function loadHistory() {
var fs = require("fs");

try {
curHistoryNum = fs.readFileSync(app.getPath('userData') + "\\json\\curhistorynum.json");

var jsonstr = fs.readFileSync(app.getPath('userData') + "\\json\\history.json");
var arr = JSON.parse(jsonstr);

for (var i = 0; i < arr.length; i++) {
let Item = {
index: arr[i].index,
url: arr[i].url,
time: arr[i].time
};
historyArray.push(Item);
// mainWindow.webContents.send('action-add-history-item', Item);
}
} catch(err) {
saveHistory();
}
}

function loadDownloads() {
var fs = require("fs");

Expand Down Expand Up @@ -978,7 +936,7 @@ function loadWelcome() {
var fs = require("fs");

try {
welcomeOn = fs.readFileSync(app.getPath('userData') + "\\json\\welcome.json");
var welcomeOn = fs.readFileSync(app.getPath('userData') + "\\json\\welcome.json");
if(welcomeOn == 1) {
showWelcomeWindow();
}
Expand Down
Loading

0 comments on commit 94e0d53

Please sign in to comment.