SlideShare a Scribd company logo
Writing native Linux desktop apps with JavaScript
Philip Chimento •   ptomato •  @therealptomato
Linux Application Summit, May 13, 2021
Image by Сергей Корчанов from Pixabay
Introduction
I maintain GJS (GNOME JavaScript)
This talk is a bit of an experiment for me
Can web JS programmers ramp up quickly on writing a desktop app?
What this talk is
For JavaScript developers and enthusiasts
who are curious about writing a desktop app
A walk through creating and publishing a desktop app in JS
Technologies: GJS, GTK, Flatpak, Flathub
A slide deck that you can read later
https://ptomato.name/talks/las2021/
What this talk is not
A step-by-step tutorial on how to write an app
There's already a good one on gjs.guide
Presented by an experienced web developer
Let's get started!
Image CC0 licensed
App: "Bloatpad"
the unnecessary note-taking app
Have something to start with
Can also use gtk-js-app
a Meson build system
a placeholder icon
resource bundles
a .desktop file
a settings schema
an AppStream meta info file
infrastructure for i18n
skeleton code
a Flatpak manifest
Build systems
Meson is probably a good one to stick with
You will need it if your app ever includes any C code
Coming from JS development you still might want something more familiar
$ yarn init
"scripts": {
"prebuild": "test -d _build || meson _build",
"build": "ninja -C _build",
"start": "meson compile -C _build devel",
"test": "meson test -C _build"
}
Yarn
$ yarn build
$ yarn start
Linter
May as well install prettier and never again worry about code style
eslint for usage
$ yarn add --dev prettier eslint eslint-config-prettier
"lint": "eslint . --fix && prettier --write ."
TypeScript
You can write in TypeScript, it mostly works
Or write JS with type annotations in comments and use TypeScript to typecheck
Thanks to the hard work of Evan Welsh
Other build tools
Bundlers are probably not needed
Tree shaking can be useful
use e.g. find-unused-exports
Minifiers are probably not needed
Babel probably works
Assembling the UI
Photo by Anna Shvets from Pexels
XML UI files or no?
XML-CSS-JS is like the trinity of HTML-CSS-JS
Alternative is to build your UI in code
XML UI files or no?
<object class="GtkListView" id="notesList">
<property name="show-separators">True</property>
<signal name="activate" handler="_onNotesListActivate"/>
</object>
vs.
this._notesList = new Gtk.ListView({ showSeparators: true });
this._notesList.connect("activate", this._onNotesListActivate.bind(this));
XML UI files
Tedious to write by hand
Glade UI Designer
GTK 3 only
GTK 4 alternative underway
Result
CSS
.large-icon {
color: #888a85;
-gtk-icon-shadow: #d3d7cf 1px 1px;
padding-right: 8px;
}
CSS
Time to write code
Image CC0 licensed
API Documentation
gjs-docs.gnome.org
About the API
Every UI element is based on Gtk.Widget
Roughly equivalent to a HTML DOM element
Methods
Properties
Signals (events)
CSS element name and classes
Things that are not UI elements are based on GObject.Object
ES modules
import Gdk from "gi://Gtk";
import Gio from "gi://Gio";
import GObject from "gi://GObject";
import Gtk from "gi://Gtk";
import { NotesListItem } from "./item.js";
Async operations
GNOME platform has asynchronous, cancellable I/O
Experimental opt-in support for JS await
Gio._promisify(Gio.OutputStream.prototype, 'write_bytes_async', 'write_bytes_finish');
// ...
let bytesWritten = 0;
while (bytesWritten < bytes.length) {
bytesWritten = await stream.write_bytes_async(bytes, priority, cancellable);
bytes = bytes.slice(bytesWritten);
}
Popular runtime libraries
These may or may not work
Check if you actually need the dependency
Use ES module directly if it doesn't have other deps
Some modules ship a browser bundle, this might work
Else, build a UMD bundle with Browserify and vendor it
Build a UMD bundle with browserify
yarn add my-library
mkdir -p src/vendor
npx browserify -r my-library -s myLibrary -o src/vendor/my-library.js
import './vendor/my-library.js';
// myLibrary is now a global object
Top 5 most used NPM libraries
1. lodash
2. chalk
3. request
4. commander
5. react
Lodash
In some cases not necessary
Use lodash-es if you need lodash
import _ from './vendor/lodash-es/lodash.js';
_.defaults({ 'a': 1 }, { 'a': 3, 'b': 2 });
Chalk
No bundle, so make a Browserified one
Color support detection code is Node-only
Edit bundle, change stdout: false and stderr: false to true
import './vendor/chalk.js';
print(chalk.blue('Hello') + ' World' + chalk.red('!'));
Request
Deprecated
Use Soup instead
const request = require('request');
request('https://ptomato.name', function (error, response, body) {
console.error('error:', error);
console.log('statusCode:', response && response.statusCode);
console.log('body:', body);
});
import Soup from 'gi://Soup';
const session = new Soup.Session();
const msg = new Soup.Message({ method: 'GET', uri: new Soup.URI('https://ptomato.name') });
session.queue_message(msg, (_, {statusCode, responseBody}) => {
log(`statusCode: ${statusCode}`);
log(`body: ${responseBody.data}`);
});
Commander
No bundle, so make a Browserified one
import System from 'system';
import './vendor/commander.js';
const { Command } = commander;
const options = new Command()
.option('-p, --pizza-type <type>', 'flavour of pizza')
.parse(System.programArgs, { from: 'user' })
.opts(); // ^^^^^^^^^^^^
if (options.pizzaType) print(`pizza flavour: ${options.pizzaType}`);
React
Not applicable
P.S. Although it would be cool if React Native worked with GTK
Fast-forward to the written code
(Live demo, but in case that doesn't work out, screenshots follow)
Image CC0 licensed
Writing native Linux desktop apps with JavaScript
Writing native Linux desktop apps with JavaScript
Writing native Linux desktop apps with JavaScript
Distributing your app to
users
Image by acebrand from Pixabay
How?
Flathub
Requirements
Luckily, the generated project skeleton meets all of these
Only need to fill in a few things
AppStream meta info
This file is used to provide the
description that users see on
Flathub
And in their software updater
appplication
Description of file format
AppStream meta info
Generator to get you started
Asks you a few questions
Asks for URLs of screenshots
Flathub guidelines
OARS rating
OARS Generator
Desktop file
Tells how to display your app in the desktop
Description of file format
List of categories
[Desktop Entry]
Name=Bloatpad
Comment=Unnecessary note-taking application
Exec=name.ptomato.Bloatpad
Icon=name.ptomato.Bloatpad
Terminal=false
Type=Application
Categories=Utility;GTK;
StartupNotify=true
Application icon
Tobias Bernard on Designing an Icon for your App
Submit it to Flathub
Instructions here
Translate your UI
Gettext is built-in to the platform
Venerable framework for UI translations
Use a website like Transifex
Recruit volunteer translators
Or translate the UI yourself in whatever languages you speak
Conclusion
Some things might seem familiar to JS developers, others might not
We should reduce the friction for these developers
But not everything from the web or Node.js applies well to the desktop
Questions
Image by IRCat from Pixabay
Thanks
Andy Holmes, Evan Welsh, Sri Ramkrishna for discussions and their work on
improving the GJS developer experience
License
Presentation licensed under Creative Commons BY-NC-ND 4.0
Bloatpad code, permissive MIT license
Ad

Recommended

PPTX
Introduction to WordPress
Harshad Mane
 
PPTX
Back to the Basics - 1 - Introduction to Web Development
Clint LaForest
 
PPTX
Introduction to Web Development
Parvez Mahbub
 
PDF
JavaScript - Chapter 15 - Debugging Techniques
WebStackAcademy
 
PPTX
Web development
Sunil Moolchandani
 
PPT
CSS for Beginners
Amit Kumar Singh
 
PPTX
Google Chrome DevTools features overview
Oleksii Prohonnyi
 
PDF
Hackfest presentation.pptx
Peter Yaworski
 
KEY
HTML presentation for beginners
jeroenvdmeer
 
PDF
Neat tricks to bypass CSRF-protection
Mikhail Egorov
 
PPTX
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
Malla Reddy University
 
PPT
4b use-case analysis
Châu Thanh Chương
 
PDF
Clean Architecture em PHP
Elton Minetto
 
PPTX
MERN PPT
NeerajGupta96647
 
PPTX
Getting started with Next.js - IM Tech Meetup - Oct 2022.pptx
Ilesh Mistry
 
PDF
HTML5: features with examples
Alfredo Torre
 
PPS
Introduction to Bootstrap: Design for Developers
Melvin John
 
PPTX
Basic HTML
Sayan De
 
PPTX
Front End Development | Introduction
JohnTaieb
 
PPTX
C# Async Await
Simplilearn
 
PDF
Wordpress CMS tutorial and guide manual
Ralph Francis Cue
 
PPTX
Sq lite presentation
Prof. Erwin Globio
 
PPTX
Introducing Swagger
Tony Tam
 
PDF
Intro to Wordpress
Nicole C. Engard
 
PPSX
Introduction to css
Evolution Network
 
PPTX
Curso Wordpress - Diseña tu Web en Wordpress
Toni Padrell
 
PPTX
HTML
chinesebilli
 
PPTX
From React to React Native - Things I wish I knew when I started
sparkfabrik
 
PDF
Electron JS | Build cross-platform desktop applications with web technologies
Bethmi Gunasekara
 

More Related Content

What's hot (20)

PDF
Hackfest presentation.pptx
Peter Yaworski
 
KEY
HTML presentation for beginners
jeroenvdmeer
 
PDF
Neat tricks to bypass CSRF-protection
Mikhail Egorov
 
PPTX
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
Malla Reddy University
 
PPT
4b use-case analysis
Châu Thanh Chương
 
PDF
Clean Architecture em PHP
Elton Minetto
 
PPTX
MERN PPT
NeerajGupta96647
 
PPTX
Getting started with Next.js - IM Tech Meetup - Oct 2022.pptx
Ilesh Mistry
 
PDF
HTML5: features with examples
Alfredo Torre
 
PPS
Introduction to Bootstrap: Design for Developers
Melvin John
 
PPTX
Basic HTML
Sayan De
 
PPTX
Front End Development | Introduction
JohnTaieb
 
PPTX
C# Async Await
Simplilearn
 
PDF
Wordpress CMS tutorial and guide manual
Ralph Francis Cue
 
PPTX
Sq lite presentation
Prof. Erwin Globio
 
PPTX
Introducing Swagger
Tony Tam
 
PDF
Intro to Wordpress
Nicole C. Engard
 
PPSX
Introduction to css
Evolution Network
 
PPTX
Curso Wordpress - Diseña tu Web en Wordpress
Toni Padrell
 
PPTX
HTML
chinesebilli
 
Hackfest presentation.pptx
Peter Yaworski
 
HTML presentation for beginners
jeroenvdmeer
 
Neat tricks to bypass CSRF-protection
Mikhail Egorov
 
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
Malla Reddy University
 
4b use-case analysis
Châu Thanh Chương
 
Clean Architecture em PHP
Elton Minetto
 
Getting started with Next.js - IM Tech Meetup - Oct 2022.pptx
Ilesh Mistry
 
HTML5: features with examples
Alfredo Torre
 
Introduction to Bootstrap: Design for Developers
Melvin John
 
Basic HTML
Sayan De
 
Front End Development | Introduction
JohnTaieb
 
C# Async Await
Simplilearn
 
Wordpress CMS tutorial and guide manual
Ralph Francis Cue
 
Sq lite presentation
Prof. Erwin Globio
 
Introducing Swagger
Tony Tam
 
Intro to Wordpress
Nicole C. Engard
 
Introduction to css
Evolution Network
 
Curso Wordpress - Diseña tu Web en Wordpress
Toni Padrell
 

Similar to Writing native Linux desktop apps with JavaScript (20)

PPTX
From React to React Native - Things I wish I knew when I started
sparkfabrik
 
PDF
Electron JS | Build cross-platform desktop applications with web technologies
Bethmi Gunasekara
 
PDF
Cross-Platform Desktop Apps with Electron (CodeStock Edition)
David Neal
 
PPTX
Node.js Web Apps @ ebay scale
Dmytro Semenov
 
PDF
Lesson 02 - React Native Development Environment Setup
University of Catania
 
PDF
Building a Desktop Streaming console with Electron and ReactJS
Emanuele Rampichini
 
PDF
Javascript in linux desktop (ICOS ver.)
Yuren Ju
 
PDF
Multiplatform hybrid development
Darko Kukovec
 
PDF
Matteo Manchi - React Native for multi-platform mobile applications - Codemot...
Codemotion
 
PDF
Building a Desktop Streaming console with Node.js and WebKit
Emanuele Rampichini
 
PDF
Electron
ITCP Community
 
PDF
Introduzione a React Native - Facebook Developer Circle Rome
Matteo Manchi
 
PDF
Cross-platform UI Engines Rendering Performance
Igalia
 
PDF
Building Apps with React Native - Lessons Learned
Alexandra Anghel
 
PPTX
Learn Electron for Web Developers
Kyle Cearley
 
PDF
Javascript, the GNOME way (JSConf EU 2011)
Igalia
 
PDF
Building desktop applications for fun with electron
TMME - TECH MEETUP FOR MYANMAR ENGINEERS IN JP
 
PDF
Lezione 02 React and React Native installation and Configuration
University of Catania
 
PDF
React Native
Craig Jolicoeur
 
PDF
React Native in Production
Seokjun Kim
 
From React to React Native - Things I wish I knew when I started
sparkfabrik
 
Electron JS | Build cross-platform desktop applications with web technologies
Bethmi Gunasekara
 
Cross-Platform Desktop Apps with Electron (CodeStock Edition)
David Neal
 
Node.js Web Apps @ ebay scale
Dmytro Semenov
 
Lesson 02 - React Native Development Environment Setup
University of Catania
 
Building a Desktop Streaming console with Electron and ReactJS
Emanuele Rampichini
 
Javascript in linux desktop (ICOS ver.)
Yuren Ju
 
Multiplatform hybrid development
Darko Kukovec
 
Matteo Manchi - React Native for multi-platform mobile applications - Codemot...
Codemotion
 
Building a Desktop Streaming console with Node.js and WebKit
Emanuele Rampichini
 
Electron
ITCP Community
 
Introduzione a React Native - Facebook Developer Circle Rome
Matteo Manchi
 
Cross-platform UI Engines Rendering Performance
Igalia
 
Building Apps with React Native - Lessons Learned
Alexandra Anghel
 
Learn Electron for Web Developers
Kyle Cearley
 
Javascript, the GNOME way (JSConf EU 2011)
Igalia
 
Building desktop applications for fun with electron
TMME - TECH MEETUP FOR MYANMAR ENGINEERS IN JP
 
Lezione 02 React and React Native installation and Configuration
University of Catania
 
React Native
Craig Jolicoeur
 
React Native in Production
Seokjun Kim
 
Ad

More from Igalia (20)

PDF
Collective Funding, Governance and Prioritiation of Browser Engine Projects
Igalia
 
PDF
Don't let your motivation go, save time with kworkflow
Igalia
 
PDF
Solving the world’s (localization) problems
Igalia
 
PDF
The Whippet Embeddable Garbage Collection Library
Igalia
 
PDF
Nobody asks "How is JavaScript?"
Igalia
 
PDF
Getting more juice out from your Raspberry Pi GPU
Igalia
 
PDF
WebRTC support in WebKitGTK and WPEWebKit with GStreamer: Status update
Igalia
 
PDF
Demystifying Temporal: A Deep Dive into JavaScript New Temporal API
Igalia
 
PDF
CSS :has() Unlimited Power
Igalia
 
PDF
Device-Generated Commands in Vulkan
Igalia
 
PDF
Current state of Lavapipe: Mesa's software renderer for Vulkan
Igalia
 
PDF
Vulkan Video is Open: Application showcase
Igalia
 
PDF
Scheme on WebAssembly: It is happening!
Igalia
 
PDF
EBC - A new backend compiler for etnaviv
Igalia
 
PDF
RISC-V LLVM State of the Union
Igalia
 
PDF
Device-Generated Commands in Vulkan
Igalia
 
PDF
Downstream challenges
Igalia
 
PDF
Using Chrome for Building Apps
Igalia
 
PDF
Sustainable Futures - Funding the Web Ecosystem v2 - fonts.pdf
Igalia
 
PDF
New and upcoming features in the Node.js module loaders
Igalia
 
Collective Funding, Governance and Prioritiation of Browser Engine Projects
Igalia
 
Don't let your motivation go, save time with kworkflow
Igalia
 
Solving the world’s (localization) problems
Igalia
 
The Whippet Embeddable Garbage Collection Library
Igalia
 
Nobody asks "How is JavaScript?"
Igalia
 
Getting more juice out from your Raspberry Pi GPU
Igalia
 
WebRTC support in WebKitGTK and WPEWebKit with GStreamer: Status update
Igalia
 
Demystifying Temporal: A Deep Dive into JavaScript New Temporal API
Igalia
 
CSS :has() Unlimited Power
Igalia
 
Device-Generated Commands in Vulkan
Igalia
 
Current state of Lavapipe: Mesa's software renderer for Vulkan
Igalia
 
Vulkan Video is Open: Application showcase
Igalia
 
Scheme on WebAssembly: It is happening!
Igalia
 
EBC - A new backend compiler for etnaviv
Igalia
 
RISC-V LLVM State of the Union
Igalia
 
Device-Generated Commands in Vulkan
Igalia
 
Downstream challenges
Igalia
 
Using Chrome for Building Apps
Igalia
 
Sustainable Futures - Funding the Web Ecosystem v2 - fonts.pdf
Igalia
 
New and upcoming features in the Node.js module loaders
Igalia
 
Ad

Recently uploaded (20)

PDF
Paper: The World Game (s) Great Redesign.pdf
Steven McGee
 
PDF
ChatGPT A.I. Powered Chatbot and Popularization.pdf
StanleySamson1
 
PPTX
原版澳洲斯文本科技大学毕业证(SUT毕业证书)如何办理
taqyed
 
PPTX
原版一样(ISM毕业证书)德国多特蒙德国际管理学院毕业证多少钱
taqyed
 
PPTX
ChatGPT_and_Its_Uses_Presentationss.pptx
Neha Prakash
 
PDF
Slides: Eco Economic Epochs for The World Game (s) pdf
Steven McGee
 
PPTX
The ARUBA Kind of new Proposal Umum .pptx
andiwarneri
 
PPT
Almos Entirely Correct Mixing with Apps to Voting
gapati2964
 
PPTX
Azure_Landing_Zone_Best_Practices_Visuals.pptx
fredsonbarbosa1
 
PPTX
最新版加拿大奎斯特大学毕业证(QUC毕业证书)原版定制
taqyed
 
PPTX
BitRecover OST to PST Converter Software
antoniogosling01
 
PDF
BroadLink Cloud Service introduction.pdf
DevendraDwivdi1
 
PDF
Clive Dickens RedTech Public Copy - Collaborate or Die
Clive Dickens
 
PDF
Transmission Control Protocol (TCP) and Starlink
APNIC
 
PPTX
IAREUOUSTPIDWHY$)CHARACTERARERWUEEJJSKWNSND
notgachabite123
 
