This repository has been archived by the owner on May 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstyle.js
66 lines (54 loc) · 1.49 KB
/
style.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
'use strict';
const { St, Shell, GObject, Gio, GLib, Gtk, Meta, Clutter } = imports.gi;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const CustomStylesPath = Me.dir.get_child('./').get_path();
var Style = class {
constructor() {
this.styles = {};
this.style_contents = {};
}
unloadAll() {
let ctx = St.ThemeContext.get_for_stage(global.stage);
let theme = ctx.get_theme();
Object.keys(this.styles).forEach((k) => {
let fn = this.styles[k];
theme.unload_stylesheet(fn);
});
}
build(name, style_array) {
let fn = this.styles[name];
let ctx = St.ThemeContext.get_for_stage(global.stage);
let theme = ctx.get_theme();
let content = '';
style_array.forEach((k) => {
content = `${content}\n${k}`;
});
if (this.style_contents[name] === content) {
// log('skip regeneration');
return;
}
if (fn) {
theme.unload_stylesheet(fn);
} else {
fn = Gio.File.new_for_path(`${CustomStylesPath}/${name}.css`);
this.styles[name] = fn;
}
this.style_contents[name] = content;
const [, etag] = fn.replace_contents(
content,
null,
false,
Gio.FileCreateFlags.REPLACE_DESTINATION,
null
);
theme.load_stylesheet(fn);
// log(content);
}
rgba(color) {
let clr = color || [1, 1, 1, 1];
let res = clr.map((r) => Math.floor(255 * r));
res[3] = clr[3].toFixed(1);
return res.join(',');
}
};