Skip to content

Commit

Permalink
fix: 手动检查更新
Browse files Browse the repository at this point in the history
  • Loading branch information
yuhldr committed Sep 22, 2024
1 parent dde9b77 commit a57de02
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 130 deletions.
20 changes: 8 additions & 12 deletions data/resources/lfy.cmb
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,12 @@
(1,176,"GtkButton","btn_translate",169,None,None,None,6,None,None),
(1,177,"GtkScrolledWindow",None,151,None,None,None,2,None,None),
(1,178,"GtkTextView","tv_to",177,None,None,None,None,None,None),
(1,182,"(section)","st_gp",87,None,None,None,3,None,None),
(1,183,"(item)","gp_reset_restore",182,None,None,None,None,None,None),
(1,184,"(item)","gp_up",182,None,None,None,1,None,None),
(1,185,"(item)","gp_down",182,None,None,None,2,None,None),
(1,186,"(section)","st_pref",87,None,None,None,3,None,None),
(1,187,"(item)","app_preferences",186,None,None,None,None,None,None),
(1,188,"(item)","win_show-help-overlay",186,None,None,None,1,None,None),
(1,189,"(item)","app_about",186,None,None,None,2,None,None),
(1,189,"(item)","app_about",186,None,None,None,3,None,None),
(1,190,"(item)","gp_up",149,None,None,None,1,None,None),
(1,191,"(item)","find_update",186,None,None,None,2,None,None),
(2,2,"AdwPreferencesDialog","PreferencesDialog",None,None,None,None,-1,None,None),
(2,5,"AdwPreferencesPage","app_general",2,None,None,None,-1,None,None),
(2,14,"AdwPreferencesGroup","apg_translate",5,None,None,None,None,None,None),
Expand Down Expand Up @@ -147,18 +145,16 @@
(1,178,"GtkTextView","right-margin","8",None,None,None,None,None,None,None,None,None),
(1,178,"GtkTextView","wrap-mode","char",None,None,None,None,None,None,None,None,None),
(1,178,"GtkWidget","margin-top","5",None,None,None,None,None,None,None,None,None),
(1,183,"(item)","action","app.gp_reset_restore",None,None,None,None,None,None,None,None,None),
(1,183,"(item)","label","Reset/Restore UI",1,None,None,None,None,None,None,None,None),
(1,184,"(item)","action","app.gp_up",None,None,None,None,None,None,None,None,None),
(1,184,"(item)","label","Hide the original text",1,None,None,None,None,None,None,None,None),
(1,185,"(item)","action","app.gp_down",None,None,None,None,None,None,None,None,None),
(1,185,"(item)","label","Hide the translated text",1,None,None,None,None,None,None,None,None),
(1,187,"(item)","action","app.preferences",None,None,None,None,None,None,None,None,None),
(1,187,"(item)","label","_Preferences",1,None,None,None,None,None,None,None,None),
(1,188,"(item)","action","win.show-help-overlay",None,None,None,None,None,None,None,None,None),
(1,188,"(item)","label","_Keyboard Shortcuts",1,None,None,None,None,None,None,None,None),
(1,189,"(item)","action","app.about",None,None,None,None,None,None,None,None,None),
(1,189,"(item)","label","_About lfy",1,None,None,None,None,None,None,None,None),
(1,190,"(item)","action","app.gp_up",None,None,None,None,None,None,None,None,None),
(1,190,"(item)","label","Hide the original text",1,None,None,None,None,None,None,None,None),
(1,191,"(item)","action","app.find_update",None,None,None,None,None,None,None,None,None),
(1,191,"(item)","label","_Check for updates",1,None,None,None,None,None,None,None,None),
(2,5,"AdwPreferencesPage","icon-name","applications-system-symbolic",None,None,None,None,None,None,None,None,None),
(2,5,"AdwPreferencesPage","title","General",1,None,None,None,None,None,None,None,None),
(2,15,"AdwActionRow","subtitle","setup API Key for translation Server, click on the right to the details",1,None,None,None,None,None,None,None,None),
Expand Down Expand Up @@ -239,7 +235,7 @@
(6,16,"GtkShortcutsShortcut","action-name","app.gp_down",None,None,None,None,None,None,None,None,None),
(6,16,"GtkShortcutsShortcut","title","Hide the translated text",1,None,None,None,None,None,None,None,None),
(6,16,"GtkWidget","tooltip-text","Copy detected, translate immediately",1,None,None,None,None,None,None,None,None),
(10,29,"AdwNavigationPage","title","test",1,None,None,None,None,None,None,None,None),
(10,29,"AdwNavigationPage","title","test",None,None,None,None,None,None,None,None,None),
(10,31,"AdwHeaderBar","title-widget",None,None,None,None,None,32,None,None,None,None),
(10,32,"AdwWindowTitle","title","Translate Server",1,None,None,None,None,None,None,None,None),
(10,36,"AdwEntryRow","show-apply-button","true",None,None,None,None,None,None,None,None,None),
Expand Down
2 changes: 1 addition & 1 deletion data/resources/server-preferences.ui
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<requires lib="gtk" version="4.12"/>
<requires lib="libadwaita" version="1.4"/>
<template class="ServerPreferencesPage" parent="AdwNavigationPage">
<property name="title" translatable="yes">test</property>
<property name="title">test</property>
<child>
<object class="AdwToolbarView">
<child type="top">
Expand Down
14 changes: 4 additions & 10 deletions data/resources/translate.ui
Original file line number Diff line number Diff line change
Expand Up @@ -140,20 +140,10 @@
<attribute name="action">app.copy2translate</attribute>
<attribute name="label" translatable="yes">Copy to translate</attribute>
</item>
</section>
<section id="st_gp">
<item>
<attribute name="action">app.gp_reset_restore</attribute>
<attribute name="label" translatable="yes">Reset/Restore UI</attribute>
</item>
<item>
<attribute name="action">app.gp_up</attribute>
<attribute name="label" translatable="yes">Hide the original text</attribute>
</item>
<item>
<attribute name="action">app.gp_down</attribute>
<attribute name="label" translatable="yes">Hide the translated text</attribute>
</item>
</section>
<section id="st_pref">
<item>
Expand All @@ -164,6 +154,10 @@
<attribute name="action">win.show-help-overlay</attribute>
<attribute name="label" translatable="yes">_Keyboard Shortcuts</attribute>
</item>
<item>
<attribute name="action">app.find_update</attribute>
<attribute name="label" translatable="yes">_Check for updates</attribute>
</item>
<item>
<attribute name="action">app.about</attribute>
<attribute name="label" translatable="yes">_About lfy</attribute>
Expand Down
35 changes: 26 additions & 9 deletions lfy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from gi.repository import Adw, Gdk, Gio, GLib, Gtk

