-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modify theme load logic so that now we don't need to reload GNOME-Shell
to change IBus themes. Signed-off-by: Hollow Man <[email protected]>
- Loading branch information
1 parent
42bc81b
commit 8aa6cbe
Showing
8 changed files
with
44 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,8 +36,6 @@ const UNKNOWN = { ON: 0, OFF: 1, DEFAULT: 2 }; | |
const ASCIIMODES = ["en", "A", "英"]; | ||
const INPUTMODE = "InputMode"; | ||
const uuid = "[email protected]"; | ||
const SETTINGS_KEY = "custom-theme"; | ||
const PERMISSIONS_MODE = 0o744; | ||
|
||
const IBusAutoSwitch = GObject.registerClass( | ||
{ | ||
|
@@ -280,104 +278,43 @@ 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(); | ||
} | ||
|
||
disable() { | ||
if (this._changedId) { | ||
this._settings.disconnect(this._changedId); | ||
gsettings.disconnect(this._changedId); | ||
this._changedId = 0; | ||
} | ||
this._changeTheme(); | ||
} | ||
|
||
// 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...")); | ||
} | ||
} | ||
); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 <EMAIL@ADDRESS>\n" | ||
"Language-Team: LANGUAGE <[email protected]>\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 "" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 <[email protected]>\n" | ||
"Language-Team: Chinese (simplified) <[email protected]>\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 "自定义主题" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,5 +8,5 @@ | |
"original-authors": ["[email protected]"], | ||
"uuid": "[email protected]", | ||
"extension-id": "customize-ibus", | ||
"version": 14 | ||
"version": 15 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters