1
+ import fs from 'fs'
1
2
import { client } from 'electron-connect'
2
3
import { app , BrowserWindow , ipcMain } from 'electron'
3
- import watch from 'chch/dist/watch'
4
+
5
+ // import watch from 'chch/dist/watch'
6
+ // import _ from 'lodash'
7
+ import { Post } from 'chch/dist/types'
4
8
5
9
let mainWindow : Electron . BrowserWindow | null
6
10
7
11
function createWindow ( ) {
8
12
// Create the browser window.
9
13
mainWindow = new BrowserWindow ( {
14
+ frame : true ,
10
15
height : 600 ,
11
16
webPreferences : {
12
17
// preload: path.join(__dirname, 'preload.js'),
@@ -19,9 +24,6 @@ function createWindow() {
19
24
// and load the index.html of the app.
20
25
mainWindow . loadFile ( 'index.html' )
21
26
22
- // Open the DevTools.
23
- mainWindow . webContents . openDevTools ( )
24
-
25
27
client . create ( mainWindow )
26
28
27
29
// Emitted when the window is closed.
@@ -63,9 +65,20 @@ ipcMain.on('watch', async (event, url) => {
63
65
if ( state . watchId ) {
64
66
clearInterval ( state . watchId )
65
67
}
66
- state . watchId = await watch ( url , ( posts , nth ) => {
67
- event . sender . send ( 'posts' , posts , nth )
68
- } )
68
+ const data = fs . readFileSync ( 'out.txt' , 'utf-8' )
69
+
70
+ const posts : Post [ ] = JSON . parse ( data )
71
+
72
+ event . sender . send ( 'posts' , posts , 0 )
73
+ // state.watchId = await watch(url, (posts, nth) => {
74
+ // const lastPost = _.last(posts)
75
+
76
+ // if (lastPost && state.watchId && lastPost.number >= 1000) {
77
+ // clearInterval(state.watchId)
78
+ // }
79
+
80
+ // event.sender.send('posts', posts, nth)
81
+ // })
69
82
} )
70
83
71
84
ipcMain . on ( 'unwatch' , async ( ) => {
0 commit comments