diff --git a/README.md b/README.md index 217aad5..aa3c04c 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ (English version is down below) -### 注意:如果后期无重大 BUG 的话,v14 将是支持 GNOME 3.38 的最后一个版本 +### 注意:如果后期无重大 BUG 的话,v15 将是支持 GNOME 3.38 的最后一个版本 在 GNOME Shell 中更改 IBus 的候选框方向、shell 主题、背景图片、字体和输入法默认语言。 @@ -53,7 +53,7 @@ IBus Tweaker 中提供的主题已经被我制作成为 IBus 主题样式表合 ### _提示:_ 1. 推荐使用 X11。如果你在 Wayland 中更改 IBus 主题,你的当前所有工作都将会丢失,因为 Wayland 下只支持通过重新登陆来重启 GNOME-shell。 -2. 在 Fedora 33 和 Ubuntu 20.04, GNOME-shell 3.38 中(v3,v5,v9,v11,v14)通过了测试。 +2. 在 Fedora 33 和 Ubuntu 20.04, GNOME-shell 3.38 中(v3,v5,v9,v11,v14,v15)通过了测试。 3. 对于那些不使用 GNOME 而是使用如 KDE,XFCE 等桌面环境的用户,更改 IBus GTK 主题也请使用我的另外一个项目[IBus-Theme](https://github.com/HollowMan6/IBus-Theme)。 ## 更改 IBus 背景图片的实现 @@ -78,20 +78,19 @@ background-size: cover; - [x] V9: 增加更改 IBus 背景图片功能。 - [x] V14: 将从 GNOME-Shell 主题提取 IBus 样式功能剥离,使用 Python 下 CSS 解析器而并非正则表达式实现功能,生成额外 IBus 样式表供用户修改测试使用。 - [x] V14: 本扩展改为接受用户提供的 IBus 样式表进行样式的应用。 +- [x] V15: 修改主题加载逻辑,免去每次更换主题都要重启 GNOME-Shell。 ## 致谢 1. [ibus-font-setting](https://extensions.gnome.org/extension/1121/ibus-font-setting/) 2. [ibus-tweaker](https://github.com/tuberry/ibus-tweaker) -3. [user-theme](https://gitlab.gnome.org/GNOME/gnome-shell-extensions/-/tree/master/extensions/user-theme) -4. [shell-restarter](https://github.com/koolskateguy89/gnome-shell-extension-shell-restarter) -5. [background-logo](https://pagure.io/background-logo-extension) +3. [background-logo](https://pagure.io/background-logo-extension) _该项目是谷歌编程之夏 (GSoC) 2021 于[OpenSUSE](https://github.com/openSUSE/mentoring/issues/158)社区成果的一部分。_ # Customize IBus -### Note: If no severe bug was found later, v14 will be the last version that support GNOME 3.38. +### Note: If no severe bug was found later, v15 will be the last version that support GNOME 3.38. Customize IBus for orientation, shell theme, background picture, font and ascii mode auto-switch. @@ -125,7 +124,7 @@ Themes in IBus Tweaker have been converted by me as IBus theme stylesheets colle ### _NOTE:_ 1. Recommend to use X11. If you change IME theme under Wayland, all your current work may be lost (Since Wayland only support relogin to restart the GNOME-shell). -2. Tested on Fedora 33 and Ubuntu 20.04, GNOME-shell 3.38(v3, v5, v9, v11, v14). +2. Tested on Fedora 33 and Ubuntu 20.04, GNOME-shell 3.38(v3, v5, v9, v11, v14, v15). 3. For users who don't use GNOME but other desktop environments like KDE, XFCE, etc., please also use another project of mine [IBus-Theme](https://github.com/HollowMan6/IBus-Theme) to use a different GTK theme for IBus. ## To-do @@ -136,14 +135,13 @@ Themes in IBus Tweaker have been converted by me as IBus theme stylesheets colle - [x] v9: Add functionality to modify IBus Background picture. - [x] V14: Strip the current function of extracting IBus style from Gnome shell theme, implement using CSS parser libraries in Python instead of regular expression. Additional IBus style sheets are generated for users to modify and test. - [x] V14: Modify this extension to accept IBus style sheets provided by users for style application. +- [x] V15: Modify theme load logic so that now we don't need to reload GNOME-Shell to change IBus themes. ## Acknowledgements 1. [ibus-font-setting](https://extensions.gnome.org/extension/1121/ibus-font-setting/) 2. [ibus-tweaker](https://github.com/tuberry/ibus-tweaker) -3. [user-theme](https://gitlab.gnome.org/GNOME/gnome-shell-extensions/-/tree/master/extensions/user-theme) -4. [shell-restarter](https://github.com/koolskateguy89/gnome-shell-extension-shell-restarter) -5. [background-logo](https://pagure.io/background-logo-extension) +3. [background-logo](https://pagure.io/background-logo-extension) _This project is part of the achievement of the Google Summer of Code 2021 at [OpenSUSE](https://github.com/openSUSE/mentoring/issues/158)._ diff --git a/customize-ibus@hollowman.ml/extension.js b/customize-ibus@hollowman.ml/extension.js index 0405495..88cf20b 100644 --- a/customize-ibus@hollowman.ml/extension.js +++ b/customize-ibus@hollowman.ml/extension.js @@ -36,8 +36,6 @@ const UNKNOWN = { ON: 0, OFF: 1, DEFAULT: 2 }; const ASCIIMODES = ["en", "A", "英"]; const INPUTMODE = "InputMode"; const uuid = "customize-ibus@hollowman.ml"; -const SETTINGS_KEY = "custom-theme"; -const PERMISSIONS_MODE = 0o744; const IBusAutoSwitch = GObject.registerClass( { @@ -280,14 +278,13 @@ const IBusThemeManager = GObject.registerClass( class IBusThemeManager extends GObject.Object { _init() { super._init(); - this._settings = ExtensionUtils.getSettings(); this._prevCssStylesheet = null; this.enable(); } enable() { - this._changedId = this._settings.connect( - `changed::${SETTINGS_KEY}`, + this._changedId = gsettings.connect( + `changed::${Fields.CUSTOMTHEME}`, this._changeTheme.bind(this) ); this._changeTheme(); @@ -295,7 +292,7 @@ const IBusThemeManager = GObject.registerClass( disable() { if (this._changedId) { - this._settings.disconnect(this._changedId); + gsettings.disconnect(this._changedId); this._changedId = 0; } this._changeTheme(); @@ -303,81 +300,21 @@ const IBusThemeManager = GObject.registerClass( // Load stylesheet _changeTheme() { - let stylesheet = this._settings.get_string(SETTINGS_KEY); - let enabled = this._settings.get_boolean(Fields.ENABLECUSTOMTHEME); + let stylesheet = gsettings.get_string(Fields.CUSTOMTHEME); + let enabled = gsettings.get_boolean(Fields.ENABLECUSTOMTHEME); - let newFileContent = ""; - let notFirstStart = false; - let needRestart = false; - if (this._prevCssStylesheet) notFirstStart = true; + let themeContext = St.ThemeContext.get_for_stage(global.stage); + let theme = themeContext.get_theme(); + if (this._prevCssStylesheet) + theme.unload_stylesheet(Gio.File.new_for_path(this._prevCssStylesheet)); if (stylesheet && enabled) { global.log(_("loading user theme for IBus:") + stylesheet); - let file = Gio.File.new_for_path(stylesheet); - let [success, contents] = file.load_contents(null); - global.log(success); - newFileContent = - "/* " + - _("Copied from Source File: ") + - stylesheet + - " */\n\n" + - contents; + theme.load_stylesheet(Gio.File.new_for_path(stylesheet)); this._prevCssStylesheet = stylesheet; } else { global.log(_("loading default theme for IBus")); - if (stylesheet) - this._settings.set_value(SETTINGS_KEY, new GLib.Variant("s", "")); - this._prevCssStylesheet = "Unsetted"; + this._prevCssStylesheet = ""; } - let file = Gio.File.new_for_path( - GLib.build_filenamev([ - global.userdatadir, - "extensions", - uuid, - "stylesheet.css", - ]) - ); - if (!file.query_exists(null)) - file = Gio.File.new_for_path( - GLib.build_filenamev([ - global.datadir, - "extensions", - uuid, - "stylesheet.css", - ]) - ); - if ( - GLib.mkdir_with_parents( - file.get_parent().get_path(), - PERMISSIONS_MODE - ) === 0 - ) { - let [success, contents] = file.load_contents(null); - if (success) { - if (contents != newFileContent && stylesheet != file.get_path()) { - file.replace_contents( - newFileContent, - null, - false, - Gio.FileCreateFlags.REPLACE_DESTINATION, - null - ); - needRestart = true; - } - } else { - file.replace_contents( - newFileContent, - null, - false, - Gio.FileCreateFlags.REPLACE_DESTINATION, - null - ); - } - } - if (notFirstStart || needRestart) this.restart(); - } - - restart() { - Meta.restart(_("Restarting...")); } } ); diff --git a/customize-ibus@hollowman.ml/locale/customize-ibus.pot b/customize-ibus@hollowman.ml/locale/customize-ibus.pot index b41c0f5..e9e3510 100644 --- a/customize-ibus@hollowman.ml/locale/customize-ibus.pot +++ b/customize-ibus@hollowman.ml/locale/customize-ibus.pot @@ -6,9 +6,9 @@ #, fuzzy msgid "" msgstr "" -"Project-Id-Version: Customize Ibus 14\n" +"Project-Id-Version: Customize Ibus 15\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-04-19 19:15+0800\n" +"POT-Creation-Date: 2021-04-20 12:59+0800\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -17,26 +17,18 @@ msgstr "" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" -#: extension.js:213 +#: extension.js:211 msgid "loading background for IBus:" msgstr "" -#: extension.js:314 +#: extension.js:311 msgid "loading user theme for IBus:" msgstr "" -#: extension.js:320 -msgid "Copied from Source File: " -msgstr "" - -#: extension.js:326 +#: extension.js:315 msgid "loading default theme for IBus" msgstr "" -#: extension.js:380 -msgid "Restarting..." -msgstr "" - #: prefs.js:61 msgid "Custom IME theme" msgstr "" diff --git a/customize-ibus@hollowman.ml/locale/zh_CN/LC_MESSAGES/customize-ibus.po b/customize-ibus@hollowman.ml/locale/zh_CN/LC_MESSAGES/customize-ibus.po index ad5440a..7939601 100644 --- a/customize-ibus@hollowman.ml/locale/zh_CN/LC_MESSAGES/customize-ibus.po +++ b/customize-ibus@hollowman.ml/locale/zh_CN/LC_MESSAGES/customize-ibus.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: customize-ibus 1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-04-19 19:15+0800\n" +"POT-Creation-Date: 2021-04-20 12:52+0800\n" "PO-Revision-Date: 2021-03-27 16:22+0800\n" "Last-Translator: Hollow Man \n" "Language-Team: Chinese (simplified) \n" @@ -17,26 +17,18 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -#: extension.js:213 +#: extension.js:211 msgid "loading background for IBus:" msgstr "正在为IBus加载背景:" -#: extension.js:314 +#: extension.js:311 msgid "loading user theme for IBus:" msgstr "正在为IBus加载用户主题:" -#: extension.js:320 -msgid "Copied from Source File: " -msgstr "拷贝自源文件:" - -#: extension.js:326 +#: extension.js:315 msgid "loading default theme for IBus" msgstr "正在为IBus加载当前系统主题" -#: extension.js:380 -msgid "Restarting..." -msgstr "正在重新启动⋯⋯" - #: prefs.js:61 msgid "Custom IME theme" msgstr "自定义主题" diff --git a/customize-ibus@hollowman.ml/metadata.json b/customize-ibus@hollowman.ml/metadata.json index 174d033..b742bc4 100644 --- a/customize-ibus@hollowman.ml/metadata.json +++ b/customize-ibus@hollowman.ml/metadata.json @@ -8,5 +8,5 @@ "original-authors": ["hollowman@hollowman.ml"], "uuid": "customize-ibus@hollowman.ml", "extension-id": "customize-ibus", - "version": 14 + "version": 15 } diff --git a/customize-ibus@hollowman.ml/prefs.js b/customize-ibus@hollowman.ml/prefs.js index 0a7db6e..c4f3f94 100644 --- a/customize-ibus@hollowman.ml/prefs.js +++ b/customize-ibus@hollowman.ml/prefs.js @@ -85,7 +85,7 @@ const CustomizeIBus = GObject.registerClass( }); this._fileChooser.connect("response", (dlg, response) => { if (response !== Gtk.ResponseType.ACCEPT) return; - gsettings.set_string("custom-bg", dlg.get_file().get_path()); + gsettings.set_string(Fields.CUSTOMBG, dlg.get_file().get_path()); }); this._logoPicker = new Gtk.Button({ @@ -96,7 +96,7 @@ const CustomizeIBus = GObject.registerClass( this._fileChooser.show(); }); gsettings.connect( - "changed::custom-bg", + `changed::${Fields.CUSTOMBG}`, this._updateLogoPicker.bind(this) ); this._updateLogoPicker(); @@ -110,7 +110,7 @@ const CustomizeIBus = GObject.registerClass( }); this._cssFileChooser.connect("response", (dlg, response) => { if (response !== Gtk.ResponseType.ACCEPT) return; - gsettings.set_string("custom-theme", dlg.get_file().get_path()); + gsettings.set_string(Fields.CUSTOMTHEME, dlg.get_file().get_path()); }); this._cssPicker = new Gtk.Button({ @@ -121,20 +121,20 @@ const CustomizeIBus = GObject.registerClass( this._cssFileChooser.show(); }); gsettings.connect( - "changed::custom-theme", + `changed::${Fields.CUSTOMTHEME}`, this._updateCssPicker.bind(this) ); this._updateCssPicker(); } _updateLogoPicker() { - const filename = gsettings.get_string("custom-bg"); + const filename = gsettings.get_string(Fields.CUSTOMBG); if (!GLib.basename(filename)) this._logoPicker.label = _("(None)"); else this._logoPicker.label = GLib.basename(filename); } _updateCssPicker() { - const filename = gsettings.get_string("custom-theme"); + const filename = gsettings.get_string(Fields.CUSTOMTHEME); if (!GLib.basename(filename)) this._cssPicker.label = _("(None)"); else this._cssPicker.label = GLib.basename(filename); } @@ -163,18 +163,18 @@ const CustomizeIBus = GObject.registerClass( }); this._field_use_custom_font.connect("notify::active", (widget) => { this._field_custom_font.set_sensitive(widget.active); - ibusGsettings.set_boolean("use-custom-font", widget.active); + ibusGsettings.set_boolean(Fields.USECUSTOMFONT, widget.active); }); this._field_use_custom_bg.connect("notify::active", (widget) => { this._logoPicker.set_sensitive(widget.active); - ibusGsettings.set_boolean("use-custom-bg", widget.active); + ibusGsettings.set_boolean(Fields.USECUSTOMBG, widget.active); }); this._field_enable_custom_theme.connect("notify::active", (widget) => { this._cssPicker.set_sensitive(widget.active); - ibusGsettings.set_boolean("enable-custom-theme", widget.active); + ibusGsettings.set_boolean(Fields.ENABLECUSTOMTHEME, widget.active); }); this._field_custom_font.connect("font-set", (widget) => { - ibusGsettings.set_string("custom-font", widget.font_name); + ibusGsettings.set_string(Fields.CUSTOMFONT, widget.font_name); gsettings.set_string(Fields.CUSTOMFONT, widget.font_name); }); diff --git a/customize-ibus@hollowman.ml/stylesheet.css b/customize-ibus@hollowman.ml/stylesheet.css deleted file mode 100644 index 714343b..0000000 --- a/customize-ibus@hollowman.ml/stylesheet.css +++ /dev/null @@ -1,3 +0,0 @@ -/* Load IBUS style for user selected shell theme.*/ - -/* Temporary empty */ diff --git a/package.json b/package.json index 043b2ee..070acca 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,12 @@ { "name": "customize-ibus", - "version": "14.0.0", + "version": "15.0.0", "description": "Customize IBus for orientation, shell theme, background picture, font and ascii mode auto-switch.", "dependencies": { - "eslint": "^7.21.0", - "eslint-config-prettier": "^8.1.0", - "eslint-plugin-prettier": "^3.3.1", - "husky": "^5.1.3", + "eslint": "^7.24.0", + "eslint-config-prettier": "^8.2.0", + "eslint-plugin-prettier": "^3.4.0", + "husky": "^6.0.0", "lint-staged": "^10.5.4", "prettier": "^2.2.1" },