This repository was archived by the owner on Feb 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
124 lines (89 loc) · 2.46 KB
/
Copy pathindex.js
File metadata and controls
124 lines (89 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*jshint esversion: 6, laxcomma: true, asi: true*/
'use strict()'
const electron = require('electron');
const path = require('path');
const ipc = require('electron').ipcMain;
const Store = require('electron-store')
const Util = require('./ourrss-util')
const getFeed = require('./rss-to-json');
const app = electron.app;
const getRSS = (feed) =>
new Promise((res, rej) =>
getFeed.load(feed, (e, rss) => e ? rej(e) : res(rss)));
// adds debug features like hotkeys for triggering dev tools and reload
require('electron-debug')();
// prevent window being garbage collected
let mainWindow;
function onClosed() {
// dereference the window
// for multiple windows store them in an array
mainWindow = null;
}
function createMainWindow() {
const win = new electron.BrowserWindow({
width: 1000,
height: 900,
frame: false,
resizable: true,
icon: path.join(`${__dirname}/img/icon.png`)
});
win.loadURL(`file://${__dirname}/index.html`);
win.on('closed', onClosed);
return win;
}
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (!mainWindow) {
mainWindow = createMainWindow();
}
});
app.on('ready', () => {
mainWindow = createMainWindow();
});
ipc.on('message', (event, mess) => Util.message(mess))
ipc.on('getFeed', function (event, url) {
getRSS(url).then(rss => {
rss.feed = url
event.sender.send('getFeedRes', rss)
if (rss.image) {
Util.message(({
head: 'Feed Fetched',
body: `${rss.title}`
}))
const store = new Store()
if (!store.get('audio')) {
const audio = {}
audio.feeds = []
store.set('audio', audio)
}
const audio = store.get('audio')
if (audio.feeds.length) {
for (let i = audio.feeds.length - 1; i--;) {
console.log(audio.feeds[i].title, ' VS ', rss.title)
if (audio.feeds[i].title === rss.title) {
console.log('b4 ', audio.feeds.length)
audio.feeds.splice(i, 1)
console.log('after ', audio.feeds.length)
}
}
audio.feeds.push(rss)
store.set('audio', audio)
} else {
audio.feeds.push(rss)
store.set('audio', audio)
}
}
}).catch(e => message(e))
});
/*
TODOs
Feature: impliment customized dialogs via https://electronjs.org/docs/api/dialog
*/
ipc.on('app-close', (ev, arr) => mainWindow.close())
ipc.on('app-maxi', (ev, arr) => mainWindow.maximize())
ipc.on('app-mini', (ev, arr) => mainWindow.minimize())
ipc.on('app-restore', (ev, arr) => mainWindow.unmaximize())