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
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

More Related Content

What's hot

Docker 101 - from 0 to Docker in 30 minutes
Docker 101 - from 0 to Docker in 30 minutesDocker 101 - from 0 to Docker in 30 minutes
Docker 101 - from 0 to Docker in 30 minutes
Luciano Fiandesio
 
Docker Introduction
Docker IntroductionDocker Introduction
Docker Introduction
Peng Xiao
 
Docker 101: Introduction to Docker
Docker 101: Introduction to DockerDocker 101: Introduction to Docker
Docker 101: Introduction to Docker
Docker, Inc.
 
Intro to Node.js (v1)
Intro to Node.js (v1)Intro to Node.js (v1)
Intro to Node.js (v1)
Chris Cowan
 
Maven Nexus
Maven NexusMaven Nexus
Maven Nexus
ericndunn
 
Thick client pentesting_the-hackers_meetup_version1.0pptx
Thick client pentesting_the-hackers_meetup_version1.0pptxThick client pentesting_the-hackers_meetup_version1.0pptx
Thick client pentesting_the-hackers_meetup_version1.0pptx
Anurag Srivastava
 
Spring Boot
Spring BootSpring Boot
Spring Boot
HongSeong Jeon
 
Pipeline Devops - Intégration continue : ansible, jenkins, docker, jmeter...
Pipeline Devops - Intégration continue : ansible, jenkins, docker, jmeter...Pipeline Devops - Intégration continue : ansible, jenkins, docker, jmeter...
Pipeline Devops - Intégration continue : ansible, jenkins, docker, jmeter...
XavierPestel
 
Docker: From Zero to Hero
Docker: From Zero to HeroDocker: From Zero to Hero
Docker: From Zero to Hero
fazalraja
 
AEM hacker - approaching Adobe Experience Manager webapps in bug bounty programs
AEM hacker - approaching Adobe Experience Manager webapps in bug bounty programsAEM hacker - approaching Adobe Experience Manager webapps in bug bounty programs
AEM hacker - approaching Adobe Experience Manager webapps in bug bounty programs
Mikhail Egorov
 
SSRF workshop
SSRF workshop SSRF workshop
SSRF workshop
Ivan Novikov
 
Jenkins
JenkinsJenkins
OWASP Top 10 2021 Presentation (Jul 2022)
OWASP Top 10 2021 Presentation (Jul 2022)OWASP Top 10 2021 Presentation (Jul 2022)
OWASP Top 10 2021 Presentation (Jul 2022)
TzahiArabov
 
A story of the passive aggressive sysadmin of AEM
A story of the passive aggressive sysadmin of AEMA story of the passive aggressive sysadmin of AEM
A story of the passive aggressive sysadmin of AEM
Frans Rosén
 
Cross site scripting XSS
Cross site scripting XSSCross site scripting XSS
Cross site scripting XSS
Ronan Dunne, CEH, SSCP
 
What is Docker Architecture | Edureka
What is Docker Architecture | EdurekaWhat is Docker Architecture | Edureka
What is Docker Architecture | Edureka
Edureka!
 
Developer's Guide to JavaScript and Web Cryptography
Developer's Guide to JavaScript and Web CryptographyDeveloper's Guide to JavaScript and Web Cryptography
Developer's Guide to JavaScript and Web Cryptography
Kevin Hakanson
 
Spring Boot
Spring BootSpring Boot
Spring Boot
koppenolski
 
Second Level Cache in JPA Explained
Second Level Cache in JPA ExplainedSecond Level Cache in JPA Explained
Second Level Cache in JPA Explained
Patrycja Wegrzynowicz
 
Defying Logic - Business Logic Testing with Automation
Defying Logic - Business Logic Testing with AutomationDefying Logic - Business Logic Testing with Automation
Defying Logic - Business Logic Testing with Automation
Rafal Los
 

What's hot (20)

Docker 101 - from 0 to Docker in 30 minutes
Docker 101 - from 0 to Docker in 30 minutesDocker 101 - from 0 to Docker in 30 minutes
Docker 101 - from 0 to Docker in 30 minutes
 
Docker Introduction
Docker IntroductionDocker Introduction
Docker Introduction
 
Docker 101: Introduction to Docker
Docker 101: Introduction to DockerDocker 101: Introduction to Docker
Docker 101: Introduction to Docker
 
