Skip to content

Commit

Permalink
fix(node-gtk): Uses snake_case for property names at constructor, fixes
Browse files Browse the repository at this point in the history
#131 + Removed support for  properties + Upgrade examples
  • Loading branch information
JumpLink committed Feb 16, 2024
1 parent 1981c06 commit cbb375c
Show file tree
Hide file tree
Showing 39 changed files with 327 additions and 140 deletions.
12 changes: 9 additions & 3 deletions .ts-for-gir.packages-all.rc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ export default {
environments: ['gjs', 'node'],
modules: ['*'],
girDirectories: [
// General gir files in this repository
'./vala-girs/gir-1.0',
'./girs',

// General gir files installed on the system
"/usr/local/share/gir-1.0",
"/usr/share/gir-1.0",
Expand All @@ -23,6 +27,9 @@ export default {
// GNOME Shell gir file dependencies on Fedora Workstation 39 (package: mutter)
'/usr/lib64/mutter-13',

// Wait for release...
'/usr/lib64/mutter-14',

// GNOME Shell gir file dependencies on Ubuntu 22.04 (package: libmutter-10-dev)
'/usr/lib/x86_64-linux-gnu/mutter-10',

Expand All @@ -35,9 +42,8 @@ export default {
// GNOME Shell gir file dependencies on Ubuntu 23.10 (package: libmutter-13-dev)
'/usr/lib/x86_64-linux-gnu/mutter-13',

// General gir files in this repository
'./vala-girs/gir-1.0',
'./girs',
// Wait for release...
'/usr/lib/x86_64-linux-gnu/mutter-14',
],
ignore: [
'Colorhug-1.0', // Duplicate of ColorHug-1.0
Expand Down
8 changes: 7 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
- Create a Reporter to create a text or json file with warnings like unknown types, renaming, etc and a summary of all that (e.g. 5 type conflicts resolved, 8 unknown types of *gint)
- Update types for GJS v1.75.2, see https://gitlab.gnome.org/GNOME/gjs/-/commit/666755b3b09d765e43d415e76105b828517b5509

# 3.2.7
# 3.2.9
- Upgrade dependencies
- Update examples and removed deprecated function calles like `byteArray.toString()`
- Removed support for `underscore` properties in the generated types, if this causes problems please let us know, then we will undo it again
- node-gtk: Uses snake_case for property names at constructor, fixes #131

# 3.2.8
- Upgrade dependencies
- Add type for import.meta.url, see 142
- C type `const` is readonly in typescript
Expand Down
8 changes: 3 additions & 5 deletions examples/gjs/adw-1-hello/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Adw from './@types/adw-1.js';
const loop = GLib.MainLoop.new(null, false)

const app = new Adw.Application({
application_id: 'com.github.jumplink.gjs.adw-1-hello',
applicationId: 'com.github.jumplink.gjs.adw-1-hello',
flags: Gio.ApplicationFlags.FLAGS_NONE
});

Expand All @@ -26,16 +26,14 @@ const onActivate = (app: Adw.Application) => {
const label = new Gtk.Label({
label: "Hello World",
marginBottom: 11,
margin_top: 11,
marginTop: 11,
})

label.marginTop = 12
label.margin_bottom = 12
label.marginBottom = 12

log(`label.marginTop: ${label.marginTop}`)
log(`label.margin_top: ${label.margin_top}`)
log(`label.marginBottom: ${label.marginBottom}`)
log(`label.margin_bottom: ${label.margin_bottom}`)

const window = new Gtk.ApplicationWindow(app)
window.set_title('Hello')
Expand Down
4 changes: 2 additions & 2 deletions examples/gjs/gio-2-cat-alias/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import GLib from "gi://GLib?version=2.0";
import Gio from "gi://Gio?version=2.0";

const ByteArray = imports.byteArray;
const textDecoder = new TextDecoder()
const loop = GLib.MainLoop.new(null, false);

function cat(filename: string) {
Expand All @@ -24,7 +24,7 @@ function cat(filename: string) {
loop.quit();
return;
}
print(ByteArray.toString(contents));
print(textDecoder.decode(contents));
loop.quit();
});

Expand Down
2 changes: 1 addition & 1 deletion examples/gjs/gio-2-cat-alias/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"module": "ESNext",
"moduleResolution": "node",
},
"include": ["@types/gjs.d.ts"],
"include": ["@types/gjs.d.ts", "@types/dom.d.ts"],
"files": [
"main.ts",
]
Expand Down
6 changes: 4 additions & 2 deletions examples/gjs/gio-2-cat-packages/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,21 @@
*/

import '@girs/gjs';
import '@girs/gjs/dom';
import '@girs/gio-2.0';

import Gio from "gi://Gio?version=2.0";

const ByteArray = imports.byteArray;
const textDecoder = new TextDecoder()

Gio._promisify(Gio.File.prototype, 'load_contents_async', 'load_contents_finish');

async function cat(filename: string) {
const file = Gio.file_new_for_path(filename);

const [contents] = await file.load_contents_async(null);
print(ByteArray.toString(contents));

print(textDecoder.decode(contents));
}

if (ARGV.length !== 1)
Expand Down
2 changes: 1 addition & 1 deletion examples/gjs/gio-2-cat-packages/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"module": "ESNext",
"moduleResolution": "node"
},
"include": ["@girs/gjs", "@girs/gjs/ambient"],
"include": ["@girs/gjs", "@girs/gjs/dom", "@girs/gjs/ambient"],
"files": [
"main.ts",
]
Expand Down
4 changes: 2 additions & 2 deletions examples/gjs/gio-2-cat-promisify/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
*/

import Gio from "gi://Gio?version=2.0";
const ByteArray = imports.byteArray;
const textDecoder = new TextDecoder();

Gio._promisify(Gio.File.prototype, 'load_contents_async', 'load_contents_finish');

async function cat(filename: string) {
const file = Gio.file_new_for_path(filename);

const [contents] = await file.load_contents_async(null);
print(ByteArray.toString(contents));
print(textDecoder.decode(contents));
}

if (ARGV.length !== 1)
Expand Down
2 changes: 1 addition & 1 deletion examples/gjs/gio-2-cat-promisify/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"target": "ESNext",
"module": "ESNext"
},
"include": ["@types/gjs.d.ts"],
"include": ["@types/gjs.d.ts", "@types/dom.d.ts"],
"files": [
"main.ts",
]
Expand Down
4 changes: 2 additions & 2 deletions examples/gjs/gio-2-cat-types-only/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* the label should show a translation of 'Print help'
*/

const ByteArray = imports.byteArray;
const textDecoder = new TextDecoder();
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;

Expand All @@ -25,7 +25,7 @@ function cat(filename: string) {
loop.quit();
return;
}
print(ByteArray.toString(contents));
print(textDecoder.decode(contents));
loop.quit();
});

