• Stars
    star
    494
  • Rank 89,130 (Top 2 %)
  • Language
    C++
  • License
    MIT License
  • Created almost 9 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

GTK+ bindings for NodeJS (via GObject introspection)

NODE-GTK

node-gtk

GNOME Gtk+ bindings for NodeJS
Package Version

Node-Gtk is a gobject-introspection library for nodejs. It makes it possible to use any introspected library, such as Gtk+, usable. It is similar in essence to GJS or PyGObject. Please note this project is currently in a beta state and is being developed. Any contributors willing to help will be welcomed.

Supported Node.js versions: 16, 18 (other versions should work but are untested)
Pre-built binaries available for: Linux, macOS (all supported versions except 18)

Table of contents

Usage

Below is a minimal example of how to use the code, but take a look at our template or at react-gtk to bootstrap your project.

const gi = require('node-gtk')
const Gtk = gi.require('Gtk', '3.0')

gi.startLoop()
Gtk.init()

const win = new Gtk.Window()
win.on('destroy', () => Gtk.mainQuit())
win.on('delete-event', () => false)

win.setDefaultSize(200, 80)
win.add(new Gtk.Label({ label: 'Hello Gtk+' }))

win.showAll()
Gtk.main()

Hello Gtk

See our examples folder for more examples, and in particular the browser demo source for a more complex application.

Hello Gtk

Documentation

Read our documentation here

Installing and building

Note that prebuilt binaries are available for common systems, in those cases building is not necessary.

Target Platforms
  • Linux: prebuilt binaries available
  • macOS: prebuilt binaries available
  • Windows: no prebuilt binaries

Requirements

  • git
  • nodejs@10 or higher
  • python3 (for node-gyp)
  • C compiler (gcc@8 or higher, or clang)

How to build on Ubuntu

Install basic dependencies.

sudo apt-get install \
  build-essential git \
  gobject-introspection \
  libgirepository1.0-dev \
  libcairo2 \
  libcairo2-dev

At this point npm install node-gtk should already install, fallback and build node-gtk without problems.

How to build on Fedora

Install basic dependencies:

sudo dnf install \
  @development-tools \
  nodejs \
  gobject-introspection \
  gtk3 \
  cairo

After installing of packages, run npm install node-gtk.

How to build on ArchLinux

The following should be the bare minimum to be able to build the project.

pacman -S --needed \
  base-devel git \
  nodejs npm \
  gtk3 gobject-introspection \
  cairo

Feel free to install all base-devel utilities.

After installing those packages, npm install node-gtk would do.

How to build on macOS

Assuming you have brew installed, the following has been successfully tested on El Captain.

brew install git node gobject-introspection gtk+3 cairo

At this point npm install node-gtk should already install, fallback and build node-gtk without problems.

How to build on Windows

Mandatory dependency is Visual C++ Build Environment: Visual Studio Build Tools (using "Visual C++ build tools" workload) or Visual Studio Community (using the "Desktop development with C++" workload).

The easiest/tested way to build this repository is within a MinGW shell provided by the MSYS2 installer.

Once VS and its C++ compiler is available and MSYS2 installed, launch the MinGW shell.

# update the system
# in case of errors, wait for the update to complete
# then close and open again MingW shell
pacman -Syyu --noconfirm

# install git, gtk3 and extra dependencie
pacman -S --needed --noconfirm git mingw-w64-$(uname -m)-{gtk3,gobject-introspection,pkg-config,cairo}

# where to put the repository clone?
# pick your flder or use ~/oss (Open Source Software)
mkdir -p ~/oss/
cd ~/oss

# clone node-gtk there
git clone https://github.com/romgrk/node-gtk
cd node-gtk

# don't include /mingw64/include directly since it conflicts with
# Windows SDK headers. we copy needed headers to __extra__ directory:
./windows/mingw_include_extra.sh

# if MSYS2 is NOT installed in C:/msys64 run:
export MINGW_WINDOWS_PATH=$(./windows/mingw_windows_path.sh)

# first run might take a while
GYP_MSVS_VERSION=2017 npm install

The GYP_MSVS_VERSION could be 2017 or above. Please verify which version you should use

The below blog post series will help you get started:

  1. Node.js GTK Hello World on Windows
  2. Find DLLs and Typelibs dependencies for Node.js GTK Application on Windows
  3. Package Node.js GTK Application on Windows

Possible issue on MinGW shell

In case you are launching the general executable without knowing the correct platform, the binary path might not be available.

In such case python won't be available either, and you can check via which python command.

If not found, you need to export the platform related binary path:

# example for the 32bit version
export PATH="/mingw32/bin:$PATH"
npm run install

This should do the trick. You can also check if there is any python at all via pacman -Qs python.

Testing the project

If you'd like to test everything builds and work properly, after installing and building you can run any of the examples:

node ./examples/hello-gtk.js

If you'll see a little window saying hello that's it: it works!

Please note in macOS the window doesn't automatically open above other windows. Try Cmd + Tab if you don't see it.

Browser demo