from lfy import RES_PATH, VERSION
from lfy import PACKAGE_URL, RES_PATH, VERSION
from lfy.api.utils import is_text
from lfy.api.utils.bak import backup_gsettings
from lfy.api.utils.check_update import main as check_update
Expand Down Expand Up @@ -49,6 +49,7 @@ def __init__(self, app_id, version, schemas_dir):
self.create_action('quit', lambda *_: self.quit(),
['<primary>q'])
self.create_action('about', self.on_about_action)
self.create_action('find_update', self.find_update)

self.create_action('del_wrapping', self.on_del_wrapping_action,
['<alt>d'])
Expand All @@ -68,10 +69,14 @@ def __init__(self, app_id, version, schemas_dir):
self.cb = Gdk.Display().get_default().get_clipboard()
self.copy_change_id = self.cb.connect("changed", self.copy)

if Settings.get().auto_check_update:
threading.Thread(target=self.find_update, daemon=True).start()
self.find_update()

def get_translate_win(self):
"""翻译窗口
Returns:
_type_: _description_
"""
win = self.props.active_window # pylint: disable=E1101
if not win:
width, height = Settings.get().window_size
Expand Down Expand Up @@ -280,12 +285,24 @@ def update_app(self, update_msg):
# pylint: disable=E1101
self.props.active_window.tv_from.get_buffer().set_text(update_msg)

def find_update(self):
def find_update(self, _widget=None, _w=None):
"""查找更新
"""

update_msg = check_update()
if update_msg is not None:
time.sleep(2)
print(update_msg)
GLib.idle_add(self.update_app, update_msg)
def fu():
"""更新子线程
"""
update_msg = check_update()
if update_msg is not None:
time.sleep(2)
print(update_msg)
GLib.idle_add(self.update_app, update_msg)
elif _widget is not None:
# 手动更新
s = _("There is no new version. The current version is {}.").format(VERSION)
s += "\n"
s += _("You can go to {} to view the beta version.").format(PACKAGE_URL)
GLib.idle_add(self.update_app, s)

if Settings.get().auto_check_update:
threading.Thread(target=fu, daemon=True).start()
Loading

0 comments on commit a57de02

Please sign in to comment.