Intro to Node.js (v1)
Intro to Node.js (v1)Intro to Node.js (v1)
Intro to Node.js (v1)
 
Maven Nexus
Maven NexusMaven Nexus
Maven Nexus
 
Thick client pentesting_the-hackers_meetup_version1.0pptx
Thick client pentesting_the-hackers_meetup_version1.0pptxThick client pentesting_the-hackers_meetup_version1.0pptx
Thick client pentesting_the-hackers_meetup_version1.0pptx
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Pipeline Devops - Intégration continue : ansible, jenkins, docker, jmeter...
Pipeline Devops - Intégration continue : ansible, jenkins, docker, jmeter...Pipeline Devops - Intégration continue : ansible, jenkins, docker, jmeter...
Pipeline Devops - Intégration continue : ansible, jenkins, docker, jmeter...
 
Docker: From Zero to Hero
Docker: From Zero to HeroDocker: From Zero to Hero
Docker: From Zero to Hero
 
AEM hacker - approaching Adobe Experience Manager webapps in bug bounty programs
AEM hacker - approaching Adobe Experience Manager webapps in bug bounty programsAEM hacker - approaching Adobe Experience Manager webapps in bug bounty programs
AEM hacker - approaching Adobe Experience Manager webapps in bug bounty programs
 
SSRF workshop
SSRF workshop SSRF workshop
SSRF workshop
 
Jenkins
JenkinsJenkins
Jenkins
 
OWASP Top 10 2021 Presentation (Jul 2022)
OWASP Top 10 2021 Presentation (Jul 2022)OWASP Top 10 2021 Presentation (Jul 2022)
OWASP Top 10 2021 Presentation (Jul 2022)
 
A story of the passive aggressive sysadmin of AEM
A story of the passive aggressive sysadmin of AEMA story of the passive aggressive sysadmin of AEM
A story of the passive aggressive sysadmin of AEM
 
Cross site scripting XSS
Cross site scripting XSSCross site scripting XSS
Cross site scripting XSS
 
What is Docker Architecture | Edureka
What is Docker Architecture | EdurekaWhat is Docker Architecture | Edureka
What is Docker Architecture | Edureka
 
Developer's Guide to JavaScript and Web Cryptography
Developer's Guide to JavaScript and Web CryptographyDeveloper's Guide to JavaScript and Web Cryptography
Developer's Guide to JavaScript and Web Cryptography
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Second Level Cache in JPA Explained
Second Level Cache in JPA ExplainedSecond Level Cache in JPA Explained
Second Level Cache in JPA Explained
 
Defying Logic - Business Logic Testing with Automation
Defying Logic - Business Logic Testing with AutomationDefying Logic - Business Logic Testing with Automation
Defying Logic - Business Logic Testing with Automation
 

Similar to Writing native Linux desktop apps with JavaScript

Flutter vs Java Graphical User Interface Frameworks - text
Flutter vs Java Graphical User Interface Frameworks - textFlutter vs Java Graphical User Interface Frameworks - text
Flutter vs Java Graphical User Interface Frameworks - text
Toma Velev
 
3 Ways to Get Started with a React App in 2024.pdf
3 Ways to Get Started with a React App in 2024.pdf3 Ways to Get Started with a React App in 2024.pdf
3 Ways to Get Started with a React App in 2024.pdf
BOSC Tech Labs
 
Node JS Express : Steps to Create Restful Web App
Node JS Express : Steps to Create Restful Web AppNode JS Express : Steps to Create Restful Web App
Node JS Express : Steps to Create Restful Web App
Edureka!
 
Confoo - Javascript Server Side : How to start
Confoo - Javascript Server Side : How to startConfoo - Javascript Server Side : How to start
Confoo - Javascript Server Side : How to start
Quentin Adam
 
Powerful tools for building web solutions
Powerful tools for building web solutionsPowerful tools for building web solutions
Powerful tools for building web solutions
Andrea Tino
 
Javascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
Javascript Frameworks Comparison - Angular, Knockout, Ember and BackboneJavascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
Javascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
Deepu S Nath
 
Desktop apps with node webkit
Desktop apps with node webkitDesktop apps with node webkit
Desktop apps with node webkit
Paul Jensen
 