PDF
Global Networking Trends, presented at the India ISP Conclave 2025
APNIC
 
PPTX
原版一样(ANU毕业证书)澳洲澳大利亚国立大学毕业证在线购买
Taqyea
 
PDF
Logging and Automated Alerting Webinar.pdf
ControlCase
 
PDF
B M Mostofa Kamal Al-Azad [Document & Localization Expert]
Mostofa Kamal Al-Azad
 
PPTX
PROCESS FOR CREATION OF BUSINESS PARTNER IN SAP
AhmadAli716831
 
Paper: The World Game (s) Great Redesign.pdf
Steven McGee
 
ChatGPT A.I. Powered Chatbot and Popularization.pdf
StanleySamson1
 
原版澳洲斯文本科技大学毕业证(SUT毕业证书)如何办理
taqyed
 
原版一样(ISM毕业证书)德国多特蒙德国际管理学院毕业证多少钱
taqyed
 
ChatGPT_and_Its_Uses_Presentationss.pptx
Neha Prakash
 
Slides: Eco Economic Epochs for The World Game (s) pdf
Steven McGee
 
The ARUBA Kind of new Proposal Umum .pptx
andiwarneri
 
Almos Entirely Correct Mixing with Apps to Voting
gapati2964
 
Azure_Landing_Zone_Best_Practices_Visuals.pptx
fredsonbarbosa1
 