Expand Down
2 changes: 1 addition & 1 deletion examples/gjs/gio-2-cat-types-only/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"noImplicitThis": true,
"alwaysStrict": true
},
"include": ["@types/gjs.d.ts", "@types/gio-2.0.d.ts", "@types/glib-2.0.d.ts"],
"include": ["@types/gjs.d.ts", "@types/dom.d.ts", "@types/gio-2.0.d.ts", "@types/glib-2.0.d.ts"],
"files": [
"main.ts",
]
Expand Down
6 changes: 4 additions & 2 deletions examples/gjs/gio-2-cat/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
* the label should show a translation of 'Print help'
*/

import imports from './@types/gjs.js';
import './@types/gjs.js';
import './@types/dom.js';
import GLib from './@types/glib-2.0.js';
import Gio from './@types/gio-2.0.js';

const loop = GLib.MainLoop.new(null, false);
const textDecoder = new TextDecoder()

function cat(filename: string) {
const file = Gio.file_new_for_path(filename);
Expand All @@ -25,7 +27,7 @@ function cat(filename: string) {
loop.quit();
return;
}
print(imports.byteArray.toString(contents));
print(textDecoder.decode(contents));
loop.quit();
});

Expand Down
12 changes: 6 additions & 6 deletions examples/gjs/glib-2-spawn-command/main.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
// Example based on https://gist.github.com/buzztaiki/1487781/74ea93d3a30f20c7f094327db9cb263a6286f6d6
import * as GLib from './@types/glib-2.0.js';
const { byteArray } = imports;
const textDecoder = new TextDecoder();