Plug yourself in and your app will never be the same (1 hr edition)
Plug yourself in and your app will never be the same (1 hr edition)Plug yourself in and your app will never be the same (1 hr edition)
Plug yourself in and your app will never be the same (1 hr edition)
Mikkel Flindt Heisterberg
 
Designing A Project Using Java Programming
Designing A Project Using Java ProgrammingDesigning A Project Using Java Programming
Designing A Project Using Java Programming
Katy Allen
 
Fewd week4 slides
Fewd week4 slidesFewd week4 slides
Fewd week4 slides
William Myers
 
Javascript Frameworks Comparison
Javascript Frameworks ComparisonJavascript Frameworks Comparison
Javascript Frameworks Comparison
Deepu S Nath
 
WebGL: GPU acceleration for the open web
WebGL: GPU acceleration for the open webWebGL: GPU acceleration for the open web
WebGL: GPU acceleration for the open web
pjcozzi
 
Introduction to Google App Engine with Python
Introduction to Google App Engine with PythonIntroduction to Google App Engine with Python
Introduction to Google App Engine with Python
Brian Lyttle
 
Plug-in Architectures
Plug-in ArchitecturesPlug-in Architectures
Plug-in Architectures
elliando dias
 
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
Paul Jensen
 
Plug yourself in and your app will never be the same (2 hour edition)
Plug yourself in and your app will never be the same (2 hour edition)Plug yourself in and your app will never be the same (2 hour edition)
Plug yourself in and your app will never be the same (2 hour edition)
Mikkel Flindt Heisterberg
 
Plug yourself in and your app will never be the same (2 hr editon)
Plug yourself in and your app will never be the same (2 hr editon)Plug yourself in and your app will never be the same (2 hr editon)
Plug yourself in and your app will never be the same (2 hr editon)
Mikkel Flindt Heisterberg
 
Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]
GDSC UofT Mississauga
 
Dot Net Fundamentals
Dot Net FundamentalsDot Net Fundamentals
Dot Net Fundamentals
LiquidHub
 
Why Gradle?
Why Gradle?Why Gradle?
Why Gradle?
Peter Ledbrook
 

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

Flutter vs Java Graphical User Interface Frameworks - text
Flutter vs Java Graphical User Interface Frameworks - textFlutter vs Java Graphical User Interface Frameworks - text
Flutter vs Java Graphical User Interface Frameworks - text
 
3 Ways to Get Started with a React App in 2024.pdf
3 Ways to Get Started with a React App in 2024.pdf3 Ways to Get Started with a React App in 2024.pdf
3 Ways to Get Started with a React App in 2024.pdf
 
Node JS Express : Steps to Create Restful Web App
Node JS Express : Steps to Create Restful Web AppNode JS Express : Steps to Create Restful Web App
Node JS Express : Steps to Create Restful Web App
 
Confoo - Javascript Server Side : How to start
Confoo - Javascript Server Side : How to startConfoo - Javascript Server Side : How to start
Confoo - Javascript Server Side : How to start
 
Powerful tools for building web solutions
Powerful tools for building web solutionsPowerful tools for building web solutions
Powerful tools for building web solutions
 
Javascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
Javascript Frameworks Comparison - Angular, Knockout, Ember and BackboneJavascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
Javascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
 
Desktop apps with node webkit
Desktop apps with node webkitDesktop apps with node webkit
Desktop apps with node webkit
 
Plug yourself in and your app will never be the same (1 hr edition)
Plug yourself in and your app will never be the same (1 hr edition)Plug yourself in and your app will never be the same (1 hr edition)
Plug yourself in and your app will never be the same (1 hr edition)
 
Designing A Project Using Java Programming
Designing A Project Using Java ProgrammingDesigning A Project Using Java Programming
Designing A Project Using Java Programming
 
Fewd week4 slides
Fewd week4 slidesFewd week4 slides
Fewd week4 slides
 
Javascript Frameworks Comparison
Javascript Frameworks ComparisonJavascript Frameworks Comparison
Javascript Frameworks Comparison
 
WebGL: GPU acceleration for the open web
WebGL: GPU acceleration for the open webWebGL: GPU acceleration for the open web
WebGL: GPU acceleration for the open web
 
