@craft-native/ios 0.0.134 → 0.0.135
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -0
- package/package.json +1 -1
- package/templates/CraftApp.swift +48 -0
package/README.md
CHANGED
|
@@ -505,6 +505,13 @@ await window.craft.restorePurchases();
|
|
|
505
505
|
window.craft.setKeepAwake(true); // Prevent screen dimming
|
|
506
506
|
window.craft.setKeepAwake(false); // Allow screen dimming
|
|
507
507
|
|
|
508
|
+
// Screen brightness, 0 to 1: always available (no config flag). It is the
|
|
509
|
+
// device's backlight, so put it back: `brightness` from 'craft-native/mobile'
|
|
510
|
+
// remembers the person's level, restores it, and releases it while the app is
|
|
511
|
+
// in the background.
|
|
512
|
+
const level = await window.craft.getBrightness(); // 0.62
|
|
513
|
+
await window.craft.setBrightness(0.1); // resolves with what the screen reports
|
|
514
|
+
|
|
508
515
|
// Speech: short spoken cues that duck the person's music instead of stopping
|
|
509
516
|
// it, and play with the silent switch on. Always available (no config flag).
|
|
510
517
|
// Resolves when the utterance ends: true if spoken, false if stopped or
|
package/package.json
CHANGED
package/templates/CraftApp.swift
CHANGED
|
@@ -2140,6 +2140,15 @@ struct CraftWebView: UIViewRepresentable {
|
|
|
2140
2140
|
} else {
|
|
2141
2141
|
rejectCallback(callbackId, error: "Keep awake is disabled", code: "CAPABILITY_DISABLED")
|
|
2142
2142
|
}
|
|
2143
|
+
// MARK: - Screen Brightness
|
|
2144
|
+
case "getBrightness":
|
|
2145
|
+
getBrightness(callbackId: callbackId)
|
|
2146
|
+
case "setBrightness":
|
|
2147
|
+
if let level = (body["level"] as? NSNumber)?.doubleValue, level.isFinite {
|
|
2148
|
+
setBrightness(level, callbackId: callbackId)
|
|
2149
|
+
} else {
|
|
2150
|
+
rejectCallback(callbackId, error: "setBrightness was called without the values it needs", code: "INVALID_ARGUMENT")
|
|
2151
|
+
}
|
|
2143
2152
|
// MARK: - Orientation Lock
|
|
2144
2153
|
case "lockOrientation":
|
|
2145
2154
|
if config.enableOrientationLock {
|
|
@@ -3102,6 +3111,7 @@ struct CraftWebView: UIViewRepresentable {
|
|
|
3102
3111
|
orientationLock: \(config.enableOrientationLock),
|
|
3103
3112
|
deepLinks: \(config.enableDeepLinks),
|
|
3104
3113
|
flashlight: true,
|
|
3114
|
+
brightness: true,
|
|
3105
3115
|
speech: true,
|
|
3106
3116
|
network: true,
|
|
3107
3117
|
deviceInfo: true,
|
|
@@ -4041,6 +4051,25 @@ struct CraftWebView: UIViewRepresentable {
|
|
|
4041
4051
|
});
|
|
4042
4052
|
},
|
|
4043
4053
|
|
|
4054
|
+
// Screen brightness, 0 to 1. Each resolves with the level the
|
|
4055
|
+
// screen then reports.
|
|
4056
|
+
getBrightness: function() {
|
|
4057
|
+
var self = this;
|
|
4058
|
+
var id = 'cb_' + (++this._callbackId);
|
|
4059
|
+
window.webkit.messageHandlers.craft.postMessage({action: 'getBrightness', callbackId: id});
|
|
4060
|
+
return new Promise(function(resolve, reject) {
|
|
4061
|
+
self._callbacks[id] = {resolve: resolve, reject: reject};
|
|
4062
|
+
});
|
|
4063
|
+
},
|
|
4064
|
+
setBrightness: function(level) {
|
|
4065
|
+
var self = this;
|
|
4066
|
+
var id = 'cb_' + (++this._callbackId);
|
|
4067
|
+
window.webkit.messageHandlers.craft.postMessage({action: 'setBrightness', level: level, callbackId: id});
|
|
4068
|
+
return new Promise(function(resolve, reject) {
|
|
4069
|
+
self._callbacks[id] = {resolve: resolve, reject: reject};
|
|
4070
|
+
});
|
|
4071
|
+
},
|
|
4072
|
+
|
|
4044
4073
|
// Speech synthesis. speak() settles when the utterance ends:
|
|
4045
4074
|
// true when it was spoken, false when something stopped it.
|
|
4046
4075
|
// No timeout, because a long sentence at a slow rate can
|
|
@@ -6236,6 +6265,25 @@ struct CraftWebView: UIViewRepresentable {
|
|
|
6236
6265
|
}
|
|
6237
6266
|
}
|
|
6238
6267
|
|
|
6268
|
+
// MARK: - Screen Brightness
|
|
6269
|
+
//
|
|
6270
|
+
// The device's backlight, 0 to 1. It is system-wide, not the app's:
|
|
6271
|
+
// a page that dims it reads it first and puts it back - when it is
|
|
6272
|
+
// done, and when the app leaves the foreground (@stacksjs/mobile's
|
|
6273
|
+
// screen API does both off the page's visibility).
|
|
6274
|
+
private func getBrightness(callbackId: String?) {
|
|
6275
|
+
DispatchQueue.main.async {
|
|
6276
|
+
self.resolveCallback(callbackId, result: Double(UIScreen.main.brightness))
|
|
6277
|
+
}
|
|
6278
|
+
}
|
|
6279
|
+
|
|
6280
|
+
private func setBrightness(_ level: Double, callbackId: String?) {
|
|
6281
|
+
DispatchQueue.main.async {
|
|
6282
|
+
UIScreen.main.brightness = CGFloat(min(max(level, 0), 1))
|
|
6283
|
+
self.resolveCallback(callbackId, result: Double(UIScreen.main.brightness))
|
|
6284
|
+
}
|
|
6285
|
+
}
|
|
6286
|
+
|
|
6239
6287
|
// MARK: - Speech Synthesis
|
|
6240
6288
|
//
|
|
6241
6289
|
// Native rather than the page's own `speechSynthesis`, which in a
|