-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathwatchdog.py
85 lines (70 loc) · 2.56 KB
/
watchdog.py
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
import threading
try:
import sublime
except ImportError:
from test.stubs import sublime
from settings import Settings
from log import Log
from win import Win
from stack_ide_manager import StackIDEManager
#############################
# Plugin development utils
#############################
# Ensure existing processes are killed when we
# save the plugin to prevent proliferation of
# stack-ide session.13953 folders
watchdog = None
settings = None
def plugin_loaded():
global watchdog, settings
settings = load_settings()
Log._set_verbosity(settings.verbosity)
StackIDEManager.configure(settings)
Win.show_popup = settings.show_popup
Win.hoogle_url = settings.hoogle_url
watchdog = StackIDEWatchdog()
def plugin_unloaded():
global watchdog
watchdog.kill()
StackIDEManager.reset()
watchdog = None
def load_settings():
settings_obj = sublime.load_settings("SublimeStackIDE.sublime-settings")
settings_obj.add_on_change("_on_new_settings", on_settings_changed)
add_to_path = settings_obj.get('add_to_PATH', [])
return Settings(
settings_obj.get('verbosity', 'normal'),
add_to_path if isinstance(add_to_path, list) else [],
settings_obj.get('show_popup', False),
settings_obj.get('hoogle_url', "http://www.stackage.org/lts/hoogle?q=")
)
def on_settings_changed():
global settings
updated_settings = load_settings()
if updated_settings.verbosity != settings.verbosity:
Log._set_verbosity(updated_settings.verbosity)
elif updated_settings.add_to_PATH != settings.add_to_PATH:
Log.normal("Settings changed, reloading backends")
StackIDEManager.configure(updated_settings)
StackIDEManager.reset()
elif updated_settings.show_popup != settings.show_popup:
Win.show_popup = updated_settings.show_popup
elif updated_settings.hoogle_url != settings.hoogle_url:
Win.hoogle_url = updated_settings.hoogle_url
settings = updated_settings
class StackIDEWatchdog():
"""
Since I can't find any way to detect if a window closes,
we use a watchdog timer to clean up stack-ide instances
once we see that the window is no longer in existence.
"""
def __init__(self):
super(StackIDEWatchdog, self).__init__()
Log.normal("Starting stack-ide-sublime watchdog")
self.check_for_processes()
def check_for_processes(self):
StackIDEManager.check_windows()
self.timer = threading.Timer(1.0, self.check_for_processes)
self.timer.start()
def kill(self):
self.timer.cancel()