Introduction to Google App Engine with Python
Introduction to Google App Engine with PythonIntroduction to Google App Engine with Python
Introduction to Google App Engine with Python
 
Plug-in Architectures
Plug-in ArchitecturesPlug-in Architectures
Plug-in Architectures
 
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
 
Plug yourself in and your app will never be the same (2 hour edition)
Plug yourself in and your app will never be the same (2 hour edition)Plug yourself in and your app will never be the same (2 hour edition)
Plug yourself in and your app will never be the same (2 hour edition)
 
Plug yourself in and your app will never be the same (2 hr editon)
Plug yourself in and your app will never be the same (2 hr editon)Plug yourself in and your app will never be the same (2 hr editon)
Plug yourself in and your app will never be the same (2 hr editon)
 
Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]
 
Dot Net Fundamentals
Dot Net FundamentalsDot Net Fundamentals
Dot Net Fundamentals
 
Why Gradle?
Why Gradle?Why Gradle?
Why Gradle?
 

More from Igalia

The journey towards stabilizing Chromium’s Wayland support
The journey towards stabilizing Chromium’s Wayland supportThe journey towards stabilizing Chromium’s Wayland support
The journey towards stabilizing Chromium’s Wayland support
Igalia
 
Sustainable Futures: Funding the Web Ecosystem
Sustainable Futures: Funding the Web EcosystemSustainable Futures: Funding the Web Ecosystem
Sustainable Futures: Funding the Web Ecosystem
Igalia
 
Status of the Layer-Based SVG Engine in WebKit
Status of the Layer-Based SVG Engine in WebKitStatus of the Layer-Based SVG Engine in WebKit
Status of the Layer-Based SVG Engine in WebKit
Igalia
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
Igalia
 
Building End-user Applications on Embedded Devices with WPE
Building End-user Applications on Embedded Devices with WPEBuilding End-user Applications on Embedded Devices with WPE
Building End-user Applications on Embedded Devices with WPE
Igalia
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Igalia
 
Automated Testing for Web-based Systems on Embedded Devices
Automated Testing for Web-based Systems on Embedded DevicesAutomated Testing for Web-based Systems on Embedded Devices
Automated Testing for Web-based Systems on Embedded Devices
Igalia
 
Embedding WPE WebKit - from Bring-up to Maintenance
Embedding WPE WebKit - from Bring-up to MaintenanceEmbedding WPE WebKit - from Bring-up to Maintenance
Embedding WPE WebKit - from Bring-up to Maintenance
Igalia
 
Optimizing Scheduler for Linux Gaming.pdf
Optimizing Scheduler for Linux Gaming.pdfOptimizing Scheduler for Linux Gaming.pdf
Optimizing Scheduler for Linux Gaming.pdf
Igalia
 
Running JS via WASM faster with JIT
Running JS via WASM      faster with JITRunning JS via WASM      faster with JIT
Running JS via WASM faster with JIT
Igalia
 
To crash or not to crash: if you do, at least recover fast!
To crash or not to crash: if you do, at least recover fast!To crash or not to crash: if you do, at least recover fast!
To crash or not to crash: if you do, at least recover fast!
Igalia
 
Implementing a Vulkan Video Encoder From Mesa to GStreamer
Implementing a Vulkan Video Encoder From Mesa to GStreamerImplementing a Vulkan Video Encoder From Mesa to GStreamer
Implementing a Vulkan Video Encoder From Mesa to GStreamer
Igalia
 
8 Years of Open Drivers, including the State of Vulkan in Mesa
8 Years of Open Drivers, including the State of Vulkan in Mesa8 Years of Open Drivers, including the State of Vulkan in Mesa
8 Years of Open Drivers, including the State of Vulkan in Mesa
Igalia
 
Introducción a Mesa. Caso específico dos dispositivos Raspberry Pi por Igalia
Introducción a Mesa. Caso específico dos dispositivos Raspberry Pi por IgaliaIntroducción a Mesa. Caso específico dos dispositivos Raspberry Pi por Igalia
Introducción a Mesa. Caso específico dos dispositivos Raspberry Pi por Igalia
Igalia
 
2023 in Chimera Linux
2023 in Chimera                    Linux2023 in Chimera                    Linux
2023 in Chimera Linux
Igalia
 
