electron based twitter client
Revision | c519ca8f3b6ed52763a1fe0dd121e9d35abd9a30 (tree) |
---|---|
Time | 2016-02-06 23:54:16 |
Author | Hiromichi Matsushima <hylom@Hiro...> |
Commiter | Hiromichi Matsushima |
add auto update TL with stream API
@@ -5,7 +5,7 @@ var BrowserWindow = require('browser-window'); | ||
5 | 5 | var mainWindow = null; |
6 | 6 | |
7 | 7 | function createWindow () { |
8 | - mainWindow = new BrowserWindow({width: 800, height: 600}); | |
8 | + mainWindow = new BrowserWindow({width: 400, height: 800}); | |
9 | 9 | mainWindow.loadURL('file://' + __dirname + '/index.html'); |
10 | 10 | |
11 | 11 | mainWindow.on('closed', function() { |
@@ -9,4 +9,11 @@ exports.getHomeTimeline = function (callback) { | ||
9 | 9 | client.get('statuses/home_timeline', callback); |
10 | 10 | }; |
11 | 11 | |
12 | - | |
12 | +exports.stream = function (callback) { | |
13 | + client.stream('user', {}, function (stream) { | |
14 | + stream.on('data', callback); | |
15 | + stream.on('error', function(error) { | |
16 | + throw error; | |
17 | + }); | |
18 | + }); | |
19 | +} |
@@ -10,12 +10,14 @@ function sprnkrViewMain () { | ||
10 | 10 | var name = tweet.user.name + ' (@' + tweet.user.screen_name + ')'; |
11 | 11 | var timestamp = tweet.created_at; |
12 | 12 | var text = tweet.text; |
13 | - var content = name + ' ' + timestamp + '<br>' + text | |
13 | + var content = '<div class="header"><span class="username">' + name + '</span><span class="timestamp">' + timestamp + '</span></div>'; | |
14 | + content += '<div class="body">'+ text + '</div>'; | |
14 | 15 | var elem = $("<li>" + content + "</li>"); |
15 | - $("#sprnkr-items").append(elem); | |
16 | + $("#sprnkr-items").prepend(elem); | |
16 | 17 | } |
17 | 18 | tweetWriter.write = function (tweet) { |
18 | 19 | if (util.isArray(tweet)) { |
20 | + tweet.reverse(); | |
19 | 21 | tweet.forEach(this.put); |
20 | 22 | } else { |
21 | 23 | this.put(tweet); |
@@ -24,13 +26,16 @@ function sprnkrViewMain () { | ||
24 | 26 | |
25 | 27 | const remote = require('electron').remote; |
26 | 28 | var models = remote.require('./models'); |
27 | - models.getHomeTimeline(renderTimeline); | |
29 | + models.getHomeTimeline(initTimeline); | |
28 | 30 | |
29 | - function renderTimeline(err, tweets, resp) { | |
31 | + function initTimeline(err, tweets, resp) { | |
30 | 32 | if (err) throw err; |
31 | 33 | tweetWriter.write(tweets); |
34 | + models.stream(function(tweets) { | |
35 | + tweetWriter.write(tweets); | |
36 | + }); | |
32 | 37 | }; |
38 | + | |
33 | 39 | } |
34 | 40 | |
35 | -console.log("do main"); | |
36 | 41 | sprnkrViewMain(); |