Skip to content

Commit

Permalink
ESM update
Browse files Browse the repository at this point in the history
  • Loading branch information
Dotnaught committed Jun 8, 2024
1 parent b2ec277 commit ed44d5d
Show file tree
Hide file tree
Showing 8 changed files with 417 additions and 450 deletions.
2 changes: 1 addition & 1 deletion html/feedWindow.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
The <b>visible</b> field can be toggled by clicking on it.<br>
Change the <b>color</b> field to make entries more distinctive.<br>
The <b>filterList</b> field can be edited for new and existing entries.<br>
Click on <b>mode</b> to toggle between "publication", "aggregator", and "docket."<br>
Click on <b>mode</b> to toggle between "publication", "aggregator", "docket," and "atemporal."<br>
The <b>filterList</b> displays only entries with any of the space-separated words in the Title or Author fields.<br>
<b>Delete Entry</b> will remove the associated feed from the database.
</p>
Expand Down
194 changes: 0 additions & 194 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -593,200 +593,6 @@ function importDB() {
log.error('Import error: ', err);
});
}
/*
const template = [
// { role: 'appMenu' }
...(isMac
? [
{
label: app.name,
submenu: [
{ role: 'about' },
{ type: 'separator' },
{ role: 'services' },
{ type: 'separator' },
{ role: 'hide' },
{ role: 'hideOthers' },
{ role: 'unhide' },
{ type: 'separator' },
{ role: 'quit' },
],
},
]
: []),
// { role: 'fileMenu' }
{
label: 'File',
submenu: [
{
label: 'Show Feeds',
accelerator: 'CmdOrCtrl+F',
async click() {
if (mainWindow) {
createFeedWindow();
}
},
},
{
type: 'separator',
},
{
label: 'Import Database',
accelerator: 'CmdOrCtrl+=',
async click() {
if (mainWindow) {
importDB();
}
},
},
{
label: 'Export Database',
accelerator: 'CmdOrCtrl+B',
async click() {
if (mainWindow) {
exportDB();
}
},
},
{
type: 'separator',
},
{
type: 'separator',
},
{
label: 'Open Main Window',
accelerator: 'CmdOrCtrl+D',
enabled: false,
id: 'mainWindow',
async click() {
setMainWindow();
},
},
{
label: 'Reset Column Widths',
async click() {
if (mainWindow) {
resetColumnWidths();
}
},
},
{
type: 'separator',
},
{
role: 'close',
},
],
},
// { role: 'editMenu' }
{
label: 'Edit',
submenu: [
{ role: 'undo' },
{ role: 'redo' },
{ type: 'separator' },
{ role: 'cut' },
{ role: 'copy' },
{ role: 'paste' },
...(isMac
? [
{ role: 'pasteAndMatchStyle' },
{ role: 'delete' },
{ role: 'selectAll' },
{ type: 'separator' },
{
label: 'Speech',
submenu: [{ role: 'startSpeaking' }, { role: 'stopSpeaking' }],
},
]
: [{ role: 'delete' }, { type: 'separator' }, { role: 'selectAll' }]),
],
},
// { role: 'viewMenu' }
{
label: 'View',
submenu: [
{
label: 'Show Settings',
click() {
shell.openPath(configFile);
},
},
{
label: 'Show App Data',
click() {
shell.openPath(userData);
},
},
{
label: 'Show Log Data',
click() {
shell.openPath(logfilePath);
},
},
{
type: 'separator',
},
{
label: 'Delete Settings',
click() {
config.clear();
app.relaunch();
app.quit();
},
},
{
label: 'Delete App Data',
click() {
shell.trashItem(app.getPath('userData'));
app.relaunch();
app.quit();
},
},
{ type: 'separator' },
{ role: 'reload' },
{ role: 'forceReload' },
{ role: 'toggleDevTools' },
{ type: 'separator' },
{ role: 'resetZoom' },
{ role: 'zoomIn' },
{ role: 'zoomOut' },
{ type: 'separator' },
{ role: 'togglefullscreen' },
],
},
// { role: 'windowMenu' }
{
label: 'Window',
submenu: [
{ role: 'minimize' },
{ role: 'zoom' },
...(isMac
? [{ type: 'separator' }, { role: 'front' }, { type: 'separator' }, { role: 'window' }]
: [{ role: 'close' }]),
],
},
{
role: 'help',
submenu: [
{
label: 'Learn More',
click: async () => {
await shell.openExternal('https://electronjs.org');
},
},
],
},
];
/*
if (!electron.app.isPackaged) {
template.push({
label: 'Debug',
submenu: debugSubmenu,
});
}
*/

import template from './js/menu.js';

Expand Down
8 changes: 0 additions & 8 deletions js/mainWindow.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
let table = document.querySelector('table');
let dropdown = document.getElementById('dropdown');
//the line below produces an error in the console: Uncaught TypeError: Cannot read properties of undefined (reading 'receive')
window.api = {
receive: function (eventName, callback) {
// Implementation of the receive method
console.log(eventName);
},
};