Building a Linux distro with LLVM
Building a Linux distro        with LLVMBuilding a Linux distro        with LLVM
Building a Linux distro with LLVM
Igalia
 
turnip: Update on Open Source Vulkan Driver for Adreno GPUs
turnip: Update on Open Source Vulkan Driver for Adreno GPUsturnip: Update on Open Source Vulkan Driver for Adreno GPUs
turnip: Update on Open Source Vulkan Driver for Adreno GPUs
Igalia
 
Graphics stack updates for Raspberry Pi devices
Graphics stack updates for Raspberry Pi devicesGraphics stack updates for Raspberry Pi devices
Graphics stack updates for Raspberry Pi devices
Igalia
 
Delegated Compositing - Utilizing Wayland Protocols for Chromium on ChromeOS
Delegated Compositing - Utilizing Wayland Protocols for Chromium on ChromeOSDelegated Compositing - Utilizing Wayland Protocols for Chromium on ChromeOS
Delegated Compositing - Utilizing Wayland Protocols for Chromium on ChromeOS
Igalia
 
MessageFormat: The future of i18n on the web
MessageFormat: The future of i18n on the webMessageFormat: The future of i18n on the web
MessageFormat: The future of i18n on the web
Igalia
 

More from Igalia (20)

The journey towards stabilizing Chromium’s Wayland support
The journey towards stabilizing Chromium’s Wayland supportThe journey towards stabilizing Chromium’s Wayland support
The journey towards stabilizing Chromium’s Wayland support
 
Sustainable Futures: Funding the Web Ecosystem
Sustainable Futures: Funding the Web EcosystemSustainable Futures: Funding the Web Ecosystem
Sustainable Futures: Funding the Web Ecosystem
 
Status of the Layer-Based SVG Engine in WebKit
Status of the Layer-Based SVG Engine in WebKitStatus of the Layer-Based SVG Engine in WebKit
Status of the Layer-Based SVG Engine in WebKit
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Building End-user Applications on Embedded Devices with WPE
Building End-user Applications on Embedded Devices with WPEBuilding End-user Applications on Embedded Devices with WPE
Building End-user Applications on Embedded Devices with WPE
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Automated Testing for Web-based Systems on Embedded Devices
Automated Testing for Web-based Systems on Embedded DevicesAutomated Testing for Web-based Systems on Embedded Devices
Automated Testing for Web-based Systems on Embedded Devices
 
Embedding WPE WebKit - from Bring-up to Maintenance
Embedding WPE WebKit - from Bring-up to MaintenanceEmbedding WPE WebKit - from Bring-up to Maintenance
Embedding WPE WebKit - from Bring-up to Maintenance
 
Optimizing Scheduler for Linux Gaming.pdf
Optimizing Scheduler for Linux Gaming.pdfOptimizing Scheduler for Linux Gaming.pdf
Optimizing Scheduler for Linux Gaming.pdf
 
Running JS via WASM faster with JIT
Running JS via WASM      faster with JITRunning JS via WASM      faster with JIT
Running JS via WASM faster with JIT
 
To crash or not to crash: if you do, at least recover fast!
To crash or not to crash: if you do, at least recover fast!To crash or not to crash: if you do, at least recover fast!
To crash or not to crash: if you do, at least recover fast!
 
Implementing a Vulkan Video Encoder From Mesa to GStreamer
Implementing a Vulkan Video Encoder From Mesa to GStreamerImplementing a Vulkan Video Encoder From Mesa to GStreamer
Implementing a Vulkan Video Encoder From Mesa to GStreamer
 
8 Years of Open Drivers, including the State of Vulkan in Mesa
8 Years of Open Drivers, including the State of Vulkan in Mesa8 Years of Open Drivers, including the State of Vulkan in Mesa
8 Years of Open Drivers, including the State of Vulkan in Mesa
 
Introducción a Mesa. Caso específico dos dispositivos Raspberry Pi por Igalia
Introducción a Mesa. Caso específico dos dispositivos Raspberry Pi por IgaliaIntroducción a Mesa. Caso específico dos dispositivos Raspberry Pi por Igalia
Introducción a Mesa. Caso específico dos dispositivos Raspberry Pi por Igalia
 
2023 in Chimera Linux
2023 in Chimera                    Linux2023 in Chimera                    Linux
2023 in Chimera Linux
 
