Skip to content

Commit d171632

Browse files
committed
feat: added logout
1 parent 3b2f104 commit d171632

File tree

4 files changed

+27
-15
lines changed

4 files changed

+27
-15
lines changed

Default.sublime-commands

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[
2+
{
3+
"caption": "Mem.dev: Logout",
4+
"command": "mmdv_logout"
5+
}
6+
]

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Mem.dev Sublime Text Plugin
2+
3+
![./images/st_demo.gif](./images/st_demo.gif)
4+
5+
### Logout
6+
7+
To logout your account, just do `Ctrl + Shift + P` (for windows) and find `Mem.dev: Logout` command.

images/st_demo.gif

231 KB
Loading

mmdv.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,24 @@
44
import json
55
import os
66

7+
class MmdvLogoutCommand(sublime_plugin.TextCommand):
8+
def run(self, edit):
9+
if 'MEMDEV_ACCESS' in os.environ:
10+
del os.environ['MEMDEV_ACCESS']
11+
712
class MmdvCommand(sublime_plugin.TextCommand):
813
def __init__(self, view):
914
super().__init__(view)
10-
self.BASE_URL = 'localhost:3000'
15+
self.BASE_URL = 'mem.dev'
16+
self.connection = 'https'
1117
self.__title = ''
12-
self.__source = ''
1318
self.__content = ''
1419

1520
def __api(self, uri, params, method = 'POST'):
16-
conn = http.client.HTTPConnection(self.BASE_URL)
21+
if self.connection == 'http':
22+
conn = http.client.HTTPConnection(self.BASE_URL)
23+
else:
24+
conn = http.client.HTTPSConnection(self.BASE_URL)
1725
headers = {
1826
'Content-type': 'application/json'
1927
}
@@ -27,22 +35,16 @@ def __api(self, uri, params, method = 'POST'):
2735
response = conn.getresponse()
2836
return json.loads(response.read().decode())
2937

30-
def __show_source_panel(self):
31-
window = self.view.window()
32-
33-
window.show_input_panel("Source", "", self.on_source_input_done, None, None)
34-
3538
def on_token_input_done(self, input_val):
3639
params = {'id': input_val}
3740
response_json = self.__api('/api/v2/authorize/ext_auth', params)
3841

3942
if response_json['token']:
4043
os.environ['MEMDEV_ACCESS'] = str(response_json['token'])
4144

42-
self.__show_source_panel()
45+
self.send_snippet()
4346

44-
def on_source_input_done(self, input_val):
45-
self.__source = input_val
47+
def send_snippet(self):
4648
syntax = self.view.settings().get("syntax")
4749

4850
if 'Plain text' not in syntax:
@@ -53,7 +55,6 @@ def on_source_input_done(self, input_val):
5355
params = {
5456
'content': self.__content,
5557
'title': self.__title,
56-
'source': input_val,
5758
'syntax': syntax,
5859
'topic': syntax
5960
}
@@ -71,8 +72,6 @@ def on_title_input_done(self, input_string):
7172
window.show_input_panel("Enter your auth token", "", self.on_token_input_done, None, None)
7273
return
7374

74-
self.__show_source_panel()
75-
7675
def run(self, edit):
7776
window = self.view.window()
7877
view = self.view
@@ -81,4 +80,4 @@ def run(self, edit):
8180
region1 = sel[0]
8281
self.__content = view.substr(region1)
8382

84-
window.show_input_panel("I just learned how to...", "", self.on_title_input_done, None, None)
83+
window.show_input_panel("I just learned how to...", "", self.on_title_input_done, None, None)

0 commit comments

Comments
 (0)