sondakika 2.0.0 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/generate_main.js DELETED
@@ -1,338 +0,0 @@
1
- const fs = require('fs');
2
- const lines = [
3
- "const { app, BrowserWindow, ipcMain, shell } = require('electron');",
4
- "const path = require('path');",
5
- "const fs = require('fs');",
6
- "const Parser = require('rss-parser');",
7
- "",
8
- "let mainWindow;",
9
- "let articleWindow = null;",
10
- "let articleWindowData = { newsItems: [], currentIndex: 0 };",
11
- "",
12
- "const parser = new Parser({",
13
- " timeout: 10000,",
14
- " requestOptions: {",
15
- " headers: {",
16
- " 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'",
17
- " }",
18
- " },",
19
- " maxRedirects: 5",
20
- "});",
21
- "",
22
- "const dataDir = path.join(app.getPath('userData'), 'data');",
23
- "const stateFile = path.join(dataDir, 'state.json');",
24
- "",
25
- "const sources = {",
26
- " cumhuriyet: { name: 'Cumhuriyet', url: 'https://www.cumhuriyet.com.tr/rss/son_dakika.xml', isSondakika: true },",
27
- " trt: { name: 'TRT Haber', url: 'https://www.trthaber.com/sondakika.rss', isSondakika: true },",
28
- " mynet: { name: 'Mynet', url: 'https://www.mynet.com/haber/rss/sondakika', isSondakika: true },",
29
- " sabah: { name: 'Sabah', url: 'https://www.sabah.com.tr/rss/anasayfa.xml', isSondakika: false },",
30
- " star: { name: 'Star', url: 'https://www.star.com.tr/rss/rss.asp?cid=124', isSondakika: false },",
31
- " vatan: { name: 'Gazete Vatan', url: 'https://www.gazetevatan.com/rss/gundem.xml', isSondakika: false },",
32
- " haberturk: { name: 'Haberturk', url: 'https://www.haberturk.com/rss', isSondakika: false },",
33
- " cnnturk: { name: 'CNN Turk', url: 'https://cnnturk.com/feed/rss/turkiye', isSondakika: false },",
34
- " yenisafak: { name: 'Yeni Safak', url: 'https://www.yenisafak.com/rss', isSondakika: false },",
35
- " aa: { name: 'Anadolu Ajansi', url: 'https://www.aa.com.tr/en/rss', isSondakika: false }",
36
- "};",
37
- "",
38
- "const defaultState = {",
39
- " enabledSources: ['cumhuriyet', 'trt', 'mynet', 'haberturk', 'cnnturk'],",
40
- " sortOrder: 'desc',",
41
- " itemsPerPage: 10,",
42
- " currentPage: 1,",
43
- " windowBounds: null,",
44
- " fontSize: 16,",
45
- " theme: 'dark'",
46
- "};",
47
- "",
48
- "function ensureDataDir() {",
49
- " if (!fs.existsSync(dataDir)) {",
50
- " fs.mkdirSync(dataDir, { recursive: true });",
51
- " }",
52
- "}",
53
- "",
54
- "function loadState() {",
55
- " ensureDataDir();",
56
- " try {",
57
- " if (fs.existsSync(stateFile)) {",
58
- " const data = fs.readFileSync(stateFile, 'utf8');",
59
- " return { ...defaultState, ...JSON.parse(data) };",
60
- " }",
61
- " } catch (err) {",
62
- " console.error('Error loading state:', err);",
63
- " }",
64
- " return { ...defaultState };",
65
- "}",
66
- "",
67
- "function saveState(state) {",
68
- " ensureDataDir();",
69
- " try {",
70
- " fs.writeFileSync(stateFile, JSON.stringify(state, null, 2), 'utf8');",
71
- " } catch (err) {",
72
- " console.error('Error saving state:', err);",
73
- " }",
74
- "}",
75
- "",
76
- "function createWindow() {",
77
- " const state = loadState();",
78
- " const bounds = state.windowBounds || { width: 1200, height: 800 };",
79
- "",
80
- " mainWindow = new BrowserWindow({",
81
- " width: bounds.width,",
82
- " height: bounds.height,",
83
- " x: bounds.x,",
84
- " y: bounds.y,",
85
- " minWidth: 900,",
86
- " minHeight: 600,",
87
- " webPreferences: {",
88
- " preload: path.join(__dirname, 'preload.js'),",
89
- " contextIsolation: true,",
90
- " nodeIntegration: false",
91
- " },",
92
- " backgroundColor: '#1a1a2e',",
93
- " show: false,",
94
- " frame: true,",
95
- " autoHideMenuBar: true",
96
- " });",
97
- "",
98
- " mainWindow.loadFile(path.join(__dirname, '../renderer/index.html'));",
99
- "",
100
- " mainWindow.once('ready-to-show', () => {",
101
- " mainWindow.show();",
102
- " });",
103
- "",
104
- " mainWindow.on('close', () => {",
105
- " saveWindowBounds();",
106
- " });",
107
- "",
108
- " mainWindow.on('closed', () => {",
109
- " mainWindow = null;",
110
- " });",
111
- "}",
112
- "",
113
- "function extractImage(item, contentHtml, sourceKey) {",
114
- " if (item.enclosure && item.enclosure.url && item.enclosure.type && item.enclosure.type.startsWith('image')) {",
115
- " return item.enclosure.url;",
116
- " }",
117
- " if (item.thumbnail) return item.thumbnail.url;",
118
- " if (item.media && item.media.content && item.media.content.url) return item.media.content.url;",
119
- " if (item['media:content'] && item['media:content'].url) return item['media:content'].url;",
120
- " if (item['media:thumbnail'] && item['media:thumbnail'].url) return item['media:thumbnail'].url;",
121
- " if (item['itunes:image'] && item['itunes:image'].href) return item['itunes:image'].href;",
122
- " if (!contentHtml) return null;",
123
- "",
124
- " if (sourceKey === 'vatan') {",
125
- " const vatanPattern = /https:\\/\\/image\\.gazetevatan\\.com\\/[^\\"'\\s<>]+\\.jpg/i;",
126
- " const vatanMatch = contentHtml.match(vatanPattern);",
127
- " if (vatanMatch) {",
128
- " let url = vatanMatch[0];",
129
- " const firstJpg = url.indexOf('.jpg');",
130
- " if (firstJpg !== -1) url = url.substring(0, firstJpg + 4);",
131
- " return url;",
132
- " }",
133
- " }",
134
- "",
135
- " const srcPattern = /src=[\"'']([^\"'']+\\.(jpg|jpeg|png|webp)[^\"'']*)/i;",
136
- " const match = contentHtml.match(srcPattern);",
137
- " if (match && match[1]) {",
138
- " const url = match[1];",
139
- " const extMatch = url.match(/\\.(jpg|jpeg|png|webp)/i);",
140
- " if (extMatch) {",
141
- " const baseUrl = url.substring(0, url.indexOf(extMatch[0]) + extMatch[0].length);",
142
- " return baseUrl;",
143
- " }",
144
- " return url;",
145
- " }",
146
- " return null;",
147
- "}",
148
- "",
149
- "const WRONG_TZ_SOURCES = new Set(['cnnturk', 'yenisafak']);",
150
- "",
151
- "function fixPublishedDate(dateStr, sourceKey) {",
152
- " if (!dateStr) return dateStr;",
153
- " if (!WRONG_TZ_SOURCES.has(sourceKey)) return dateStr;",
154
- " const ts = Date.parse(dateStr);",
155
- " if (isNaN(ts)) return dateStr;",
156
- " return new Date(ts - 3 * 60 * 60 * 1000).toISOString();",
157
- "}",
158
- "",
159
- "async function fetchAllNews(enabledSources) {",
160
- " const results = [];",
161
- " for (const sourceKey of enabledSources) {",
162
- " const source = sources[sourceKey];",
163
- " if (!source) continue;",
164
- " try {",
165
- " const feed = await parser.parseURL(source.url);",
166
- " const items = feed.items.map(item => {",
167
- " const fields = [",
168
- " item['content:encoded'], item.content, item.contentSnippet,",
169
- " item.summary, item.description",
170
- " ];",
171
- " let bestContent = '';",
172
- " let bestContentRaw = '';",
173
- " for (const field of fields) {",
174
- " if (field) {",
175
- " const cleaned = cleanHtml(field);",
176
- " if (cleaned.length > bestContent.length) {",
177
- " bestContent = cleaned;",
178
- " bestContentRaw = field;",
179
- " }",
180
- " }",
181
- " }",
182
- " if (!bestContent || bestContent.length < 50) {",
183
- " bestContent = item.title || '';",
184
- " bestContentRaw = item.title || '';",
185
- " }",
186
- " const imageUrl = extractImage(item, bestContentRaw, sourceKey);",
187
- " return {",
188
- " ...item,",
189
- " pubDate: fixPublishedDate(item.pubDate, sourceKey),",
190
- " isoDate: fixPublishedDate(item.isoDate, sourceKey),",
191
- " sourceKey,",
192
- " sourceName: source.name,",
193
- " isSondakika: source.isSondakika,",
194
- " fullContent: bestContent,",
195
- " imageUrl,",
196
- " newsTitle: item.title",
197
- " };",
198
- " });",
199
- " results.push(...items);",
200
- " } catch (err) {",
201
- " console.error('Error fetching ' + sourceKey + ':', err.message);",
202
- " }",
203
- " }",
204
- " return results;",
205
- "}",
206
- "",
207
- "function cleanHtml(html) {",
208
- " if (!html) return '';",
209
- " let text = html.replace(/<p[^>]*>/gi, '\\n').replace(/<\\/p>/gi, '\\n').replace(/<br\\s*\\/?>/gi, '\\n').replace(/<[^>]*>/g, '');",
210
- " text = text.replace(/&nbsp;/g, ' ').replace(/&amp;/g, '&').replace(/&quot;/g, '\"').replace(/&#39;/g, \"'\").replace(/&lt;/g, '<').replace(/&gt;/g, '>').trim();",
211
- " text = text.replace(/\\n+/g, '\\n').trim();",
212
- " return text;",
213
- "}",
214
- "",
215
- "function sortNews(items, sortOrder) {",
216
- " return items.sort((a, b) => {",
217
- " const dateA = new Date(a.pubDate || a.isoDate || 0);",
218
- " const dateB = new Date(b.pubDate || b.isoDate || 0);",
219
- " return sortOrder === 'desc' ? dateB - dateA : dateA - dateB;",
220
- " });",
221
- "}",
222
- "",
223
- "function saveWindowBounds() {",
224
- " if (!mainWindow || mainWindow.isDestroyed()) return;",
225
- " const state = loadState();",
226
- " state.windowBounds = mainWindow.getBounds();",
227
- " saveState(state);",
228
- "}",
229
- "",
230
- "app.whenReady().then(() => {",
231
- " createWindow();",
232
- " app.on('activate', () => {",
233
- " if (BrowserWindow.getAllWindows().length === 0) createWindow();",
234
- " });",
235
- "});",
236
- "",
237
- "app.on('window-all-closed', () => {",
238
- " if (process.platform !== 'darwin') app.quit();",
239
- "});",
240
- "",
241
- "ipcMain.handle('get-sources', () => sources);",
242
- "",
243
- "ipcMain.handle('get-state', () => loadState());",
244
- "",
245
- "ipcMain.handle('save-state', (event, state) => {",
246
- " saveState(state);",
247
- " return true;",
248
- "});",
249
- "",
250
- "ipcMain.handle('set-font-size', (event, fontSize) => {",
251
- " const state = loadState();",
252
- " state.fontSize = fontSize;",
253
- " saveState(state);",
254
- " return true;",
255
- "});",
256
- "",
257
- "ipcMain.handle('set-theme', (event, theme) => {",
258
- " const state = loadState();",
259
- " state.theme = theme;",
260
- " saveState(state);",
261
- " return true;",
262
- "});",
263
- "",
264
- "ipcMain.handle('fetch-news', async (event, enabledSources, sortOrder) => {",
265
- " let items = await fetchAllNews(enabledSources);",
266
- " items = sortNews(items, sortOrder);",
267
- " return items;",
268
- "});",
269
- "",
270
- "ipcMain.handle('open-external', async (event, url) => {",
271
- " await shell.openExternal(url);",
272
- " return true;",
273
- "});",
274
- "",
275
- "ipcMain.handle('open-article-view', async (event, newsItems, currentIndex) => {",
276
- " if (articleWindow && !articleWindow.isDestroyed()) {",
277
- " articleWindowData = { newsItems, currentIndex, fontSize: loadState().fontSize || 16 };",
278
- " articleWindow.focus();",
279
- " articleWindow.webContents.send('article-view-navigate', articleWindowData);",
280
- " return true;",
281
- " }",
282
- "",
283
- " articleWindowData = { newsItems, currentIndex, fontSize: loadState().fontSize || 16 };",
284
- " const state = loadState();",
285
- " const mainBounds = mainWindow ? mainWindow.getBounds() : { width: 1200, height: 800, x: 100, y: 50 };",
286
- "",
287
- " articleWindow = new BrowserWindow({",
288
- " width: mainBounds.width,",
289
- " height: mainBounds.height,",
290
- " x: mainBounds.x,",
291
- " y: mainBounds.y,",
292
- " minWidth: 700,",
293
- " minHeight: 500,",
294
- " parent: mainWindow,",
295
- " webPreferences: {",
296
- " preload: path.join(__dirname, 'article-preload.js'),",
297
- " contextIsolation: true,",
298
- " nodeIntegration: false",
299
- " },",
300
- " backgroundColor: '#0f0f1a',",
301
- " show: false,",
302
- " frame: true,",
303
- " autoHideMenuBar: true,",
304
- " title: 'Haber Goruntule'",
305
- " });",
306
- "",
307
- " articleWindow.loadFile(path.join(__dirname, '../renderer/article-view.html'));",
308
- "",
309
- " articleWindow.once('ready-to-show', () => {",
310
- " articleWindow.show();",
311
- " if (mainWindow && !mainWindow.isDestroyed()) mainWindow.hide();",
312
- " });",
313
- "",
314
- " articleWindow.on('closed', () => {",
315
- " articleWindow = null;",
316
- " if (mainWindow && !mainWindow.isDestroyed()) {",
317
- " mainWindow.show();",
318
- " mainWindow.focus();",
319
- " mainWindow.webContents.send('article-view-closed', articleWindowData.currentIndex);",
320
- " }",
321
- " });",
322
- "",
323
- " return true;",
324
- "});",
325
- "",
326
- "ipcMain.handle('article-view-get-data', () => articleWindowData);",
327
- "",
328
- "ipcMain.handle('article-view-close', (event, currentIndex) => {",
329
- " articleWindowData.currentIndex = currentIndex;",
330
- " if (articleWindow && !articleWindow.isDestroyed()) {",
331
- " articleWindow.close();",
332
- " }",
333
- " return true;",
334
- "});"
335
- ];
336
-
337
- fs.writeFileSync('src/main/main.js', lines.join('\n'), 'utf8');
338
- console.log('main.js generated successfully');