mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-19 14:52:40 +08:00
feat: expose screen keep-on control (#413)
This commit is contained in:
Vendored
+1
@@ -26,6 +26,7 @@ declare namespace jsb {
|
||||
export function getDeviceOrientation(): number;
|
||||
export function getNetworkType(): number; // TODO: enum type
|
||||
export function getSafeAreaEdge(): NativeSafeAreaEdge;
|
||||
export function setKeepScreenOn(enabled: boolean): void;
|
||||
|
||||
export function setAccelerometerEnabled(isEnabled: boolean);
|
||||
export function setAccelerometerInterval(intervalInSeconds: number);
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
*/
|
||||
|
||||
import { screenAdapter, IScreenOptions } from 'pal/screen-adapter';
|
||||
import { systemInfo } from 'pal/system-info';
|
||||
import { OS } from '../../../pal/system-info/enum-type';
|
||||
import { legacyCC } from '../global-exports';
|
||||
import { Size } from '../math';
|
||||
import { settings, SettingsCategory } from '../settings';
|
||||
@@ -101,6 +103,18 @@ export class Screen {
|
||||
return screenAdapter.devicePixelRatio;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Controls whether the screen stays on while the app is in the foreground.
|
||||
* Supported on native Android and iOS. Has no effect on other platforms.
|
||||
* @zh 控制应用在前台时是否保持屏幕常亮。仅在 Android 和 iOS 原生平台生效。
|
||||
* @param enabled @en Pass true to keep the screen on or false to restore normal screen timeout. @zh 传入 true 开启常亮,传入 false 恢复系统的自动熄屏行为。
|
||||
*/
|
||||
public setKeepScreenOn (enabled: boolean): void {
|
||||
if (systemInfo.isNative && (systemInfo.os === OS.ANDROID || systemInfo.os === OS.IOS)) {
|
||||
jsb.device.setKeepScreenOn(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Get and set the size of current window in physical pixels.
|
||||
* NOTE:
|
||||
|
||||
Reference in New Issue
Block a user