Building a Linux distro with LLVM
Building a Linux distro        with LLVMBuilding a Linux distro        with LLVM
Building a Linux distro with LLVM
 
turnip: Update on Open Source Vulkan Driver for Adreno GPUs
turnip: Update on Open Source Vulkan Driver for Adreno GPUsturnip: Update on Open Source Vulkan Driver for Adreno GPUs
turnip: Update on Open Source Vulkan Driver for Adreno GPUs
 
Graphics stack updates for Raspberry Pi devices
Graphics stack updates for Raspberry Pi devicesGraphics stack updates for Raspberry Pi devices
Graphics stack updates for Raspberry Pi devices
 
Delegated Compositing - Utilizing Wayland Protocols for Chromium on ChromeOS
Delegated Compositing - Utilizing Wayland Protocols for Chromium on ChromeOSDelegated Compositing - Utilizing Wayland Protocols for Chromium on ChromeOS
Delegated Compositing - Utilizing Wayland Protocols for Chromium on ChromeOS
 
MessageFormat: The future of i18n on the web
MessageFormat: The future of i18n on the webMessageFormat: The future of i18n on the web
MessageFormat: The future of i18n on the web
 

Recently uploaded

HijackLoader Evolution: Interactive Process Hollowing
HijackLoader Evolution: Interactive Process HollowingHijackLoader Evolution: Interactive Process Hollowing
HijackLoader Evolution: Interactive Process Hollowing
Donato Onofri
 
How to make a complaint to the police for Social Media Fraud.pdf
How to make a complaint to the police for Social Media Fraud.pdfHow to make a complaint to the police for Social Media Fraud.pdf
How to make a complaint to the police for Social Media Fraud.pdf
Infosec train
 
cyber crime.pptx..........................
cyber crime.pptx..........................cyber crime.pptx..........................
cyber crime.pptx..........................
GNAMBIKARAO
 
Honeypots Unveiled: Proactive Defense Tactics for Cyber Security, Phoenix Sum...
Honeypots Unveiled: Proactive Defense Tactics for Cyber Security, Phoenix Sum...Honeypots Unveiled: Proactive Defense Tactics for Cyber Security, Phoenix Sum...
Honeypots Unveiled: Proactive Defense Tactics for Cyber Security, Phoenix Sum...
APNIC
 
Securing BGP: Operational Strategies and Best Practices for Network Defenders...
Securing BGP: Operational Strategies and Best Practices for Network Defenders...Securing BGP: Operational Strategies and Best Practices for Network Defenders...
Securing BGP: Operational Strategies and Best Practices for Network Defenders...
APNIC
 
一比一原版(uc毕业证书)加拿大卡尔加里大学毕业证如何办理
一比一原版(uc毕业证书)加拿大卡尔加里大学毕业证如何办理一比一原版(uc毕业证书)加拿大卡尔加里大学毕业证如何办理
一比一原版(uc毕业证书)加拿大卡尔加里大学毕业证如何办理
dtagbe
 
快速办理(新加坡SMU毕业证书)新加坡管理大学毕业证文凭证书一模一样
快速办理(新加坡SMU毕业证书)新加坡管理大学毕业证文凭证书一模一样快速办理(新加坡SMU毕业证书)新加坡管理大学毕业证文凭证书一模一样
快速办理(新加坡SMU毕业证书)新加坡管理大学毕业证文凭证书一模一样
3a0sd7z3
 
一比一原版新西兰林肯大学毕业证(Lincoln毕业证书)学历如何办理
一比一原版新西兰林肯大学毕业证(Lincoln毕业证书)学历如何办理一比一原版新西兰林肯大学毕业证(Lincoln毕业证书)学历如何办理
一比一原版新西兰林肯大学毕业证(Lincoln毕业证书)学历如何办理
thezot
 
快速办理(Vic毕业证书)惠灵顿维多利亚大学毕业证完成信一模一样
快速办理(Vic毕业证书)惠灵顿维多利亚大学毕业证完成信一模一样快速办理(Vic毕业证书)惠灵顿维多利亚大学毕业证完成信一模一样
快速办理(Vic毕业证书)惠灵顿维多利亚大学毕业证完成信一模一样
3a0sd7z3
 
