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.
gui-device-Share.salam
/*
* 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
funcmain:
println"running on", device.Platform()
ifnot device.CanShare():
println"no share sheet here"retendif device.Share("Salam is a programming language", "https://salamlang.ir"):
println"share sheet opened"else:
println"could not share"endend
Output
running on none
no share sheet here
Feedback on a button
Use Haptic for taps and confirmations, and Vibrate for a longer buzz.
gui-device-Haptic.salam
/*
* 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
funcmain:
ifnot device.CanVibrate():
println"no vibration here"retend
_ok := device.Haptic(device.HapticKind.Tap)
_ok2 := device.Haptic(device.HapticKind.Success)
_ok3 := device.Vibrate(200)
end
Output
no vibration here
Ask for the camera
A button that shows the state and asks when pressed. The view runs again when the dialog closes.
gui-device-Permission.salam
/*
* 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
funclabel(): str:
s := device.CheckPermission(device.Permission.Camera)
if s == device.PermissionState.Granted:
ret"Camera allowed"endif s == device.PermissionState.Denied:
ret"Camera denied"endret"Ask for the camera"endfuncmain:
printlnlabel()
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)
end
Notify the user
Check the permission, then show a notification now and schedule another one.
gui-device-Notification.salam
/*
* 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
funcmain:
if device.CheckPermission(device.Permission.Notifications) != device.PermissionState.Granted:
println"notifications are not allowed"retend
_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)
end
Output
notifications are not allowed
Where am I
A button that asks for the permission, then for one fix, and shows the position.
gui-device-Location.salam
/*
* 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
importstrfuncwhere(): 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"endif state == device.LocationState.Pending:
ret"looking for the position"endif state == device.LocationState.Failed:
ret"no position"endret"tap to locate"endfuncask():
if device.CheckPermission(device.Permission.Location) == device.PermissionState.Granted:
_ok := device.RequestLocation()
ui.Invalidate()
else:
_ok2 := device.RequestPermission(device.Permission.Location)
endendfuncmain:
printlnwhere()
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)
end
Pick or take a photo
Two buttons: the first picks from the gallery and shows where the copy was saved, the second opens the camera.
gui-device-Photo.salam
/*
* 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
funclabel(): str:
state := device.PhotoStatus()
if state == device.PhotoState.Ready:
ret"saved to " + device.LastPhoto()
endif state == device.PhotoState.Pending:
ret"waiting for the photo"endif state == device.PhotoState.Failed:
ret"no photo"endret"choose a photo"endfuncmain:
printlnlabel()
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)
end
Save a file
Write into the data folder, which is private to the app and survives restarts.
gui-device-Paths.salam
/*
* 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
funcmain:
dir := device.DataDir()
if dir.Len() == 0:
println"no app folders here"retendprintln"data", dir
println"cache", device.CacheDir()
println"documents", device.DocumentsDir()
println"temp", device.TempDir()
_ok := io.WriteFile(dir + "/notes.txt", "saved")
end
Output
no app folders here
Remember a token
Save a secret, read it back and remove it.
gui-device-Secure.salam
/*
* 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
funcmain:
ifnot device.SecureSet("token", "s3cret"):
println"no secure storage here"retendprintln"token", device.SecureGet("token")
_gone := device.SecureDelete("token")
println"after delete", device.SecureGet("token").Len()
end
Output
no secure storage here
Show the device
A page with the phone model, the battery and the connection. It redraws when the connection changes.
gui-device-Info.salam
/*
* 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
funcnetwork_name(): str:
kind := device.Network()
if kind == device.NetworkKind.Wifi:
ret"wifi"endif kind == device.NetworkKind.Cellular:
ret"mobile data"endif kind == device.NetworkKind.Offline:
ret"offline"endret"connected"endfuncmain:
if device.OSName().Len() == 0:
println"no device info here"retend
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)
end
Output
no device info here
Open 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.
gui-device-Links.salam
/*
* 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 := ""funcmain:
last = device.LaunchURL()
if last.Len() == 0and device.Platform() == "none":
println"no links here"retend
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)
end
Output
no links here
Full screen and bright
Keep the screen on, lock to portrait, and two buttons for full screen and full brightness.
gui-device-Screen.salam
/*
* 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 := falsefuncmain:
ifnot device.KeepAwake(true):
println"no screen control here"retend
_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)
end
Output
no screen control here
Unlock with a fingerprint
A button that asks the system to recognise the user and shows the result.
gui-device-Auth.salam
/*
* 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
funclabel(): str:
state := device.AuthStatus()
if state == device.AuthState.Success:
ret"unlocked"endif state == device.AuthState.Pending:
ret"waiting"endif state == device.AuthState.Failed:
ret"not recognised"endret"locked"endfuncmain:
ifnot device.CanAuthenticate():
println"no biometrics here"retend
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)
end
Showing notifications (asked at run time from Android 13).
gui-device-Permission.salam
/*
* 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
funclabel(): str:
s := device.CheckPermission(device.Permission.Camera)
if s == device.PermissionState.Granted:
ret"Camera allowed"endif s == device.PermissionState.Denied:
ret"Camera denied"endret"Ask for the camera"endfuncmain:
printlnlabel()
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)
end
The user cancelled or the system has no picker or camera.
gui-device-Photo.salam
/*
* 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
funclabel(): str:
state := device.PhotoStatus()
if state == device.PhotoState.Ready:
ret"saved to " + device.LastPhoto()
endif state == device.PhotoState.Pending:
ret"waiting for the photo"endif state == device.PhotoState.Failed:
ret"no photo"endret"choose a photo"endfuncmain:
printlnlabel()
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)
end
No fix could be made: the permission is missing or no provider is on.
gui-device-Location.salam
/*
* 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
importstrfuncwhere(): 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"endif state == device.LocationState.Pending:
ret"looking for the position"endif state == device.LocationState.Failed:
ret"no position"endret"tap to locate"endfuncask():
if device.CheckPermission(device.Permission.Location) == device.PermissionState.Granted:
_ok := device.RequestLocation()
ui.Invalidate()
else:
_ok2 := device.RequestPermission(device.Permission.Location)
endendfuncmain:
printlnwhere()
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)
end
/*
* 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
funcmain:
ifnot device.CanVibrate():
println"no vibration here"retend
_ok := device.Haptic(device.HapticKind.Tap)
_ok2 := device.Haptic(device.HapticKind.Success)
_ok3 := device.Vibrate(200)
end
/*
* 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 := falsefuncmain:
ifnot device.KeepAwake(true):
println"no screen control here"retend
_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)
end
The user cancelled, was not recognised or the system has no biometrics.
gui-device-Auth.salam
/*
* 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
funclabel(): str:
state := device.AuthStatus()
if state == device.AuthState.Success:
ret"unlocked"endif state == device.AuthState.Pending:
ret"waiting"endif state == device.AuthState.Failed:
ret"not recognised"endret"locked"endfuncmain:
ifnot device.CanAuthenticate():
println"no biometrics here"retend
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)
end
Names the system the program runs on: android, ios or none.
gui-device-Share.salam
/*
* 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
funcmain:
println"running on", device.Platform()
ifnot device.CanShare():
println"no share sheet here"retendif device.Share("Salam is a programming language", "https://salamlang.ir"):
println"share sheet opened"else:
println"could not share"endend
Returns the private folder for the files the app keeps. Empty where the system has none.
gui-device-Paths.salam
/*
* 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
funcmain:
dir := device.DataDir()
if dir.Len() == 0:
println"no app folders here"retendprintln"data", dir
println"cache", device.CacheDir()
println"documents", device.DocumentsDir()
println"temp", device.TempDir()
_ok := io.WriteFile(dir + "/notes.txt", "saved")
end
Saves a value under a key in the Android Keystore backed storage or the iOS Keychain. False when the key is empty or longer than 200 bytes, the value is longer than 16000 bytes or the system has no secure storage.
gui-device-Secure.salam
/*
* 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
funcmain:
ifnot device.SecureSet("token", "s3cret"):
println"no secure storage here"retendprintln"token", device.SecureGet("token")
_gone := device.SecureDelete("token")
println"after delete", device.SecureGet("token").Len()
end
Returns the kind of connection in use. When it changes, the function set by OnChange runs. On Android the build declares ACCESS_NETWORK_STATE when you call it.
Locks the screen to portrait or landscape at run time, or frees it with Auto. The build option --orientation sets the start. False where the system has no such control.
Hides the status bar and the navigation bar (the home indicator on iOS) for a full screen page, or shows them again. False where the system has no such control.
Chooses light or dark status bar icons, overriding the choice the page makes from its background. Auto gives the choice back. False where the system has no status bar.
Sets the screen brightness from 0.0 to 1.0 while the app runs. A negative number gives control back to the system. On iOS the change is system wide until restored. False where the system has no such control.
Opens the system biometric prompt with the given reason as its title. False when there are no biometrics; the answer comes through OnChange and AuthStatus. The build declares USE_BIOMETRIC on Android and the Face ID description on iOS when you call it.
Sets the function that runs with the link when the app is opened by a link while it is already running. Needs the build option --scheme or --link-host. Several links in a row give the latest.
gui-device-Links.salam
/*
* 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 := ""funcmain:
last = device.LaunchURL()
if last.Len() == 0and device.Platform() == "none":
println"no links here"retend
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)
end
Opens the system dialog for a permission. Returns false when the system has no such permission or it is not declared; the answer comes through OnChange.
Posts a notification now with an id, a title and a body. False when notifications are not allowed, both texts are empty or the system has none.
gui-device-Notification.salam
/*
* 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
funcmain:
if device.CheckPermission(device.Permission.Notifications) != device.PermissionState.Granted:
println"notifications are not allowed"retend
_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)
end
Posts a notification after the given seconds, even if the app is closed by then. False when the seconds are not positive or notifications are not allowed.