If you'd like to test ./examples/browser.js you'll need WebKit2 GTK+ libary.

  • in Ubuntu, you can apt-get install libwebkit2gtk-3.0 (4.0 works too) and try it out.
  • in Fedora, you should run sudo dnf install webkit2gtk3
  • in ArchLinux, you can pacman -S --needed webkitgtk and try it out.
  • in macOS, there is no way to run it right now because webkitgtk was removed from homebrew

Once installed, you can ./examples/browser.js google.com or any other page, and you might try the dark theme out too:

# macOS needs to have the Adwaita theme installed
# brew install adwaita-icon-theme

# Usage: ./examples/browser.js <url> [theme]
./examples/browser.js  google.com  dark

Contributing

If you'd like to help, we'd be more than happy to have support. To setup your development environment, you can run npm run configure. You can then build the project with npm run build.

Don't hesitate to join our Discord channel.

Contributors

More Repositories

1

barbar.nvim

The neovim tabline plugin.
Lua
2,297
star
2

web-toolkit

A web UI framework based on GTK's Adwaita theme
JavaScript
210
star
3

kui.nvim

UI neovim framework for kitty
C
185
star
4

todoist.nvim

A todoist extension for neovim
JavaScript
164
star
5

kirby.nvim

Fuzzy picker for neovim - using kitty graphics protocol
Lua
144
star
6

fzy-lua-native

Luajit FFI bindings to FZY
Lua
117
star
7

doom-one.vim

A dark colorschme for vim, ported from doom-emacs' doom-one theme.
Vim Script
104
star
8

color-bits

High-performance javascript color library
TypeScript
89
star
9

winteract.vim

Interactive window mode
Vim Script
69
star
10

react-fast-memo

A faster React.memo()
JavaScript
53
star
11

github-light.vim

Github colorscheme for vim
Vim Script
36
star
12

nvim

local rc files - feel free to explore
Vim Script
35
star
13

2d-geometry

Performant & ergonomic 2D geometry in Typescript
TypeScript
35
star
14

termrk

Terminal for atom, using pty.js & term.js
CoffeeScript
33
star
15

xedel

Keyboard-centric modal code editor, built with nodejs and GTK
JavaScript
26
star
16

searchReplace.vim

Search & Replace, simply & efficiently [neovim only]
Vim Script
25
star
17

lister

An experimental Gtk-based fuzzy-finder (with support for neovim)
JavaScript
22
star
18

node-todoist

nodejs implementation of todoist sync API
TypeScript
21
star
19

replace.vim

Replace operator for Vim
Vim Script
20
star
20

react-drop-zone

Simple, elegant & efficient drop-zone component
JavaScript
17
star
21

equal.operator

A text-object for LHS/RHS of assignment.
Vim Script
16
star
22

node-gtk-template

A node-gtk application template
JavaScript
11
star
23

vim-exeline

Execute a command on save
Vim Script
11
star
24

kui-demo.nvim

kui.nvim demo
Lua
9
star
25

pp.vim

pretty-printer with real colors.
Vim Script
8
star
26

pencil

High performance & low bundle size 2D canvas drawing library
TypeScript
8
star
27

solid-base-components

Barely styled components for solidjs.
TypeScript
7
star
28

babel-plugin-fast-jsx

Inline react jsx calls
JavaScript
7
star
29

blog-romgrk

MDX
6
star
30

tree-sitter.vim

JavaScript
5
star
31

node-loompy

Create loompy files with Nodejs
JavaScript
5
star
32

yama-neovim

JavaScript
4
star
33

lib.kom

Vim short#() libraries for scripting - hi#(), win#(), buf#(), color#()
Vim Script
4
star
34

pxm

Long-running background commands runner
TypeScript
3
star
35

kyntell.vim

dark colorscheme
Vim Script
3
star
36

tree-sitter-grain

C
3
star
37

wasm-js

A webassembly javascript interpreter
JavaScript
3
star
38

aoe4-villager-enforcer

Age of Empires IV training tool
Rust
3
star
39

bioinformatics-parser

Simple nodejs fasta/fastq parser
JavaScript
2
star
40

keykit

npm module for keyevents etc.
CoffeeScript
2
star
41

git-config

JavaScript
1
star
42

node-fzy

Native fzy binding for nodejs
C
1
star
43

pg_fzy

The fzy function for PostgreSQL
C
1
star
44

ol-resources

Functions & examples for OL related stuff
JavaScript
1
star
45

physic_engine

basic java 2D physic simulation engine
Java
1
star
46

columnMove.vim

Move along the vertical axis
Vim Script
1
star
47

pepiniere

Simple PWA that tracks time spent on tasks
JavaScript
1
star
48

zsh

Shell
1
star
49

sqlite-objects

Usable wrappers around SQLite
JavaScript
1
star
50

coffee-nvim

coffeescript host & lib for scripting neovim
CoffeeScript
1
star
51

cv-generator

TypeScript
1
star
52

js-benchmark

JavaScript
1
star
53

edcc

JavaScript
1
star
54

dotfiles

Shell
1
star