From cfb1ce3d258794d13a8ab922c7c5e93ee3898ddb Mon Sep 17 00:00:00 2001 From: xfangfang <2553041586@qq.com> Date: Fri, 17 Sep 2021 22:58:34 +0800 Subject: [PATCH] Better configuration file format --- Macast.py | 3 +++ i18n/zh_CN/LC_MESSAGES/macast.po | 4 ++-- macast/macast.py | 4 ++-- macast/utils.py | 2 +- macast_renderer/mpv.py | 3 +++ 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Macast.py b/Macast.py index a5167bb01..010d28d2d 100644 --- a/Macast.py +++ b/Macast.py @@ -11,6 +11,7 @@ logger = logging.getLogger("Macast") logger.setLevel(logging.DEBUG) + def get_base_path(path="."): if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'): base_path = sys._MEIPASS @@ -18,6 +19,7 @@ def get_base_path(path="."): base_path = os.getcwd() return os.path.join(base_path, path) + try: locale = Setting.get_locale() lang = gettext.translation('macast', localedir=get_base_path('i18n'), languages=[locale]) @@ -29,6 +31,7 @@ def get_base_path(path="."): logger.error("Macast Loading Default Language en_US") if __name__ == '__main__': + Setting.load() mpv_path = 'mpv' if sys.platform == 'darwin': mpv_path = get_base_path('bin/MacOS/mpv') diff --git a/i18n/zh_CN/LC_MESSAGES/macast.po b/i18n/zh_CN/LC_MESSAGES/macast.po index 04bcdd8dd..37ad09fef 100644 --- a/i18n/zh_CN/LC_MESSAGES/macast.po +++ b/i18n/zh_CN/LC_MESSAGES/macast.po @@ -57,8 +57,8 @@ msgstr "打开配置目录" msgid "Check For Updates" msgstr "检查更新" -msgid "About" -msgstr "关于" +msgid "Help" +msgstr "帮助" msgid "Macast New Update {}" msgstr "Macast有新版本 {}" diff --git a/macast/macast.py b/macast/macast.py index 6e9774824..e4cc0320c 100644 --- a/macast/macast.py +++ b/macast/macast.py @@ -418,7 +418,7 @@ def build_setting_menu(self): ], self.on_menubar_icon_change_click)) self.open_config_menuitem = MenuItem(_("Open Config Directory"), self.on_open_config_click) self.check_update_menuitem = MenuItem(_("Check For Updates"), self.on_check_click) - self.about_menuitem = MenuItem(_("About"), self.on_about_click) + self.about_menuitem = MenuItem(_("Help"), self.on_about_click) self.menubar_icon_menuitem.items()[self.setting_menubar_icon].checked = True player_settings = self.dlna_service.renderer.renderer_setting.build_menu() @@ -588,7 +588,7 @@ def on_start_at_login_click(self, item): self.notification(_("Error"), _(res[1])) def on_about_click(self, _): - self.open_browser('https://github.com/xfangfang/Macast') + self.open_browser('https://xfangfang.github.io/Macast/') def on_toggle_service_click(self, item): if Setting.is_service_running(): diff --git a/macast/utils.py b/macast/utils.py index c31cd2963..ac58c2705 100644 --- a/macast/utils.py +++ b/macast/utils.py @@ -49,7 +49,7 @@ def save(): if not os.path.exists(SETTING_DIR): os.makedirs(SETTING_DIR) with open(Setting.setting_path, "w") as f: - json.dump(obj=Setting.setting, fp=f) + json.dump(obj=Setting.setting, fp=f, sort_keys=True, indent=4) @staticmethod def load(): diff --git a/macast_renderer/mpv.py b/macast_renderer/mpv.py index e00c6651d..6a34dbeae 100644 --- a/macast_renderer/mpv.py +++ b/macast_renderer/mpv.py @@ -58,6 +58,7 @@ def __init__(self, lang=gettext.gettext, path="mpv"): self.mpv_sock = '/tmp/macast_mpvsocket{}'.format(mpv_rand) self.path = path self.proc = None + self.title = Setting.get_friendly_name() self.mpv_thread = None self.ipc_thread = None self.ipc_sock = None @@ -99,6 +100,7 @@ def set_media_url(self, data): def set_media_title(self, data): """ data : string """ + self.title = data self.send_command(['set_property', 'title', data]) def set_media_position(self, data): @@ -408,6 +410,7 @@ def reload(self): def loadfile(): logger.debug("mpv loadfile") self.send_command(['loadfile', uri, 'replace']) + self.send_command(['set_property', 'title', self.title]) cherrypy.engine.unsubscribe('mpvipc_start', loadfile) def resatrt():