forked from yusdacra/FlutterEnhancements
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
43 lines (30 loc) · 1.04 KB
/
main.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
import os
import sublime
import sublime_plugin
import subprocess
def readFile(fn):
with open(fn, 'r') as fp:
return fp.read().strip()
def getCurrentPID():
fn = sublime.active_window().active_view().file_name()
dir = os.path.dirname(fn)
for _ in range(12):
dirs = os.listdir(dir)
if 'flutter.pid' in dirs:
pid = readFile(os.path.join(dir, 'flutter.pid'))
return pid
else:
dir = os.path.dirname(dir)
return None
class FlutterHotReloadCommand(sublime_plugin.WindowCommand):
def run(self):
print(dir(self))
pid = getCurrentPID()
subprocess.call(["bash", "-c", "kill -SIGUSR1 {}".format(pid)])
class FlutterHotRestartCommand(sublime_plugin.WindowCommand):
def run(self):
pid = getCurrentPID()
subprocess.call(["bash", "-c", "kill -SIGUSR2 {}".format(pid)])
class FlutterHotReloadWhenSaved(sublime_plugin.EventListener):
def on_post_save_async(self, view):
view.window().run_command("flutter_hot_reload")