mirror of
https://git.undefined-dev.fr/Blendman974/faceclaw.git
synced 2026-11-19 21:03:09 +00:00
31 lines
1.3 KiB
TypeScript
31 lines
1.3 KiB
TypeScript
import { Application, isAndroid } from "@nativescript/core";
|
|
import { getStringSetting, onSettingsStoreChanged } from "./settings-store";
|
|
|
|
// Shared with phoneRotationSetting; keep startup independent of the glasses UI.
|
|
const ROTATION_KEY = "phone.rotation";
|
|
|
|
/** Installed once on the UI thread; also covers navigation and activity recreation. */
|
|
export function registerPhoneRotation(): void {
|
|
if (!isAndroid) return;
|
|
|
|
const apply = (activity = Application.android.foregroundActivity ?? Application.android.startActivity): void => {
|
|
if (!activity) return;
|
|
const orientations = android.content.pm.ActivityInfo;
|
|
const requested = {
|
|
auto: orientations.SCREEN_ORIENTATION_UNSPECIFIED,
|
|
portrait: orientations.SCREEN_ORIENTATION_PORTRAIT,
|
|
landscape: orientations.SCREEN_ORIENTATION_SENSOR_LANDSCAPE,
|
|
}[getStringSetting(ROTATION_KEY, "auto")] ?? orientations.SCREEN_ORIENTATION_UNSPECIFIED;
|
|
if (activity.getRequestedOrientation() !== requested) {
|
|
activity.setRequestedOrientation(requested);
|
|
}
|
|
};
|
|
|
|
Application.android.on(Application.android.activityCreatedEvent, (args) => apply(args.activity));
|
|
Application.android.on(Application.android.activityResumedEvent, (args) => apply(args.activity));
|
|
onSettingsStoreChanged((key) => {
|
|
if (key === ROTATION_KEY) apply();
|
|
});
|
|
apply();
|
|
}
|