Use session ID and squash bugs
This commit is contained in:
26
main.py
26
main.py
@@ -30,7 +30,7 @@ if os.path.exists(usage_db):
|
|||||||
# Initialize items cache and x2goclient sessions file path
|
# Initialize items cache and x2goclient sessions file path
|
||||||
x2goclient_bin = ""
|
x2goclient_bin = ""
|
||||||
# Locate x2goclient profiles and binary
|
# Locate x2goclient profiles and binary
|
||||||
x2go_sessions_path = ["{}/.x2goclient/sessions".format(os.environ.get('HOME'))]
|
x2go_sessions_path = "{}/.x2goclient/sessions".format(os.environ.get('HOME'))
|
||||||
x2goclient_bin = distutils.spawn.find_executable('x2goclient')
|
x2goclient_bin = distutils.spawn.find_executable('x2goclient')
|
||||||
# This extension is useless without x2goclient
|
# This extension is useless without x2goclient
|
||||||
if x2goclient_bin is None or x2goclient_bin == "":
|
if x2goclient_bin is None or x2goclient_bin == "":
|
||||||
@@ -39,7 +39,7 @@ if x2goclient_bin is None or x2goclient_bin == "":
|
|||||||
# Check if x2goclient sessions file exists
|
# Check if x2goclient sessions file exists
|
||||||
x2go_sessions_path_exists = None
|
x2go_sessions_path_exists = None
|
||||||
# Check default paths first
|
# Check default paths first
|
||||||
if os.path.isfile(x2go_sessions_path):
|
if os.path.exists(x2go_sessions_path):
|
||||||
x2go_sessions_path_exists = True
|
x2go_sessions_path_exists = True
|
||||||
|
|
||||||
|
|
||||||
@@ -52,26 +52,28 @@ class x2goclientExtension(Extension):
|
|||||||
|
|
||||||
def list_sessions(self, query):
|
def list_sessions(self, query):
|
||||||
items = []
|
items = []
|
||||||
|
items_cache = []
|
||||||
with open('/home/bryan/.x2goclient/sessions') as lines:
|
with open('/home/bryan/.x2goclient/sessions') as lines:
|
||||||
for line in lines:
|
for line in lines:
|
||||||
|
if line.startswith('['):
|
||||||
|
item = line.rstrip()
|
||||||
|
items.append(item[1:-1])
|
||||||
if line.startswith('host=') or line.startswith('name='):
|
if line.startswith('host=') or line.startswith('name='):
|
||||||
line = line.rstrip()
|
line = line.rstrip()
|
||||||
line = line.split('=',1)
|
line = line.split('=',1)
|
||||||
item = line[1]
|
item = line[1]
|
||||||
items.append(item)
|
items.append(item)
|
||||||
it_items = iter(items)
|
it_items = iter(items)
|
||||||
sessions = list(zip(it_items, it_items))
|
sessions = list(zip(it_items, it_items, it_items))
|
||||||
for session in sessions:
|
for session in sessions:
|
||||||
host = session[0]
|
seid = session[0]
|
||||||
name = session[1]
|
host = session[1]
|
||||||
|
name = session[2]
|
||||||
# Search for query inside filename and profile description
|
# Search for query inside filename and profile description
|
||||||
# Multiple strings can be used to search in description
|
|
||||||
# all() is used to achieve a AND search (include all keywords)
|
|
||||||
keywords = query.split(" ")
|
keywords = query.split(" ")
|
||||||
# if (query in base.lower()) or (query in desc.lower()):
|
# if (query in base.lower()) or (query in desc.lower()):
|
||||||
if (query.lower() in host.lower()) or (query.lower() in name.lower()):
|
if (query.lower() in host.lower()) or (query.lower() in name.lower()):
|
||||||
items_cache.append(create_item(host, name))
|
items_cache.append(create_item(seid, host, name))
|
||||||
|
|
||||||
items_cache = sorted(items_cache, key=sort_by_usage, reverse=True)
|
items_cache = sorted(items_cache, key=sort_by_usage, reverse=True)
|
||||||
return items_cache
|
return items_cache
|
||||||
|
|
||||||
@@ -109,16 +111,16 @@ class ItemEnterEventListener(EventListener):
|
|||||||
# Update usage JSON
|
# Update usage JSON
|
||||||
with open(usage_db, 'w') as db:
|
with open(usage_db, 'w') as db:
|
||||||
db.write(json.dumps(usage_cache, indent=2))
|
db.write(json.dumps(usage_cache, indent=2))
|
||||||
return RunScriptAction('#!/usr/bin/env bash\n{} --session {}\n'.format(x2goclient_bin, on_enter), None).run()
|
return RunScriptAction('#!/usr/bin/env bash\n{} --sessionid={}\n'.format(x2goclient_bin, on_enter), None).run()
|
||||||
|
|
||||||
|
|
||||||
def create_item(host, name):
|
def create_item(seid, host, name):
|
||||||
return ExtensionResultItem(
|
return ExtensionResultItem(
|
||||||
name=name,
|
name=name,
|
||||||
description=host,
|
description=host,
|
||||||
icon="images/x2goclient.svg",
|
icon="images/x2goclient.svg",
|
||||||
on_enter=ExtensionCustomAction(
|
on_enter=ExtensionCustomAction(
|
||||||
{"id": name})
|
{"id": seid})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
"required_api_version": "^2.0.0",
|
"required_api_version": "^2.0.0",
|
||||||
"name": "x2goclient",
|
"name": "x2goclient",
|
||||||
"description": "Quick access to x2goclient sessions",
|
"description": "Quick access to x2goclient sessions",
|
||||||
"developer_name": "cryobry",
|
"developer_name": "Bryan Roessler",
|
||||||
"icon": "images/icon.svg",
|
"icon": "images/x2goclient.svg",
|
||||||
"options": {
|
"options": {
|
||||||
"query_debounce": 0.1
|
"query_debounce": 0.1
|
||||||
},
|
},
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
"id": "sessions",
|
"id": "sessions",
|
||||||
"type": "input",
|
"type": "input",
|
||||||
"name": "x2goclient sessions file",
|
"name": "x2goclient sessions file",
|
||||||
"description": "Where x2goclient stores its profile configuration file <br /><code>~/.x2goclient/sessions</code> is checked by default",
|
"description": "Where x2goclient stores its sessions file <br /><code>~/.x2goclient/sessions</code> is checked by default",
|
||||||
"default_value": ""
|
"default_value": ""
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user