最新版加拿大奎斯特大学毕业证(QUC毕业证书)原版定制
taqyed
 
BitRecover OST to PST Converter Software
antoniogosling01
 
BroadLink Cloud Service introduction.pdf
DevendraDwivdi1
 
Clive Dickens RedTech Public Copy - Collaborate or Die
Clive Dickens
 
Transmission Control Protocol (TCP) and Starlink
APNIC
 
IAREUOUSTPIDWHY$)CHARACTERARERWUEEJJSKWNSND
notgachabite123
 
Global Networking Trends, presented at the India ISP Conclave 2025
APNIC
 
原版一样(ANU毕业证书)澳洲澳大利亚国立大学毕业证在线购买
Taqyea
 
Logging and Automated Alerting Webinar.pdf
ControlCase
 
B M Mostofa Kamal Al-Azad [Document & Localization Expert]
Mostofa Kamal Al-Azad
 
PROCESS FOR CREATION OF BUSINESS PARTNER IN SAP
AhmadAli716831
 

Writing native Linux desktop apps with JavaScript

  • 1. Writing native Linux desktop apps with JavaScript Philip Chimento •   ptomato •  @therealptomato Linux Application Summit, May 13, 2021 Image by Сергей Корчанов from Pixabay
  • 2. Introduction I maintain GJS (GNOME JavaScript) This talk is a bit of an experiment for me Can web JS programmers ramp up quickly on writing a desktop app?
  • 3. What this talk is For JavaScript developers and enthusiasts who are curious about writing a desktop app A walk through creating and publishing a desktop app in JS Technologies: GJS, GTK, Flatpak, Flathub A slide deck that you can read later https://ptomato.name/talks/las2021/
  • 4. What this talk is not A step-by-step tutorial on how to write an app There's already a good one on gjs.guide Presented by an experienced web developer
  • 7. Have something to start with Can also use gtk-js-app
  • 8. a Meson build system a placeholder icon resource bundles a .desktop file a settings schema an AppStream meta info file infrastructure for i18n skeleton code a Flatpak manifest
  • 9. Build systems Meson is probably a good one to stick with You will need it if your app ever includes any C code Coming from JS development you still might want something more familiar $ yarn init "scripts": { "prebuild": "test -d _build || meson _build", "build": "ninja -C _build", "start": "meson compile -C _build devel", "test": "meson test -C _build" }
  • 10. Yarn $ yarn build $ yarn start
  • 11. Linter May as well install prettier and never again worry about code style eslint for usage $ yarn add --dev prettier eslint eslint-config-prettier "lint": "eslint . --fix && prettier --write ."
  • 12. TypeScript You can write in TypeScript, it mostly works Or write JS with type annotations in comments and use TypeScript to typecheck Thanks to the hard work of Evan Welsh
  • 13. Other build tools Bundlers are probably not needed Tree shaking can be useful use e.g. find-unused-exports Minifiers are probably not needed Babel probably works
  • 14. Assembling the UI Photo by Anna Shvets from Pexels
  • 15. XML UI files or no? XML-CSS-JS is like the trinity of HTML-CSS-JS Alternative is to build your UI in code
  • 16. XML UI files or no? <object class="GtkListView" id="notesList"> <property name="show-separators">True</property> <signal name="activate" handler="_onNotesListActivate"/> </object> vs. this._notesList = new Gtk.ListView({ showSeparators: true }); this._notesList.connect("activate", this._onNotesListActivate.bind(this));
  • 17. XML UI files Tedious to write by hand Glade UI Designer GTK 3 only GTK 4 alternative underway
  • 19. CSS .large-icon { color: #888a85; -gtk-icon-shadow: #d3d7cf 1px 1px; padding-right: 8px; }
  • 20. CSS
  • 21. Time to write code Image CC0 licensed
  • 23. About the API Every UI element is based on Gtk.Widget Roughly equivalent to a HTML DOM element Methods Properties Signals (events) CSS element name and classes Things that are not UI elements are based on GObject.Object
  • 24. ES modules import Gdk from "gi://Gtk"; import Gio from "gi://Gio"; import GObject from "gi://GObject"; import Gtk from "gi://Gtk"; import { NotesListItem } from "./item.js";
  • 25. Async operations GNOME platform has asynchronous, cancellable I/O Experimental opt-in support for JS await Gio._promisify(Gio.OutputStream.prototype, 'write_bytes_async', 'write_bytes_finish'); // ... let bytesWritten = 0; while (bytesWritten < bytes.length) { bytesWritten = await stream.write_bytes_async(bytes, priority, cancellable); bytes = bytes.slice(bytesWritten); }
  • 26. Popular runtime libraries These may or may not work Check if you actually need the dependency Use ES module directly if it doesn't have other deps Some modules ship a browser bundle, this might work Else, build a UMD bundle with Browserify and vendor it
  • 27. Build a UMD bundle with browserify yarn add my-library mkdir -p src/vendor npx browserify -r my-library -s myLibrary -o src/vendor/my-library.js import './vendor/my-library.js'; // myLibrary is now a global object
  • 28. Top 5 most used NPM libraries 1. lodash 2. chalk 3. request 4. commander 5. react
  • 29. Lodash In some cases not necessary Use lodash-es if you need lodash import _ from './vendor/lodash-es/lodash.js'; _.defaults({ 'a': 1 }, { 'a': 3, 'b': 2 });
  • 30. Chalk No bundle, so make a Browserified one Color support detection code is Node-only Edit bundle, change stdout: false and stderr: false to true import './vendor/chalk.js'; print(chalk.blue('Hello') + ' World' + chalk.red('!'));
  • 31. Request Deprecated Use Soup instead const request = require('request'); request('https://ptomato.name', function (error, response, body) { console.error('error:', error); console.log('statusCode:', response && response.statusCode); console.log('body:', body); }); import Soup from 'gi://Soup'; const session = new Soup.Session(); const msg = new Soup.Message({ method: 'GET', uri: new Soup.URI('https://ptomato.name') }); session.queue_message(msg, (_, {statusCode, responseBody}) => { log(`statusCode: ${statusCode}`); log(`body: ${responseBody.data}`); });
  • 32. Commander No bundle, so make a Browserified one import System from 'system'; import './vendor/commander.js'; const { Command } = commander; const options = new Command() .option('-p, --pizza-type <type>', 'flavour of pizza') .parse(System.programArgs, { from: 'user' }) .opts(); // ^^^^^^^^^^^^ if (options.pizzaType) print(`pizza flavour: ${options.pizzaType}`);
  • 33. React Not applicable P.S. Although it would be cool if React Native worked with GTK
  • 34. Fast-forward to the written code (Live demo, but in case that doesn't work out, screenshots follow) Image CC0 licensed
  • 38. Distributing your app to users Image by acebrand from Pixabay
  • 39. How? Flathub Requirements Luckily, the generated project skeleton meets all of these Only need to fill in a few things
  • 40. AppStream meta info This file is used to provide the description that users see on Flathub And in their software updater appplication Description of file format
  • 41. AppStream meta info Generator to get you started Asks you a few questions Asks for URLs of screenshots Flathub guidelines OARS rating OARS Generator
  • 42. Desktop file Tells how to display your app in the desktop Description of file format List of categories [Desktop Entry] Name=Bloatpad Comment=Unnecessary note-taking application Exec=name.ptomato.Bloatpad Icon=name.ptomato.Bloatpad Terminal=false Type=Application Categories=Utility;GTK; StartupNotify=true
  • 43. Application icon Tobias Bernard on Designing an Icon for your App
  • 44. Submit it to Flathub Instructions here
  • 45. Translate your UI Gettext is built-in to the platform Venerable framework for UI translations Use a website like Transifex Recruit volunteer translators Or translate the UI yourself in whatever languages you speak
  • 46. Conclusion Some things might seem familiar to JS developers, others might not We should reduce the friction for these developers But not everything from the web or Node.js applies well to the desktop
  • 47. Questions Image by IRCat from Pixabay
  • 48. Thanks Andy Holmes, Evan Welsh, Sri Ramkrishna for discussions and their work on improving the GJS developer experience License Presentation licensed under Creative Commons BY-NC-ND 4.0 Bloatpad code, permissive MIT license