Skip to content

Commit 7252482

Browse files
committed
App.applyCss take stylesheets, and an optional reset parameter
1 parent 29d143d commit 7252482

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- add MprisPlayer.track_album
88
- add MprisPlayer.metadata
99
- add Widget.keybind
10+
- App.applyCss takes stylesheets, and an optional reset parameter
1011

1112
## Fixes
1213

src/app.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,16 @@ export class App extends Gtk.Application {
9898
this._cssProviders = [];
9999
};
100100

101-
readonly applyCss = (path: string) => {
101+
readonly applyCss = (pathOrStyle: string, reset = false) => {
102102
const screen = Gdk.Screen.get_default();
103103
if (!screen) {
104104
console.error("couldn't get screen");
105105
return;
106106
}
107107

108+
if (reset)
109+
this.resetCss();
110+
108111
const cssProvider = new Gtk.CssProvider();
109112
cssProvider.connect('parsing-error', (_, section, err) => {
110113
const file = section.get_file().get_path();
@@ -113,7 +116,10 @@ export class App extends Gtk.Application {
113116
});
114117

115118
try {
116-
cssProvider.load_from_path(path);
119+
if (GLib.file_test(pathOrStyle, GLib.FileTest.EXISTS))
120+
cssProvider.load_from_path(pathOrStyle);
121+
else
122+
cssProvider.load_from_data(new TextEncoder().encode(pathOrStyle));
117123
} finally {
118124
// log on parsing-error
119125
}

0 commit comments

Comments
 (0)