// Rest of your code...
window.api.receive('updateBar', (args) => {
let bar = document.getElementById('bar');
let progress = (args[0] / args[1]) * 100;
Expand Down
3 changes: 0 additions & 3 deletions js/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,6 @@ const template = [
{
label: 'Learn More',
click: async () => {
const { shell } = require('electron');
//convert line above to ESM

await shell.openExternal('https://electronjs.org');
},
},
Expand Down
75 changes: 52 additions & 23 deletions js/rsslib.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ let parser = new Parser({
feed: [['dc:date', 'isoDate']],
item: [['dc:creator', 'creator']],
},
timeout: 10000,
timeout: 50000,
});

import { formatDistance, differenceInHours } from 'date-fns';
import { statusCodes } from './statusCodes.js';

const getAllFeeds = async (urlList, feedMode, win) => {
console.assert(urlList.length > 0, 'urlList is empty');
console.assert(feedMode !== undefined, 'feedmode is underfined');
console.assert(win !== undefined, 'win is underfined');
//console.assert(urlList.length > 0, 'urlList is empty');
//console.assert(feedMode !== undefined, 'feedmode is underfined');
//console.assert(win !== undefined, 'win is underfined');
let errors = [];
const promises = urlList.map(async (entry) => {
if (
Expand All @@ -34,23 +35,32 @@ const getAllFeeds = async (urlList, feedMode, win) => {
// parser.options.requestOptions = {};
// }
parser.options.requestOptions = {};
console.log(`Fetching ${entry.feed}`);
//console.log(`Fetching ${entry.feed}`);
const rssResult = await parser.parseURL(entry.feed);

const combinedResults = {
res: rssResult,
meta: entry,
errors: errors,
};
console.assert(combinedResults.res !== undefined, 'res is underfined');
console.assert(combinedResults.meta !== undefined, 'meta is underfined');
//console.assert(combinedResults.res !== undefined, 'res is underfined');
//console.assert(combinedResults.meta !== undefined, 'meta is underfined');
//console.log(combinedResults);
return combinedResults;
} catch (e) {
console.log(`Error at ${entry.feed}`);
console.error(`${e.name}: ${e.message}`);
//if message is in statusCodes, append the status code
if (statusCodes[e.message] !== undefined) {
e.message = e.message + ': ' + statusCodes[e.message];
}
//push error to array
errors.push({ feed: entry.feed, error: e.message });
errors.push({
title: e.message,
hoursAgo: new Date().getTime(),
author: 'Error',
sourceLink: entry.feed,
});
}
}
});
Expand Down Expand Up @@ -135,7 +145,9 @@ function removeXMLInvalidChars(str, removeDiscouragedChars) {
}

function processFeeds(feeds, timeWindow, feedMode) {
if (feeds[0] === undefined) feeds.shift();
//if (feeds[0] === undefined) feeds.shift();
//remove undefined feeds
feeds = feeds.filter((feed) => feed !== undefined);

let arr = [];

Expand All @@ -156,25 +168,22 @@ function processFeeds(feeds, timeWindow, feedMode) {
return url;
}
};
//get last item in feeds

feeds.forEach((feed) => {
feeds.forEach((feed, index, array) => {
if (feed === undefined) {
return;
} else if (feedMode === 'publication' && feed.meta.mode !== 'publication') {
return;
} else if (feedMode === 'aggregator' && feed.meta.mode !== 'aggregator') {
return;
} else if (feedMode === 'docket' && feed.meta.mode !== 'docket') {
return;
} else if (feedMode === 'atemporal' && feed.meta.mode !== 'atemporal') {
} else if (feedMode !== feed.meta.mode) {
return;
}
//console.log(feed.errors);
//filter for articles with words in list
let filterList = feed.meta.filterList;
console.log(`Processing ${feed.res.title}`);
console.log(Object.keys(feed.res));
console.log('Done processing feed');
//console.log(`Processing ${feed.res.title}`);
//console.log(Object.keys(feed.res));
//console.log('Items:');
feed.res.items.forEach((i) => {
//console.log(Object.keys(i));
//print item to console
let altURLs = undefined;
let altLink = undefined;
Expand Down Expand Up @@ -214,7 +223,7 @@ function processFeeds(feeds, timeWindow, feedMode) {
aggIndex = 1;
}
altLink = feed.meta.mode === 'aggregator' ? altURLs[linkIndex] : i.link;
console.assert(altLink !== undefined, 'altLink is underfined');
//console.assert(altLink !== undefined, 'altLink is underfined');
aggregatorLink = altURLs[aggIndex];
}
//create the feed object to be displayed
Expand Down Expand Up @@ -287,7 +296,7 @@ function processFeeds(feeds, timeWindow, feedMode) {
obj.sourceLink = getOrigin(sourceURL);
obj.aggregatorLink = aggregatorLink;
obj.feedTitle = feed.res.title;
console.assert(obj.feedTitle !== undefined, 'obj.feedTitle is underfined');
//console.assert(obj.feedTitle !== undefined, 'obj.feedTitle is underfined');
//testing
removeXMLInvalidChars(obj.title, true);
obj.color = feed.meta.color;
Expand All @@ -307,12 +316,32 @@ function processFeeds(feeds, timeWindow, feedMode) {
arr.push(obj);
} //otherwise, don't show
});
//add errors to feed
//console.log('index', index, 'array length', array.length - 1);
if (Object.is(array.length - 1, index) && feed.errors.length > 0) {
//console.log('Adding errors to feed');
for (let i = 0; i < feed.errors.length; i++) {
let obj = {};
obj.title = feed.errors[i].title;
obj.link = feed.errors[i].sourceLink;
obj.urlHash = crypto.createHash('sha1').update(obj.link).digest('hex');
obj.sourceDisplayText = getHostname(obj.link);
obj.sourceLink = getOrigin(obj.link);
obj.feedTitle = feed.res.title;
obj.color = '#ff0000';
obj.published = feed.errors[i].hoursAgo;
obj.pubtype = feed.meta.mode;
obj.author = feed.errors[i].author;
obj.hoursAgo = 'Now';
arr.push(obj);
}
}
});

arr.sort(function (a, b) {
return b.published - a.published;
});
console.log('Finished processing feeds');
//console.log('Finished processing feeds');
return arr;
}

Expand Down
Loading

0 comments on commit ed44d5d

Please sign in to comment.