Add app api

This commit is contained in:
2025-01-20 15:18:16 +08:00
parent 27e7356721
commit 6033a3cde9
2 changed files with 38 additions and 0 deletions

View File

@@ -1310,3 +1310,37 @@ let UI = {
}) })
} }
} }
/**
* App related apis
* @since 1.2.1
*/
let APP = {
/**
* Get the app version
* @returns {string} - The app version
*/
get version() {
return appVersion // defined in the engine
},
/**
* Get current app locale
* @returns {string} - The app locale, in the format of [languageCode]_[countryCode]
*/
get locale() {
return sendMessage({
method: 'getLocale'
})
},
/**
* Get current running platform
* @returns {string} - The platform name, "android", "ios", "windows", "macos", "linux"
*/
get platform() {
return sendMessage({
method: 'getPlatform'
})
}
}

View File

@@ -155,6 +155,10 @@ class JsEngine with _JSEngineApi, JsUiApi {
return Future.delayed(Duration(milliseconds: message["time"])); return Future.delayed(Duration(milliseconds: message["time"]));
case "UI": case "UI":
return handleUIMessage(Map.from(message)); return handleUIMessage(Map.from(message));
case "getLocale":
return "${App.locale.languageCode}-${App.locale.countryCode}";
case "getPlatform":
return Platform.operatingSystem;
} }
} }
return null; return null;