怎么办理(umiami毕业证书)美国迈阿密大学毕业证文凭证书实拍图原版一模一样
怎么办理(umiami毕业证书)美国迈阿密大学毕业证文凭证书实拍图原版一模一样怎么办理(umiami毕业证书)美国迈阿密大学毕业证文凭证书实拍图原版一模一样
怎么办理(umiami毕业证书)美国迈阿密大学毕业证文凭证书实拍图原版一模一样
rtunex8r
 
Bengaluru Dreamin' 24 - Personal Branding
Bengaluru Dreamin' 24 - Personal BrandingBengaluru Dreamin' 24 - Personal Branding
Bengaluru Dreamin' 24 - Personal Branding
Tarandeep Singh
 

Recently uploaded (11)

HijackLoader Evolution: Interactive Process Hollowing
HijackLoader Evolution: Interactive Process HollowingHijackLoader Evolution: Interactive Process Hollowing
HijackLoader Evolution: Interactive Process Hollowing
 
How to make a complaint to the police for Social Media Fraud.pdf
How to make a complaint to the police for Social Media Fraud.pdfHow to make a complaint to the police for Social Media Fraud.pdf
How to make a complaint to the police for Social Media Fraud.pdf
 
cyber crime.pptx..........................
cyber crime.pptx..........................cyber crime.pptx..........................
cyber crime.pptx..........................
 
Honeypots Unveiled: Proactive Defense Tactics for Cyber Security, Phoenix Sum...
Honeypots Unveiled: Proactive Defense Tactics for Cyber Security, Phoenix Sum...Honeypots Unveiled: Proactive Defense Tactics for Cyber Security, Phoenix Sum...
Honeypots Unveiled: Proactive Defense Tactics for Cyber Security, Phoenix Sum...
 
Securing BGP: Operational Strategies and Best Practices for Network Defenders...
Securing BGP: Operational Strategies and Best Practices for Network Defenders...Securing BGP: Operational Strategies and Best Practices for Network Defenders...
Securing BGP: Operational Strategies and Best Practices for Network Defenders...
 
一比一原版(uc毕业证书)加拿大卡尔加里大学毕业证如何办理
一比一原版(uc毕业证书)加拿大卡尔加里大学毕业证如何办理一比一原版(uc毕业证书)加拿大卡尔加里大学毕业证如何办理
一比一原版(uc毕业证书)加拿大卡尔加里大学毕业证如何办理
 
快速办理(新加坡SMU毕业证书)新加坡管理大学毕业证文凭证书一模一样
快速办理(新加坡SMU毕业证书)新加坡管理大学毕业证文凭证书一模一样快速办理(新加坡SMU毕业证书)新加坡管理大学毕业证文凭证书一模一样
快速办理(新加坡SMU毕业证书)新加坡管理大学毕业证文凭证书一模一样
 
一比一原版新西兰林肯大学毕业证(Lincoln毕业证书)学历如何办理
一比一原版新西兰林肯大学毕业证(Lincoln毕业证书)学历如何办理一比一原版新西兰林肯大学毕业证(Lincoln毕业证书)学历如何办理
一比一原版新西兰林肯大学毕业证(Lincoln毕业证书)学历如何办理
 
快速办理(Vic毕业证书)惠灵顿维多利亚大学毕业证完成信一模一样
快速办理(Vic毕业证书)惠灵顿维多利亚大学毕业证完成信一模一样快速办理(Vic毕业证书)惠灵顿维多利亚大学毕业证完成信一模一样
快速办理(Vic毕业证书)惠灵顿维多利亚大学毕业证完成信一模一样
 
怎么办理(umiami毕业证书)美国迈阿密大学毕业证文凭证书实拍图原版一模一样
怎么办理(umiami毕业证书)美国迈阿密大学毕业证文凭证书实拍图原版一模一样怎么办理(umiami毕业证书)美国迈阿密大学毕业证文凭证书实拍图原版一模一样
怎么办理(umiami毕业证书)美国迈阿密大学毕业证文凭证书实拍图原版一模一样
 
Bengaluru Dreamin' 24 - Personal Branding
Bengaluru Dreamin' 24 - Personal BrandingBengaluru Dreamin' 24 - Personal Branding
Bengaluru Dreamin' 24 - Personal Branding
 

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
  • 35.
  • 36.
  • 37.
  • 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