Skip to content

Commit

Permalink
new logo and open with function
Browse files Browse the repository at this point in the history
  • Loading branch information
hhelibeb committed Apr 15, 2020
1 parent 94e68cc commit 2aaa401
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 24 deletions.
37 changes: 37 additions & 0 deletions browser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import winreg


FIREFOX = 'Firefox'
CHROME = "Chrome"
IE = 'IE'

PROGRAMS = {
IE: "iexplore.exe",
FIREFOX: "firefox.exe",
CHROME: "chrome.exe"
}


def get_path(browser_name) -> str:

reg_local_machine = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
reg_current_user = winreg.ConnectRegistry(None, winreg.HKEY_CURRENT_USER)
key = f'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\{PROGRAMS[browser_name]}'

path = __get_default_value(reg_current_user, key)
if path:
return path

return __get_default_value(reg_local_machine, key)


def __get_default_value(registry, key) -> str:
result = ''
try:
result_key = winreg.OpenKey(registry, key)
result = winreg.QueryValueEx(result_key, '')[0]
result_key.Close()
except FileNotFoundError:
pass
return result

69 changes: 46 additions & 23 deletions firefox.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
with load_module():
import sqlite3
import configparser
import winreg
import os
import webbrowser
import json
import browser
from os import path
from typing import List

Expand Down Expand Up @@ -39,6 +41,22 @@ def query(self, param):
results = self.get_results(db_path=db_path, sql=self.generate_sql(q))
return results

def context_menu(self, data):

results = []
for browser_name in browser.PROGRAMS:
if browser.get_path(browser_name):
results.append({
"Title": f"Open With {browser_name}",
"SubTitle": str(data),
"IcoPath": f"img\\{browser_name}.ico",
'JsonRPCAction': {
'method': 'open_url',
'parameters': [str(data), browser_name]
}
})
return results

def get_db(self) -> str:

dir = os.path.abspath(os.getcwd())
Expand Down Expand Up @@ -70,26 +88,25 @@ def generate_sql(self, keyword: str) -> List[str]:
cond1 = f"'{keyword}%'"
cond2 = f"'%{keyword}%'"

sql1 = f'''select b.title, visit_count, url
from moz_bookmarks as b
join moz_places as p on b.fk = p.id
where lower(b.title) like {cond1}
order by p.visit_count desc'''
sql2 = f'''select b.title, visit_count, url
from moz_bookmarks as b
join moz_places as p on b.fk = p.id
where lower(b.title) like {cond2}
and lower(b.title) not like {cond1}
order by p.visit_count desc'''
sql3 = f'''select b.title, visit_count, url
from moz_bookmarks as b
join moz_places as p on b.fk = p.id
where lower(p.url) like {cond2}
order by p.visit_count desc'''

results += [sql1]
results += [sql2]
results += [sql3]
results.append(f'''select b.title, visit_count, url, frecency, b.guid
from moz_bookmarks as b
join moz_places as p on b.fk = p.id
where lower(b.title) like {cond1}
order by frecency desc '''
)
results.append(f'''select b.title, visit_count, url, frecency, b.guid
from moz_bookmarks as b
join moz_places as p on b.fk = p.id
where lower(b.title) like {cond2}
and lower(b.title) not like {cond1}
order by frecency desc '''
)
results.append(f'''select b.title, visit_count, url, frecency, b.guid
from moz_bookmarks as b
join moz_places as p on b.fk = p.id
where lower(p.url) like {cond2}
order by frecency desc '''
)

return results

Expand Down Expand Up @@ -144,7 +161,8 @@ def get_results(self, db_path: str, sql: List[str]) -> List[dict]:
result = {
'Title': title,
'SubTitle': url,
'IcoPath': 'img\\firefox.ico',
'IcoPath': 'img\\Firefox.ico',
"ContextData": url,
'JsonRPCAction': {
'method': 'open_url',
'parameters': [url]
Expand All @@ -164,8 +182,13 @@ def get_results(self, db_path: str, sql: List[str]) -> List[dict]:
}]
return results

def open_url(self, url=None):
webbrowser.open(url)
def open_url(self, url=None, browser_name=None):
if not browser_name:
webbrowser.open(url)
else:
browser_path = browser.get_path(browser_name)
webbrowser.register(browser_name, None, webbrowser.BackgroundBrowser(browser_path))
webbrowser.get(browser_name).open_new_tab(url)

def open_dir(self, dir=None):
if dir:
Expand Down
Binary file added img/Chrome.ico
Binary file not shown.
Binary file added img/Firefox One Colo.ico
Binary file not shown.
Binary file added img/Firefox.ico
Binary file not shown.
Binary file added img/Firefox_Old.ico
Binary file not shown.
Binary file added img/IE.ico
Binary file not shown.
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"Name":"Firefox Bookmarks",
"Description":"Search Firefox Bookmarks",
"Author":"hhelibeb",
"Version":"1.0.0",
"Version":"1.0.1",
"Language":"python",
"Website":"https://github.com/hhelibeb/Wox.Plugin.Firefox-Bookmarks",
"IcoPath": "img\\Firefox.ico",
Expand Down

0 comments on commit 2aaa401

Please sign in to comment.