Skip to content

BraidenPsiuk/pinephone.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pinephone.js (GitHub)

A tiny JavaScript library which provides a consistent API for interacting with Pine64 PinePhone devices.

supported devices

GitHub Repo Stars Module Types Minified File Size License Donations

Features:

Device Information

  • Reading device model name (Is it an OG or Pro PinePhone?)
  • Reading device model version (Which mainboard version is this?)

WiFi / Bluetooth

  • Getting current statuses (Are WiFi/BT currently enabled?)
  • Enable / Disable (Control WiFi/BT radios at software level)

Examples:

Importing the library

Various builds of pinephone.js are now provided. You can import the library in CommonJS or ES module format.

// CommonJS (Classic node.js)
const pinephone = require('pinephone')

// ES Module, importing the entire library
import * as pinephone from 'pinephone'

// ES Module, importing only what's needed (allows tree-shaking)
import { getModelName, getBluetoothStatus } from 'pinephone'

Basic usage example

// Usage example still needed
// See below for other examples

Getting device information

If you just want to know if the device is an OG PinePhone or a Pro, use the following:

console.log( pinephone.getModelName() )
// output -> 'Pine64 PinePhone' OR 'Pine64 PinePhonePro'

You can also get the version (helps to identify the phone's mainboard):

console.log( pinephone.getModelVersion() )
// output -> '1.0', '1.1', '1.2', etc...

If you want these values returned as an object:

console.log( pinephone.getDeviceInfo() )
// output -> (example Object):
// {
//   modelName: 'Pine64 PinePhonePro',
//   modelVersion: '1.0'
// }

If you want to hand-pick returned values, you can pass an array of constants like this (see full list of options):

console.log(pinephone.getDeviceInfo( [pinephone.Model_VersionNumber] ))
// output -> (example Object):
// {
//   modelVersion: '1.0'
// }

Getting WiFi / Bluetooth statuses

Find out if WiFi or Bluetooth are enabled, both at the software level and also the hardware level (via the kill switch located inside the back cover of the phone).

console.log( pinephone.getWifiStatus() )
// output -> (example Object):
// {
//   softwareEnabled: true,
//   hardwareEnabled: true
// }

console.log( pinephone.getBluetoothStatus() )
// output -> (example Object):
// {
//   softwareEnabled: false,
//   hardwareEnabled: true
// }

Enabling or disabling WiFi / Bluetooth

This one is pretty self-explanitory. Just remember not to test disabling WiFi if you are connected to the phone via SSH!

// Controlling WiFi (software)
pinephone.enableWifi()
pinephone.disableWifi()

// Controlling Bluetooth (software)
pinephone.enableBluetooth()
pinephone.disableBluetooth()

Getting sensor data

Sensor data is accessed via EventEmitter events. By default, sensors are sampled every 50ms.

Reading sensor data is currently not implemented in this version of pinephone.js, but the feature will be made available very soon.

See src/test-scripts/read-x-accel.mjs for example code if you are curious and want to implement something right away.

Developing JavaScript Apps for Mobile Linux Devices:

Current PinePhone Apps

Many of the currently available applications that run on PinePhones weren't designed specifically for mobile devices. They can be desktop applications which were updated to be more adaptive and therefore mobile-friendly through the use of libraries such as Gnome's libhandy. Many of them are being written in C, C++, or Rust. The PinePhone community offers several ways to get started writing apps. Initially, you'll likely be faced with choosing a framework, such as GTK (Typically found on Phosh or Gnome-Mobile), or the KDE frameworks which utilize QT (common on Plasma Mobile).

Your choice of framework isn't really that critical to the end-user, as most apps will build and run perfectly fine under any mobile Linux environment. You can basically just choose the framework that works best for you. When it comes to JavaScript, here are just three options to consider, with Node-GTK being my personal recommendation.

Choices for Developing Mobile Linux Apps with JavaScript

  • Node-GTK - If you prefer working entirely in JavaScript and don't want to ship an entire browser, Node-GTK might be a great solution for you. It offers bindings to GTK 3 and 4, allows use of WebGTK (and therefore WebGL/GPU), and lets you make use of npm modules (something gjs does not offer). As it is GTK-based, you can build front-ends using Glade and all apps built with Node-GTK will feel right at home with other apps in Phosh or Gnome-mobile.
  • Tauri - Seems like a good step in the right direction, as it is much lighter than Electron. Tauri apps will likely not feel very at-home next to other PinePhone apps though, as it doesn't use GTK or QT styling.
  • Electron - Definitely seen as an attractive option for JS devs, due to how simple it is to start developing, testing, and packaging. But Electron has many downsides which need to be considered. It relies on Chromium, leading to large app bundle sizes and high memory usage. Many end users don't like the idea of Chromium (owned by Google) being a requirement for their app to work. It can also cause your app to feel downright sluggish, especially on devices like the original PinePhone with it's limited memory.

Regarding Bun

Bun, an optimized JavaScript runtime using JavaScriptCore, is now supported thanks to their very recent implementation of the child_process API! This means that all methods will now work, even those utilizing rfkill, such as getBluetoothStatus() and enableWifi()!

To use pinephone.js with bun, make sure bun is already installed and then run the following:

bun upgrade --canary

As support for child_process was only recently added to bun, you will need to update to bun's canary release to use pinephone.js as expected. Once Bun publishes an official release with this change included (which should only be a few weeks), you will no longer need to explicitly switch to the canary version.

Contributing:

How to contribute

The best way to contribute is by submitting issues and/or pull requests to the pinephone.js development repository. If you would like to contribute financially, a donation would be greatly appriciated (see next section).

Donations

This library was developed by a sole individual of the PinePhone community - I am not affiliated with Pine64, the company! Any donations you make here will go directly to me, not Pine64. If you are looking instead to support Pine64 (which I highly recommend, they're awesome), please consider purchasing one of their devices or donating to them.

That said, if you like pinephone.js or your project relies on it, a donation (even a small one) would help development quite a bit. Thank you!

Donate with fiat:

  • Donate using Liberapay

Donate with crypto:

  • Monero (XMR): 4B12BmQuYNF9PHg275ASbfiD7iXy1vK2YJkxtK5V4xv9UTrxFv9ZQ4ASokykTvEVa7fL1NDbtKdLyEDHsMGrRht4FdHqiKj
  • Litecoin (LTC): LLfE4awRw47ghQJzMvmn1WPvVykcXwqt9S
  • Bitcoin Cash (BCH): qpzezt09wvry2tc30pzlsj9tk9npmu70kqht4x3xqg

DISCLAIMER: "PINE64 and the PINE64 pinecone logo are trademarked by Pine Store Limited." For more information, please visit this webpage. Please contact me if you have any issues or concerns involving this project's use of branding or imagery.

About

Interact with PinePhone devices using JavaScript!

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published