From 8f529ea0fa071245d9afc9f13d0abe5181516857 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Sat, 19 Jun 2021 18:10:00 +0200 Subject: [PATCH] Fix open browser on servers --- cleantoots/utils.py | 11 ++++++++--- pyproject.toml | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/cleantoots/utils.py b/cleantoots/utils.py index 382db06..0f5335e 100644 --- a/cleantoots/utils.py +++ b/cleantoots/utils.py @@ -1,6 +1,7 @@ import configparser import os import sys +import webbrowser import click @@ -19,18 +20,22 @@ def _config_has_sections(config): def _open_url(url, echo): + opened = False + if _is_tty(): if echo: click.echo( - "We will now open a browser for each account set in the config file." + "We will now try to open a browser for each account set in the config file." ) click.echo( "You'll need to authenticate and then copy the code provided in the web " "page back into this terminal, upon prompt." ) click.pause() - click.launch(url) - else: + result = webbrowser.open(url) + opened = result + + if not opened: click.echo("Go to {}, authenticate and enter the code below.".format(url)) diff --git a/pyproject.toml b/pyproject.toml index 536fe49..b920c04 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "cleantoots" -version = "0.4.1" +version = "0.4.2" description = "Cleanup your toot history." license = "GPL-3.0-or-later" authors = ["Gabriel Augendre "]