@gtkx/css 0.6.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  import { events } from "@gtkx/ffi";
2
- import { DisplayManager } from "@gtkx/ffi/gdk";
3
- import { CssProvider, StyleContext } from "@gtkx/ffi/gtk";
2
+ import * as Gdk from "@gtkx/ffi/gdk";
3
+ import * as Gtk from "@gtkx/ffi/gtk";
4
4
  const STYLE_PROVIDER_PRIORITY_APPLICATION = 600;
5
5
  let isGtkReady = false;
6
6
  const pendingSheets = [];
@@ -11,7 +11,15 @@ const flushPendingStyles = () => {
11
11
  }
12
12
  pendingSheets.length = 0;
13
13
  };
14
+ const resetGtkState = () => {
15
+ isGtkReady = false;
16
+ // Re-register the start listener for the next start() call
17
+ events.once("start", flushPendingStyles);
18
+ };
19
+ // Initial registration
14
20
  events.once("start", flushPendingStyles);
21
+ // Handle stop to reset state and prepare for potential restart
22
+ events.on("stop", resetGtkState);
15
23
  /**
16
24
  * Custom StyleSheet implementation for Emotion that outputs to GTK's CssProvider.
17
25
  * Implements Emotion's StyleSheet interface to enable CSS-in-JS with GTK widgets.
@@ -30,10 +38,10 @@ export class StyleSheet {
30
38
  }
31
39
  ensureProvider() {
32
40
  if (!this.provider) {
33
- this.provider = new CssProvider();
34
- this.display = DisplayManager.get().getDefaultDisplay();
41
+ this.provider = new Gtk.CssProvider();
42
+ this.display = Gdk.DisplayManager.get().getDefaultDisplay();
35
43
  if (this.display) {
36
- StyleContext.addProviderForDisplay(this.display, this.provider, STYLE_PROVIDER_PRIORITY_APPLICATION);
44
+ Gtk.StyleContext.addProviderForDisplay(this.display, this.provider, STYLE_PROVIDER_PRIORITY_APPLICATION);
37
45
  this.isRegistered = true;
38
46
  }
39
47
  }
@@ -64,7 +72,7 @@ export class StyleSheet {
64
72
  }
65
73
  flush() {
66
74
  if (this.provider && this.display && this.isRegistered) {
67
- StyleContext.removeProviderForDisplay(this.display, this.provider);
75
+ Gtk.StyleContext.removeProviderForDisplay(this.display, this.provider);
68
76
  this.isRegistered = false;
69
77
  }
70
78
  this.rules = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gtkx/css",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "description": "Emotion-style CSS-in-JS for GTKX applications",
5
5
  "keywords": [
6
6
  "gtk",
@@ -35,7 +35,7 @@
35
35
  "dependencies": {
36
36
  "@emotion/cache": "11.14.0",
37
37
  "@emotion/serialize": "1.3.3",
38
- "@gtkx/ffi": "0.6.1"
38
+ "@gtkx/ffi": "0.7.0"
39
39
  },
40
40
  "scripts": {
41
41
  "build": "tsc -b && cp ../../README.md .",