gui.device
Phone features for Salam apps: share sheet, haptics, permissions, notifications, location and photos on Android, with the same calls returning false on other systems.
import gui.device
gui.device reaches the features of a phone that a page cannot draw: the share sheet and more as they are added. Every call has the same signature on every system. On a desktop, or when the phone does not offer the feature, the call returns false or an empty value and the program carries on.
Platform names the system the program runs on: android, ios or none on a desktop. CanShare tells whether a share sheet exists, and Share opens it with a text and a link. Either may be empty, but not both. The call returns once the sheet is shown; it does not tell what the user chose.
Haptic gives a short system feedback (Tap, Heavy, Success or Failure) and needs no permission. Vibrate runs the motor for a number of milliseconds, at most 5000; on Android the build script adds the VIBRATE permission to the manifest only when the program calls it.
Runtime permissions: CheckPermission answers NotAsked, Granted or Denied at once, and RequestPermission opens the system dialog. The answer arrives later: OnChange sets a function that runs on the UI thread when any request finishes, and a gui.ui app calls ui.Invalidate there and reads CheckPermission in its view. A program that uses gui.window directly receives an EventKind.HostResult event and calls Notify. On Android the manifest must declare the permission: build with --permission camera (also microphone, location, notifications). Without a declaration the request is denied at once. Systems without permissions report Denied.
Notifications: ShowNotification posts one now, ScheduleNotification posts one after a number of seconds, even when the app is not in front, and CancelNotification removes it. The id replaces an earlier notification with the same id. Tapping a notification opens the app. They return false until the Notifications permission is granted (ask with RequestPermission first; from Android 13 it is asked at run time). The build script adds the permission to the manifest when the program shows or schedules a notification. A scheduled notification is inexact and does not survive a restart of the phone.
Location, one fix at a time: RequestLocation asks for the current position and returns at once, LocationStatus says Pending, Ready or Failed, and LastLocation reads the answer. OnChange runs when the fix arrives. The Location permission must be granted first; the build script declares it when the program asks for a location. GPS is used when it is on, the network provider otherwise, and a fix can take several seconds.
Photos: PickPhoto opens the system photo picker and TakePhoto opens the camera app, both without any permission, because the system apps do the work. PhotoStatus says Pending, Ready or Failed (also when the user cancels) and LastPhoto is the path of a JPEG copy in the app cache directory, which image can open. OnChange runs when the picture is ready. The camera app asks for its own permission; if the app declares the camera permission itself (--permission camera) it must be granted before TakePhoto.
App folders: DataDir is the private folder for files the app keeps, CacheDir holds files the system may delete when space runs low, DocumentsDir is the folder the user can reach (the app folder on shared storage on Android, Documents on iOS) and TempDir is for short lived files. Each returns the path of a folder that exists, or an empty string where the system has no such folder. No permission is needed.
Secure storage keeps small secrets such as a login token: SecureSet saves a value under a key, SecureGet reads it back (empty when there is none) and SecureDelete removes it. On Android the value is encrypted with an AES key that never leaves the Android Keystore; on iOS it goes to the Keychain. Keys are up to 200 bytes and values up to 16000 bytes. Where the system has no secure storage, SecureSet and SecureDelete return false and SecureGet returns an empty string.
Device and app information: Model, OSName and OSVersion name the phone and its system; Language is the preferred language tag, Languages the whole list and TimeZone the zone name; ScreenDensity is the pixels per layout point; AppVersion and BuildNumber are the values given with --version and --build when building; IsDarkMode tells the appearance. BatteryLevel gives percent, or -1 when unknown, and IsCharging tells whether the phone is plugged in. Network answers Offline, Wifi, Cellular, Ethernet or Other, and a change of connection runs the function set by OnChange, the way a permission answer does. Each call returns an empty string, zero, false or Offline where the system has no such information, and no permission is needed except ACCESS_NETWORK_STATE for Network on Android, which the build adds.
Links into the app: build with --scheme NAME to open links like NAME://path (a URL type on iOS, an intent filter on Android) and, on Android, with --link-host HOST to open https://HOST links; the site must also serve its assetlinks.json. LaunchURL is the link that started the app, empty when it was started in the usual way, and OnOpenURL sets the function that runs with a link that arrives while the app is running (the host event wakes the loop, so it runs on the UI thread). OpenSettings opens the settings page of the app, where the user can change permissions.
Screen behaviour: KeepAwake stops the screen from sleeping while the app is in front, LockOrientation locks to Portrait or Landscape at run time (the build option --orientation sets the start) and Auto frees it. Immersive hides the status bar and the navigation bar for a full screen page, SetBarStyle picks light or dark status bar icons, and SetBrightness and Brightness use values from 0.0 to 1.0. They need no permission. Each returns false where the system has no such control.
Biometrics: CanAuthenticate tells whether the phone has a fingerprint or face the user has set up, and Authenticate opens the system prompt with a reason. It returns at once; AuthStatus then says Pending, Success or Failed, and OnChange runs when the answer arrives. No biometric data reaches the app, only the verdict.
Calls go through the host layer of the phone shell, so they work in apps built with tools/bash/build-android-app.sh.
Share a link
Check CanShare first when the app also runs on a desktop, and hide the button or fall back to the clipboard when it is false.
/*
* Salam Programming Language (2018-2026)
*
* +-------------------+
* | S A L A M |
* +-------------------+
*
* Designed by Seyyed Ali Mohammadiyeh and the Salam Team
*
* Repository: https://github.com/SalamLang/Salam
*
*/
import gui.device
func main:
println "running on", device.Platform()
if not device.CanShare():
println "no share sheet here"
ret
end
if device.Share("Salam is a programming language", "https://salamlang.ir"):
println "share sheet opened"
else:
println "could not share"
end
endFeedback on a button
Use Haptic for taps and confirmations, and Vibrate for a longer buzz.
/*
* Salam Programming Language (2018-2026)
*
* +-------------------+
* | S A L A M |
* +-------------------+
*
* Designed by Seyyed Ali Mohammadiyeh and the Salam Team
*
* Repository: https://github.com/SalamLang/Salam
*
*/
import gui.device
func main:
if not device.CanVibrate():
println "no vibration here"
ret
end
_ok := device.Haptic(device.HapticKind.Tap)
_ok2 := device.Haptic(device.HapticKind.Success)
_ok3 := device.Vibrate(200)
endAsk for the camera
A button that shows the state and asks when pressed. The view runs again when the dialog closes.
/*
* Salam Programming Language (2018-2026)
*
* +-------------------+
* | S A L A M |
* +-------------------+
*
* Designed by Seyyed Ali Mohammadiyeh and the Salam Team
*
* Repository: https://github.com/SalamLang/Salam
*
*/
import gui.device
import gui.ui
func label(): str:
s := device.CheckPermission(device.Permission.Camera)
if s == device.PermissionState.Granted:
ret "Camera allowed"
end
if s == device.PermissionState.Denied:
ret "Camera denied"
end
ret "Ask for the camera"
end
func main:
println label()
device.OnChange((): ui.Invalidate() end)
ui.RunPage((): ret ui.NoPatches() end, (b: ui.Builder):
b.Open("button")
b.On("click", (): _ok := device.RequestPermission(device.Permission.Camera) end)
b.Text(label())
b.Close()
end)
endNotify the user
Check the permission, then show a notification now and schedule another one.
/*
* Salam Programming Language (2018-2026)
*
* +-------------------+
* | S A L A M |
* +-------------------+
*
* Designed by Seyyed Ali Mohammadiyeh and the Salam Team
*
* Repository: https://github.com/SalamLang/Salam
*
*/
import gui.device
func main:
if device.CheckPermission(device.Permission.Notifications) != device.PermissionState.Granted:
println "notifications are not allowed"
ret
end
_ok := device.ShowNotification(1, "Download finished", "report.pdf is ready")
_ok2 := device.ScheduleNotification(2, "Stand up", "Time for a break", 1800)
_ok3 := device.CancelNotification(2)
endWhere am I
A button that asks for the permission, then for one fix, and shows the position.
/*
* Salam Programming Language (2018-2026)
*
* +-------------------+
* | S A L A M |
* +-------------------+
*
* Designed by Seyyed Ali Mohammadiyeh and the Salam Team
*
* Repository: https://github.com/SalamLang/Salam
*
*/
import gui.device
import gui.ui
import str
func where(): str:
state := device.LocationStatus()
if state == device.LocationState.Ready:
here := device.LastLocation()
ret "lat " + str.FromFloat(here.latitude) + " lon " + str.FromFloat(here.longitude) + " within " + str.FromFloat(here.accuracy) + " m"
end
if state == device.LocationState.Pending:
ret "looking for the position"
end
if state == device.LocationState.Failed:
ret "no position"
end
ret "tap to locate"
end
func ask():
if device.CheckPermission(device.Permission.Location) == device.PermissionState.Granted:
_ok := device.RequestLocation()
ui.Invalidate()
else:
_ok2 := device.RequestPermission(device.Permission.Location)
end
end
func main:
println where()
device.OnChange((): ui.Invalidate() end)
ui.RunPage((): ret ui.NoPatches() end, (b: ui.Builder):
b.Open("button")
b.On("click", (): ask() end)
b.Text(where())
b.Close()
end)
endPick or take a photo
Two buttons: the first picks from the gallery and shows where the copy was saved, the second opens the camera.
/*
* Salam Programming Language (2018-2026)
*
* +-------------------+
* | S A L A M |
* +-------------------+
*
* Designed by Seyyed Ali Mohammadiyeh and the Salam Team
*
* Repository: https://github.com/SalamLang/Salam
*
*/
import gui.device
import gui.ui
func label(): str:
state := device.PhotoStatus()
if state == device.PhotoState.Ready:
ret "saved to " + device.LastPhoto()
end
if state == device.PhotoState.Pending:
ret "waiting for the photo"
end
if state == device.PhotoState.Failed:
ret "no photo"
end
ret "choose a photo"
end
func main:
println label()
device.OnChange((): ui.Invalidate() end)
ui.RunPage((): ret ui.NoPatches() end, (b: ui.Builder):
b.Open("button")
b.On("click", (): _ok := device.PickPhoto() end)
b.Text(label())
b.Close()
b.Open("button")
b.On("click", (): _ok2 := device.TakePhoto() end)
b.Text("take a photo")
b.Close()
end)
endSave a file
Write into the data folder, which is private to the app and survives restarts.
/*
* Salam Programming Language (2018-2026)
*
* +-------------------+
* | S A L A M |
* +-------------------+
*
* Designed by Seyyed Ali Mohammadiyeh and the Salam Team
*
* Repository: https://github.com/SalamLang/Salam
*
*/
import gui.device
import io
func main:
dir := device.DataDir()
if dir.Len() == 0:
println "no app folders here"
ret
end
println "data", dir
println "cache", device.CacheDir()
println "documents", device.DocumentsDir()
println "temp", device.TempDir()
_ok := io.WriteFile(dir + "/notes.txt", "saved")
endRemember a token
Save a secret, read it back and remove it.
/*
* Salam Programming Language (2018-2026)
*
* +-------------------+
* | S A L A M |
* +-------------------+
*
* Designed by Seyyed Ali Mohammadiyeh and the Salam Team
*
* Repository: https://github.com/SalamLang/Salam
*
*/
import gui.device
func main:
if not device.SecureSet("token", "s3cret"):
println "no secure storage here"
ret
end
println "token", device.SecureGet("token")
_gone := device.SecureDelete("token")
println "after delete", device.SecureGet("token").Len()
endShow the device
A page with the phone model, the battery and the connection. It redraws when the connection changes.
/*
* Salam Programming Language (2018-2026)
*
* +-------------------+
* | S A L A M |
* +-------------------+
*
* Designed by Seyyed Ali Mohammadiyeh and the Salam Team
*
* Repository: https://github.com/SalamLang/Salam
*
*/
import gui.device
import gui.ui
func network_name(): str:
kind := device.Network()
if kind == device.NetworkKind.Wifi:
ret "wifi"
end
if kind == device.NetworkKind.Cellular:
ret "mobile data"
end
if kind == device.NetworkKind.Offline:
ret "offline"
end
ret "connected"
end
func main:
if device.OSName().Len() == 0:
println "no device info here"
ret
end
device.OnChange((): ui.Invalidate() end)
ui.RunPage((): ret ui.NoPatches() end, (b: ui.Builder):
b.Open("button")
b.Text(device.Model() + ", " + device.OSName() + " " + device.OSVersion())
b.Close()
b.Open("button")
b.Text("battery " + device.BatteryLevel() + "%, " + network_name())
b.Close()
b.Open("button")
b.Text(device.Language() + ", " + device.TimeZone() + ", v" + device.AppVersion())
b.Close()
end)
endOpen from a link
Build with --scheme demo, then open demo://hello on the phone. The page shows the link and has a button for the app settings.
/*
* Salam Programming Language (2018-2026)
*
* +-------------------+
* | S A L A M |
* +-------------------+
*
* Designed by Seyyed Ali Mohammadiyeh and the Salam Team
*
* Repository: https://github.com/SalamLang/Salam
*
*/
import gui.device
import gui.ui
mut last := ""
func main:
last = device.LaunchURL()
if last.Len() == 0 and device.Platform() == "none":
println "no links here"
ret
end
device.OnOpenURL((url: str): ui.Invalidate() last = url end)
ui.RunPage((): ret ui.NoPatches() end, (b: ui.Builder):
b.Open("button")
b.Text("opened with " + last)
b.Close()
b.Open("button")
b.On("click", (): _ok := device.OpenSettings() end)
b.Text("app settings")
b.Close()
end)
endFull screen and bright
Keep the screen on, lock to portrait, and two buttons for full screen and full brightness.
/*
* Salam Programming Language (2018-2026)
*
* +-------------------+
* | S A L A M |
* +-------------------+
*
* Designed by Seyyed Ali Mohammadiyeh and the Salam Team
*
* Repository: https://github.com/SalamLang/Salam
*
*/
import gui.device
import gui.ui
mut full := false
func main:
if not device.KeepAwake(true):
println "no screen control here"
ret
end
_lock := device.LockOrientation(device.Orientation.Portrait)
ui.RunPage((): ret ui.NoPatches() end, (b: ui.Builder):
b.Open("button")
b.On("click", (): full = not full _ok := device.Immersive(full) end)
b.Text("full screen")
b.Close()
b.Open("button")
b.On("click", (): _ok2 := device.SetBrightness(1.0) end)
b.Text("full brightness")
b.Close()
end)
endUnlock with a fingerprint
A button that asks the system to recognise the user and shows the result.
/*
* Salam Programming Language (2018-2026)
*
* +-------------------+
* | S A L A M |
* +-------------------+
*
* Designed by Seyyed Ali Mohammadiyeh and the Salam Team
*
* Repository: https://github.com/SalamLang/Salam
*
*/
import gui.device
import gui.ui
func label(): str:
state := device.AuthStatus()
if state == device.AuthState.Success:
ret "unlocked"
end
if state == device.AuthState.Pending:
ret "waiting"
end
if state == device.AuthState.Failed:
ret "not recognised"
end
ret "locked"
end
func main:
if not device.CanAuthenticate():
println "no biometrics here"
ret
end
device.OnChange((): ui.Invalidate() end)
ui.RunPage((): ret ui.NoPatches() end, (b: ui.Builder):
b.Open("button")
b.On("click", (): _ok := device.Authenticate("Unlock the notes") end)
b.Text(label())
b.Close()
end)
endTypes
Permission
enum Permission| Name | Type | Description |
|---|---|---|
Camera | | Taking pictures. |
Microphone | | Recording sound. |
Location | | Reading the position of the phone. |
Notifications | | Showing notifications (asked at run time from Android 13). |
/*
* Salam Programming Language (2018-2026)
*
* +-------------------+
* | S A L A M |
* +-------------------+
*
* Designed by Seyyed Ali Mohammadiyeh and the Salam Team
*
* Repository: https://github.com/SalamLang/Salam
*
*/
import gui.device
import gui.ui
func label(): str:
s := device.CheckPermission(device.Permission.Camera)
if s == device.PermissionState.Granted:
ret "Camera allowed"
end
if s == device.PermissionState.Denied:
ret "Camera denied"
end
ret "Ask for the camera"
end
func main:
println label()
device.OnChange((): ui.Invalidate() end)
ui.RunPage((): ret ui.NoPatches() end, (b: ui.Builder):
b.Open("button")
b.On("click", (): _ok := device.RequestPermission(device.Permission.Camera) end)
b.Text(label())
b.Close()
end)
endPermissionState
enum PermissionState| Name | Type | Description |
|---|---|---|
NotAsked | | The user has not been asked yet. |
Granted | | The app may use the feature. |
Denied | | The user refused, or the system has no such permission. |
The example for this item is shown with the ones above: gui-device-Permission.salam
PhotoState
enum PhotoState| Name | Type | Description |
|---|---|---|
Idle | | No request was made. |
Pending | | The picker or camera is open. |
Ready | | A photo was saved; read its path with LastPhoto. |
Failed | | The user cancelled or the system has no picker or camera. |
/*
* Salam Programming Language (2018-2026)
*
* +-------------------+
* | S A L A M |
* +-------------------+
*
* Designed by Seyyed Ali Mohammadiyeh and the Salam Team
*
* Repository: https://github.com/SalamLang/Salam
*
*/
import gui.device
import gui.ui
func label(): str:
state := device.PhotoStatus()
if state == device.PhotoState.Ready:
ret "saved to " + device.LastPhoto()
end
if state == device.PhotoState.Pending:
ret "waiting for the photo"
end
if state == device.PhotoState.Failed:
ret "no photo"
end
ret "choose a photo"
end
func main:
println label()
device.OnChange((): ui.Invalidate() end)
ui.RunPage((): ret ui.NoPatches() end, (b: ui.Builder):
b.Open("button")
b.On("click", (): _ok := device.PickPhoto() end)
b.Text(label())
b.Close()
b.Open("button")
b.On("click", (): _ok2 := device.TakePhoto() end)
b.Text("take a photo")
b.Close()
end)
endLocationState
enum LocationState| Name | Type | Description |
|---|---|---|
Idle | | No request was made. |
Pending | | A fix is being looked for. |
Ready | | A fix arrived; read it with LastLocation. |
Failed | | No fix could be made: the permission is missing or no provider is on. |
/*
* Salam Programming Language (2018-2026)
*
* +-------------------+
* | S A L A M |
* +-------------------+
*
* Designed by Seyyed Ali Mohammadiyeh and the Salam Team
*
* Repository: https://github.com/SalamLang/Salam
*
*/
import gui.device
import gui.ui
import str
func where(): str:
state := device.LocationStatus()
if state == device.LocationState.Ready:
here := device.LastLocation()
ret "lat " + str.FromFloat(here.latitude) + " lon " + str.FromFloat(here.longitude) + " within " + str.FromFloat(here.accuracy) + " m"
end
if state == device.LocationState.Pending:
ret "looking for the position"
end
if state == device.LocationState.Failed:
ret "no position"
end
ret "tap to locate"
end
func ask():
if device.CheckPermission(device.Permission.Location) == device.PermissionState.Granted:
_ok := device.RequestLocation()
ui.Invalidate()
else:
_ok2 := device.RequestPermission(device.Permission.Location)
end
end
func main:
println where()
device.OnChange((): ui.Invalidate() end)
ui.RunPage((): ret ui.NoPatches() end, (b: ui.Builder):
b.Open("button")
b.On("click", (): ask() end)
b.Text(where())
b.Close()
end)
endLocation
struct Location| Name | Type | Description |
|---|---|---|
latitude | f64 = 0 | Degrees north of the equator. |
longitude | f64 = 0 | Degrees east of the prime meridian. |
accuracy | f64 = 0 | The error radius in meters, 0 when unknown. |
The example for this item is shown with the ones above: gui-device-Location.salam
HapticKind
enum HapticKindHaptic.| Name | Type | Description |
|---|---|---|
Tap | | A light tap, like pressing a key. |
Heavy | | A firmer pulse, like a long press. |
Success | | A confirmation pulse. |
Failure | | A rejection pulse. |
/*
* Salam Programming Language (2018-2026)
*
* +-------------------+
* | S A L A M |
* +-------------------+
*
* Designed by Seyyed Ali Mohammadiyeh and the Salam Team
*
* Repository: https://github.com/SalamLang/Salam
*
*/
import gui.device
func main:
if not device.CanVibrate():
println "no vibration here"
ret
end
_ok := device.Haptic(device.HapticKind.Tap)
_ok2 := device.Haptic(device.HapticKind.Success)
_ok3 := device.Vibrate(200)
endNetworkKind
enum NetworkKind| Name | Type | Description |
|---|---|---|
Offline | | No connection. |
Wifi | | Connected through Wi-Fi. |
Cellular | | Connected through the mobile network. |
Ethernet | | Connected through a cable. |
Other | | Connected some other way, such as a VPN or Bluetooth. |
/*
* Salam Programming Language (2018-2026)
*
* +-------------------+
* | S A L A M |
* +-------------------+
*
* Designed by Seyyed Ali Mohammadiyeh and the Salam Team
*
* Repository: https://github.com/SalamLang/Salam
*
*/
import gui.device
import gui.ui
func network_name(): str:
kind := device.Network()
if kind == device.NetworkKind.Wifi:
ret "wifi"
end
if kind == device.NetworkKind.Cellular:
ret "mobile data"
end
if kind == device.NetworkKind.Offline:
ret "offline"
end
ret "connected"
end
func main:
if device.OSName().Len() == 0:
println "no device info here"
ret
end
device.OnChange((): ui.Invalidate() end)
ui.RunPage((): ret ui.NoPatches() end, (b: ui.Builder):
b.Open("button")
b.Text(device.Model() + ", " + device.OSName() + " " + device.OSVersion())
b.Close()
b.Open("button")
b.Text("battery " + device.BatteryLevel() + "%, " + network_name())
b.Close()
b.Open("button")
b.Text(device.Language() + ", " + device.TimeZone() + ", v" + device.AppVersion())
b.Close()
end)
endOrientation
enum Orientation| Name | Type | Description |
|---|---|---|
Auto | | Follow the sensor, within what the build allows. |
Portrait | | Stay upright. |
Landscape | | Stay on its side. |
/*
* Salam Programming Language (2018-2026)
*
* +-------------------+
* | S A L A M |
* +-------------------+
*
* Designed by Seyyed Ali Mohammadiyeh and the Salam Team
*
* Repository: https://github.com/SalamLang/Salam
*
*/
import gui.device
import gui.ui
mut full := false
func main:
if not device.KeepAwake(true):
println "no screen control here"
ret
end
_lock := device.LockOrientation(device.Orientation.Portrait)
ui.RunPage((): ret ui.NoPatches() end, (b: ui.Builder):
b.Open("button")
b.On("click", (): full = not full _ok := device.Immersive(full) end)
b.Text("full screen")
b.Close()
b.Open("button")
b.On("click", (): _ok2 := device.SetBrightness(1.0) end)
b.Text("full brightness")
b.Close()
end)
endBarStyle
enum BarStyle| Name | Type | Description |
|---|---|---|
Auto | | Follow the page and the system appearance. |
LightIcons | | Light icons, for a dark page. |
DarkIcons | | Dark icons, for a light page. |
The example for this item is shown with the ones above: gui-device-Screen.salam
AuthState
enum AuthState| Name | Type | Description |
|---|---|---|
Idle | | No check was asked for. |
Pending | | The system prompt is open. |
Success | | The user was recognised. |
Failed | | The user cancelled, was not recognised or the system has no biometrics. |
/*
* Salam Programming Language (2018-2026)
*
* +-------------------+
* | S A L A M |
* +-------------------+
*
* Designed by Seyyed Ali Mohammadiyeh and the Salam Team
*
* Repository: https://github.com/SalamLang/Salam
*
*/
import gui.device
import gui.ui
func label(): str:
state := device.AuthStatus()
if state == device.AuthState.Success:
ret "unlocked"
end
if state == device.AuthState.Pending:
ret "waiting"
end
if state == device.AuthState.Failed:
ret "not recognised"
end
ret "locked"
end
func main:
if not device.CanAuthenticate():
println "no biometrics here"
ret
end
device.OnChange((): ui.Invalidate() end)
ui.RunPage((): ret ui.NoPatches() end, (b: ui.Builder):
b.Open("button")
b.On("click", (): _ok := device.Authenticate("Unlock the notes") end)
b.Text(label())
b.Close()
end)
endFunctions
Platform
func Platform(): strandroid, ios or none./*
* Salam Programming Language (2018-2026)
*
* +-------------------+
* | S A L A M |
* +-------------------+
*
* Designed by Seyyed Ali Mohammadiyeh and the Salam Team
*
* Repository: https://github.com/SalamLang/Salam
*
*/
import gui.device
func main:
println "running on", device.Platform()
if not device.CanShare():
println "no share sheet here"
ret
end
if device.Share("Salam is a programming language", "https://salamlang.ir"):
println "share sheet opened"
else:
println "could not share"
end
endCanShare
func CanShare(): boolThe example for this item is shown with the ones above: gui-device-Share.salam
Share
func Share(text: str, url: str): boolThe example for this item is shown with the ones above: gui-device-Share.salam
CanVibrate
func CanVibrate(): boolThe example for this item is shown with the ones above: gui-device-Haptic.salam
Vibrate
func Vibrate(ms: int): boolThe example for this item is shown with the ones above: gui-device-Haptic.salam
Haptic
func Haptic(kind: HapticKind): boolThe example for this item is shown with the ones above: gui-device-Haptic.salam
DataDir
func DataDir(): str/*
* Salam Programming Language (2018-2026)
*
* +-------------------+
* | S A L A M |
* +-------------------+
*
* Designed by Seyyed Ali Mohammadiyeh and the Salam Team
*
* Repository: https://github.com/SalamLang/Salam
*
*/
import gui.device
import io
func main:
dir := device.DataDir()
if dir.Len() == 0:
println "no app folders here"
ret
end
println "data", dir
println "cache", device.CacheDir()
println "documents", device.DocumentsDir()
println "temp", device.TempDir()
_ok := io.WriteFile(dir + "/notes.txt", "saved")
endCacheDir
func CacheDir(): strThe example for this item is shown with the ones above: gui-device-Paths.salam
DocumentsDir
func DocumentsDir(): strThe example for this item is shown with the ones above: gui-device-Paths.salam
TempDir
func TempDir(): strThe example for this item is shown with the ones above: gui-device-Paths.salam
SecureSet
func SecureSet(key: str, value: str): bool/*
* Salam Programming Language (2018-2026)
*
* +-------------------+
* | S A L A M |
* +-------------------+
*
* Designed by Seyyed Ali Mohammadiyeh and the Salam Team
*
* Repository: https://github.com/SalamLang/Salam
*
*/
import gui.device
func main:
if not device.SecureSet("token", "s3cret"):
println "no secure storage here"
ret
end
println "token", device.SecureGet("token")
_gone := device.SecureDelete("token")
println "after delete", device.SecureGet("token").Len()
endSecureGet
func SecureGet(key: str): strThe example for this item is shown with the ones above: gui-device-Secure.salam
SecureDelete
func SecureDelete(key: str): boolThe example for this item is shown with the ones above: gui-device-Secure.salam
Model
func Model(): strThe example for this item is shown with the ones above: gui-device-Info.salam
OSName
func OSName(): strAndroid or iOS. Empty on a desktop.The example for this item is shown with the ones above: gui-device-Info.salam
OSVersion
func OSVersion(): str15. Empty on a desktop.The example for this item is shown with the ones above: gui-device-Info.salam
Language
func Language(): stren-US. Empty on a desktop.The example for this item is shown with the ones above: gui-device-Info.salam
Languages
func Languages(): Vector<str>The example for this item is shown with the ones above: gui-device-Info.salam
TimeZone
func TimeZone(): strAsia/Tehran. Empty on a desktop.The example for this item is shown with the ones above: gui-device-Info.salam
ScreenDensity
func ScreenDensity(): f64The example for this item is shown with the ones above: gui-device-Info.salam
AppVersion
func AppVersion(): str--version when building. Empty on a desktop.The example for this item is shown with the ones above: gui-device-Info.salam
BuildNumber
func BuildNumber(): int--build when building. Zero on a desktop.The example for this item is shown with the ones above: gui-device-Info.salam
IsDarkMode
func IsDarkMode(): boolThe example for this item is shown with the ones above: gui-device-Info.salam
BatteryLevel
func BatteryLevel(): intThe example for this item is shown with the ones above: gui-device-Info.salam
IsCharging
func IsCharging(): boolThe example for this item is shown with the ones above: gui-device-Info.salam
Network
func Network(): NetworkKindOnChange runs. On Android the build declares ACCESS_NETWORK_STATE when you call it.The example for this item is shown with the ones above: gui-device-Info.salam
KeepAwake
func KeepAwake(enabled: bool): boolThe example for this item is shown with the ones above: gui-device-Screen.salam
LockOrientation
func LockOrientation(o: Orientation): boolAuto. The build option --orientation sets the start. False where the system has no such control.The example for this item is shown with the ones above: gui-device-Screen.salam
Immersive
func Immersive(enabled: bool): boolThe example for this item is shown with the ones above: gui-device-Screen.salam
SetBarStyle
func SetBarStyle(style: BarStyle): boolAuto gives the choice back. False where the system has no status bar.The example for this item is shown with the ones above: gui-device-Screen.salam
SetBrightness
func SetBrightness(level: f64): boolThe example for this item is shown with the ones above: gui-device-Screen.salam
Brightness
func Brightness(): f64The example for this item is shown with the ones above: gui-device-Screen.salam
CanAuthenticate
func CanAuthenticate(): boolThe example for this item is shown with the ones above: gui-device-Auth.salam
Authenticate
func Authenticate(reason: str): boolOnChange and AuthStatus. The build declares USE_BIOMETRIC on Android and the Face ID description on iOS when you call it.The example for this item is shown with the ones above: gui-device-Auth.salam
AuthStatus
func AuthStatus(): AuthStateThe example for this item is shown with the ones above: gui-device-Auth.salam
OnChange
func OnChange(hook: func())gui.ui apps get it called by the event loop.The example for this item is shown with the ones above: gui-device-Permission.salam
OnOpenURL
func OnOpenURL(hook: func(str))--scheme or --link-host. Several links in a row give the latest./*
* Salam Programming Language (2018-2026)
*
* +-------------------+
* | S A L A M |
* +-------------------+
*
* Designed by Seyyed Ali Mohammadiyeh and the Salam Team
*
* Repository: https://github.com/SalamLang/Salam
*
*/
import gui.device
import gui.ui
mut last := ""
func main:
last = device.LaunchURL()
if last.Len() == 0 and device.Platform() == "none":
println "no links here"
ret
end
device.OnOpenURL((url: str): ui.Invalidate() last = url end)
ui.RunPage((): ret ui.NoPatches() end, (b: ui.Builder):
b.Open("button")
b.Text("opened with " + last)
b.Close()
b.Open("button")
b.On("click", (): _ok := device.OpenSettings() end)
b.Text("app settings")
b.Close()
end)
endLaunchURL
func LaunchURL(): strThe example for this item is shown with the ones above: gui-device-Links.salam
OpenSettings
func OpenSettings(): boolThe example for this item is shown with the ones above: gui-device-Links.salam
Notify
func Notify()OnChange. gui.ui calls it for you; call it yourself from a HostResult event of gui.window.The example for this item is shown with the ones above: gui-device-Permission.salam
CheckPermission
func CheckPermission(p: Permission): PermissionStateThe example for this item is shown with the ones above: gui-device-Permission.salam
RequestPermission
func RequestPermission(p: Permission): boolOnChange.The example for this item is shown with the ones above: gui-device-Permission.salam
ShowNotification
func ShowNotification(id: int, title: str, body: str): bool/*
* Salam Programming Language (2018-2026)
*
* +-------------------+
* | S A L A M |
* +-------------------+
*
* Designed by Seyyed Ali Mohammadiyeh and the Salam Team
*
* Repository: https://github.com/SalamLang/Salam
*
*/
import gui.device
func main:
if device.CheckPermission(device.Permission.Notifications) != device.PermissionState.Granted:
println "notifications are not allowed"
ret
end
_ok := device.ShowNotification(1, "Download finished", "report.pdf is ready")
_ok2 := device.ScheduleNotification(2, "Stand up", "Time for a break", 1800)
_ok3 := device.CancelNotification(2)
endScheduleNotification
func ScheduleNotification(id: int, title: str, body: str, seconds: int): boolThe example for this item is shown with the ones above: gui-device-Notification.salam
CancelNotification
func CancelNotification(id: int): boolThe example for this item is shown with the ones above: gui-device-Notification.salam
RequestLocation
func RequestLocation(): boolThe example for this item is shown with the ones above: gui-device-Location.salam
LocationStatus
func LocationStatus(): LocationStateThe example for this item is shown with the ones above: gui-device-Location.salam
LastLocation
func LastLocation(): LocationThe example for this item is shown with the ones above: gui-device-Location.salam
PickPhoto
func PickPhoto(): boolOnChange.The example for this item is shown with the ones above: gui-device-Photo.salam
TakePhoto
func TakePhoto(): boolOnChange.The example for this item is shown with the ones above: gui-device-Photo.salam
PhotoStatus
func PhotoStatus(): PhotoStateThe example for this item is shown with the ones above: gui-device-Photo.salam
LastPhoto
func LastPhoto(): strThe example for this item is shown with the ones above: gui-device-Photo.salam