-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithubNotif.py
More file actions
63 lines (46 loc) · 1.62 KB
/
githubNotif.py
File metadata and controls
63 lines (46 loc) · 1.62 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
import sublime
import sys
import sublime_plugin
import webbrowser
PY3 = sys.version > '3'
if PY3:
from .request import *
else:
from request import *
class OpenGithubNotificationsCommand(sublime_plugin.WindowCommand):
def run(self):
webbrowser.open_new_tab("https://github.com/notifications")
class GithubNotifStatusBar(sublime_plugin.EventListener):
_template = None
_activated = False
_status = None
def on_activated_async(self, view):
self._run(view)
def _run(self, view):
self._view = view
if not self._activated:
settings = sublime.load_settings('githubNotif.sublime-settings')
self._updateInterval = settings.get('update_interval', 60)
self._template = settings.get('template', None)
self._startTimer()
self._activated = True
self._showStatus()
def _startTimer(self):
self._updateData()
self._showStatus()
sublime.set_timeout_async(lambda: self._startTimer(), self._updateInterval * 1e3)
def _updateData(self):
print("[GithubNotifStatusBar]: updateData")
notifications = api_request('https://api.github.com/notifications')
if notifications is not None:
not_count = len(notifications)
not_str = str(not_count)
if not_count >= 50:
not_str += "+"
self._status = self._template.format(notif=not_str)
return True
else:
return False
def _showStatus(self):
if self._status is not None:
self._view.set_status('GithubNotif', self._status)