diff --git a/CHANGELOG.md b/CHANGELOG.md index d8592da..e9b85dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [1.2.6] - 2017-11-18 +### Changed +- Getting phantom icon from a function. + ## [1.2.5] - 2017-11-14 ### Changed - Fix to read phantom icon. diff --git a/open_in_browser.py b/open_in_browser.py index 10c60a3..dad9d76 100644 --- a/open_in_browser.py +++ b/open_in_browser.py @@ -1,14 +1,10 @@ import base64, os, re, sublime, sublime_plugin, subprocess, webbrowser from urllib.parse import urlparse -from .settings import get_setting +from .settings import get_setting, get_image -import os - -PLUGIN_PATH = os.path.dirname(os.path.realpath(__file__)) -PLUGIN_NAME = os.path.basename(PLUGIN_PATH).replace(".sublime-package", "") -ENCODED_IMG = base64.b64encode(sublime.load_binary_resource("Packages/" + PLUGIN_NAME +"/open-in-browser.png")).decode() REGEX = "(http|ftp|https)://([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?" + class OpenInBrowser(sublime_plugin.ViewEventListener): def __init__(self, view): self.view = view @@ -20,7 +16,7 @@ def erase_phantom(self): self.view.erase_phantoms('open_link_phantom') def get_url_link(self, url): - return sublime.expand_variables("", {"url": url, "encoded_img": ENCODED_IMG, 'font_size': str(self.font_size)}) + return sublime.expand_variables("", {"url": url, "encoded_img": get_image(), 'font_size': str(self.font_size)}) def on_activated_async(self): if get_setting('enable'): diff --git a/settings.py b/settings.py index ee52ab9..5c219b0 100644 --- a/settings.py +++ b/settings.py @@ -1,5 +1,8 @@ -import sublime +import base64, sublime def get_setting(key, default=None): settings = sublime.load_settings('OpenInBrowser.sublime-settings') - return settings.get(key, default) \ No newline at end of file + return settings.get(key, default) + +def get_image(): + return base64.b64encode(sublime.load_binary_resource("Packages/Open In Browser/open-in-browser.png")).decode()