[Webview] CF bypass: Improvements
- Removes useless in-app notification - Display server name in headerbar subtitle
This commit is contained in:
@@ -207,11 +207,28 @@ along with Komikku. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
<object class="GtkStackPage">
|
<object class="GtkStackPage">
|
||||||
<property name="name">webview</property>
|
<property name="name">webview</property>
|
||||||
<property name="child">
|
<property name="child">
|
||||||
<object class="GtkLabel" id="webview_title_label">
|
<object class="GtkBox">
|
||||||
<property name="label" translatable="yes">Webview</property>
|
<property name="valign">center</property>
|
||||||
<style>
|
<property name="orientation">vertical</property>
|
||||||
<class name="title"/>
|
<child>
|
||||||
</style>
|
<object class="GtkLabel" id="webview_title_label">
|
||||||
|
<property name="label" translatable="yes">Download Manager</property>
|
||||||
|
<property name="ellipsize">end</property>
|
||||||
|
<property name="single_line_mode">1</property>
|
||||||
|
<style>
|
||||||
|
<class name="title"/>
|
||||||
|
</style>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel" id="webview_subtitle_label">
|
||||||
|
<property name="ellipsize">end</property>
|
||||||
|
<property name="single_line_mode">1</property>
|
||||||
|
<style>
|
||||||
|
<class name="subtitle"/>
|
||||||
|
</style>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
</object>
|
</object>
|
||||||
</property>
|
</property>
|
||||||
</object>
|
</object>
|
||||||
|
@@ -20,12 +20,13 @@ from gi.repository import GObject
|
|||||||
from gi.repository import Gtk
|
from gi.repository import Gtk
|
||||||
from gi.repository import WebKit2
|
from gi.repository import WebKit2
|
||||||
|
|
||||||
from komikku.servers import USER_AGENT
|
|
||||||
from komikku.servers.exceptions import CfBypassError
|
from komikku.servers.exceptions import CfBypassError
|
||||||
from komikku.utils import get_cache_dir
|
from komikku.utils import get_cache_dir
|
||||||
|
|
||||||
CF_RELOAD_MAX = 5
|
CF_RELOAD_MAX = 5
|
||||||
DEBUG = False
|
DEBUG = False
|
||||||
|
USER_AGENT = f'Mozilla/5.0 (X11; Linux {platform.machine()}) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Safari/605.1.15'
|
||||||
|
|
||||||
logger = logging.getLogger('komikku.webview')
|
logger = logging.getLogger('komikku.webview')
|
||||||
|
|
||||||
|
|
||||||
@@ -41,6 +42,7 @@ class Webview(Gtk.ScrolledWindow):
|
|||||||
self.window = window
|
self.window = window
|
||||||
|
|
||||||
self.title_label = self.window.webview_title_label
|
self.title_label = self.window.webview_title_label
|
||||||
|
self.subtitle_label = self.window.webview_subtitle_label
|
||||||
|
|
||||||
Gtk.ScrolledWindow.__init__(self)
|
Gtk.ScrolledWindow.__init__(self)
|
||||||
|
|
||||||
@@ -183,10 +185,12 @@ def bypass_cf(func):
|
|||||||
|
|
||||||
if event != WebKit2.LoadEvent.REDIRECTED and '__cf_chl_tk' in webview.webkit_webview.get_uri():
|
if event != WebKit2.LoadEvent.REDIRECTED and '__cf_chl_tk' in webview.webkit_webview.get_uri():
|
||||||
# Challenge has been passed
|
# Challenge has been passed
|
||||||
|
|
||||||
# Disable images auto-load
|
# Disable images auto-load
|
||||||
webview.webkit_webview.get_settings().set_auto_load_images(False)
|
webview.webkit_webview.get_settings().set_auto_load_images(False)
|
||||||
# Notify user that is must wait (page load finish)
|
|
||||||
webview.window.show_notification(_('Success, challenge solved, please wait…'))
|
# Exit from webview
|
||||||
|
webview.navigate_back(None)
|
||||||
|
|
||||||
if event != WebKit2.LoadEvent.FINISHED:
|
if event != WebKit2.LoadEvent.FINISHED:
|
||||||
return
|
return
|
||||||
@@ -228,6 +232,7 @@ def bypass_cf(func):
|
|||||||
logger.debug(f'{server.id}: Captcha `{webview.webkit_webview.props.title}` detected')
|
logger.debug(f'{server.id}: Captcha `{webview.webkit_webview.props.title}` detected')
|
||||||
# Show webview, user must complete a CAPTCHA
|
# Show webview, user must complete a CAPTCHA
|
||||||
webview.title_label.set_text(_('Please complete CAPTCHA'))
|
webview.title_label.set_text(_('Please complete CAPTCHA'))
|
||||||
|
webview.subtitle_label.set_text(server.name)
|
||||||
webview.show()
|
webview.show()
|
||||||
|
|
||||||
if webview.webkit_webview.props.title != 'ready':
|
if webview.webkit_webview.props.title != 'ready':
|
||||||
@@ -237,9 +242,6 @@ def bypass_cf(func):
|
|||||||
cookie_manager = webview.web_context.get_cookie_manager()
|
cookie_manager = webview.web_context.get_cookie_manager()
|
||||||
cookie_manager.get_cookies(server.base_url, None, on_get_cookies_finish, None)
|
cookie_manager.get_cookies(server.base_url, None, on_get_cookies_finish, None)
|
||||||
|
|
||||||
# Exit from webview
|
|
||||||
webview.navigate_back(None)
|
|
||||||
|
|
||||||
def on_get_cookies_finish(cookie_manager, result, user_data):
|
def on_get_cookies_finish(cookie_manager, result, user_data):
|
||||||
nonlocal done
|
nonlocal done
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user