let [res, out, err, status] = GLib.spawn_command_line_sync('ls -la');
if (out) print(byteArray.toString(out));
if (out) print(textDecoder.decode(out));

[res, out] = GLib.spawn_command_line_sync('ls -la');
if (out) print(byteArray.toString(out));
if (out) print(textDecoder.decode(out));

[res, out] = GLib.spawn_sync(null, ['/bin/ls', '-la'], null, 0, null);
if (out) print(byteArray.toString(out));
if (out) print(textDecoder.decode(out));

[res, out] = GLib.spawn_sync(GLib.getenv('HOME'), ['/bin/ls', '-la'], null, 0, null);
if (out) print(byteArray.toString(out));
if (out) print(textDecoder.decode(out));

[res, out] = GLib.spawn_sync(null, ['ls', '-la'], null, GLib.SpawnFlags.SEARCH_PATH, null);
if (out) print(byteArray.toString(out));
if (out) print(textDecoder.decode(out));
2 changes: 1 addition & 1 deletion examples/gjs/glib-2-spawn-command/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"noImplicitThis": true,
"alwaysStrict": true,
},
"include": ["@types/gjs.d.ts", "@types/ambient.d.ts"],
"include": ["@types/gjs.d.ts", "@types/dom.d.ts", "@types/ambient.d.ts"],
"files": [
"main.ts"
]
Expand Down
6 changes: 3 additions & 3 deletions examples/gjs/gtk-3-editor/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ const { gettext } = imports;

Gtk.init(null)

const wnd = new Gtk.Window({ title: 'Editor Test', default_width: 600, default_height: 400 })
const wnd = new Gtk.Window({ title: 'Editor Test', defaultWidth: 600, defaultHeight: 400 })
const box = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0)
const notebook = new Gtk.Notebook({})
const srcView = new GtkSource.View()

srcView.auto_indent = true
srcView.show_line_numbers = true
srcView.autoIndent = true
srcView.showLineNumbers = true
srcView.monospace = true

const buf = srcView.buffer as GtkSource.Buffer;
Expand Down
6 changes: 3 additions & 3 deletions examples/gjs/gtk-3-hello-2/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ Gtk.init(null);
let win = new Gtk.Window({
type: Gtk.WindowType.TOPLEVEL,
title: 'A default title',
default_width: 300,
default_height: 250,
defaultWidth: 300,
defaultHeight: 250,
// A decent example of how constants are mapped:
// 'Gtk' and 'WindowPosition' from the enum name GtkWindowPosition,
// 'CENTER' from the enum's constant GTK_WIN_POS_CENTER
window_position: Gtk.WindowPosition.CENTER,
windowPosition: Gtk.WindowPosition.CENTER,
});

// Object properties can also be set or changed after construction, unless they
Expand Down
6 changes: 3 additions & 3 deletions examples/gjs/gtk-3-hello/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ if (!settings) {
throw new Error('Can\t load default settings!')
}

settings.gtk_application_prefer_dark_theme = true
settings.gtk_theme_name = 'Adwaita'
settings.gtkApplicationPreferDarkTheme = true
settings.gtkThemeName = 'Adwaita'

print(settings.gtk_enable_accels)
print(settings.gtkEnableAccels)

const win = new Gtk.Window()
win.set_title('gjs-gtk')
Expand Down
File renamed without changes.
Loading

0 comments on commit cbb375c

Please sign in to comment.