From 682c3462f12d36a4c2b52c0d89b5e8a70786f5cb Mon Sep 17 00:00:00 2001 From: George Edward Bulmer Date: Wed, 7 Feb 2018 19:21:53 +0000 Subject: [PATCH] Ensure version info only gets pasted once --- qutebrowser/misc/utilcmds.py | 3 ++- qutebrowser/utils/version.py | 18 ++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/qutebrowser/misc/utilcmds.py b/qutebrowser/misc/utilcmds.py index cc494a180..d2743d56e 100644 --- a/qutebrowser/misc/utilcmds.py +++ b/qutebrowser/misc/utilcmds.py @@ -39,6 +39,7 @@ from qutebrowser.utils import log, objreg, usertypes, message, debug, utils from qutebrowser.commands import cmdutils, runners, cmdexc from qutebrowser.config import config, configdata from qutebrowser.misc import consolewidget +from qutebrowser.utils.version import pastebin_version @cmdutils.register(maxsplit=1, no_cmd_split=True, no_replace_variables=True) @@ -380,4 +381,4 @@ def version(win_id, paste=False): tabbed_browser.openurl(QUrl('qute://version'), newtab=True) if paste: - utils.version.pastebin_version() + pastebin_version() diff --git a/qutebrowser/utils/version.py b/qutebrowser/utils/version.py index fd6fdfa23..779be348b 100644 --- a/qutebrowser/utils/version.py +++ b/qutebrowser/utils/version.py @@ -65,6 +65,7 @@ class DistributionInfo: pretty = attr.ib() +PASTEBIN_URL = None Distribution = enum.Enum( 'Distribution', ['unknown', 'ubuntu', 'debian', 'void', 'arch', 'gentoo', 'fedora', 'opensuse', 'linuxmint', 'manjaro']) @@ -453,22 +454,31 @@ def opengl_vendor(): # pragma: no cover def pastebin_version(): """Pastebin the version and log the url to messages.""" - app = QApplication.instance() - http_client = httpclient.HTTPClient() - def _get_paste_title(): return "qute version info {}".format(qutebrowser.__version__) - def _on_paste_version_success(url): + def _yank_url(url): utils.set_clipboard(url) message.info("Version url {} yanked to clipboard.".format(url)) + + def _on_paste_version_success(url): + global PASTEBIN_URL + _yank_url(url) pbclient.deleteLater() + PASTEBIN_URL = url def _on_paste_version_err(text): message.error("Failed to pastebin version" " info: {}".format(text)) pbclient.deleteLater() + if PASTEBIN_URL: + _yank_url(PASTEBIN_URL) + return + + app = QApplication.instance() + http_client = httpclient.HTTPClient() + misc_api = pastebin.PastebinClient.MISC_API_URL pbclient = pastebin.PastebinClient(http_client, parent=app, api_url=misc_api)