3 changed files with 130 additions and 4 deletions
+108
View File
@@ -170,6 +170,114 @@ pub async fn open_url(app: tauri::AppHandle, url: String) -> Result<(), String>
.map_err(|e| e.to_string())
}
/// 切换移动端屏幕方向(iOS 原生旋转屏幕方向:横屏 Landscape / 竖屏 Portrait)。
#[tauri::command]
pub async fn set_orientation(app: tauri::AppHandle, landscape: bool) -> Result<(), String> {
#[cfg(target_os = "ios")]
{
let _ = app.run_on_main_thread(move || {
request_ios_orientation(landscape);
});
}
#[cfg(not(target_os = "ios"))]
{
let _ = (&app, landscape);
}
Ok(())
}
#[cfg(target_os = "ios")]
fn request_ios_orientation(landscape: bool) {
use std::ffi::{c_char, c_void};
extern "C" {
fn objc_getClass(name: *const c_char) -> *mut c_void;
fn sel_registerName(name: *const c_char) -> *mut c_void;
fn objc_msgSend();
}
unsafe {
let msg0: unsafe extern "C" fn(*mut c_void, *mut c_void) -> *mut c_void =
std::mem::transmute(objc_msgSend as *const ());
let msg0_usize: unsafe extern "C" fn(*mut c_void, *mut c_void) -> usize =
std::mem::transmute(objc_msgSend as *const ());
let msg1_usize: unsafe extern "C" fn(*mut c_void, *mut c_void, usize) -> *mut c_void =
std::mem::transmute(objc_msgSend as *const ());
let msg2_ptr: unsafe extern "C" fn(*mut c_void, *mut c_void, *mut c_void, *mut c_void) =
std::mem::transmute(objc_msgSend as *const ());
let msg1_void: unsafe extern "C" fn(*mut c_void, *mut c_void) =
std::mem::transmute(objc_msgSend as *const ());
// 1. iOS 16+ UIWindowScene.requestGeometryUpdateWithPreferences:errorHandler:
// UIInterfaceOrientationMaskPortrait = 1 << 1 = 2
// UIInterfaceOrientationMaskLandscapeRight = 1 << 3 = 8
let mask: usize = if landscape { 8 } else { 2 };
let prefs_cls = objc_getClass(b"UIWindowSceneGeometryPreferencesIOS\0".as_ptr() as *const c_char);
let app_cls = objc_getClass(b"UIApplication\0".as_ptr() as *const c_char);
if !prefs_cls.is_null() && !app_cls.is_null() {
let sel_alloc = sel_registerName(b"alloc\0".as_ptr() as *const c_char);
let sel_init = sel_registerName(b"initWithInterfaceOrientations:\0".as_ptr() as *const c_char);
let raw_prefs = msg0(prefs_cls, sel_alloc);
let prefs = if !raw_prefs.is_null() {
msg1_usize(raw_prefs, sel_init, mask)
} else {
std::ptr::null_mut()
};
let sel_shared = sel_registerName(b"sharedApplication\0".as_ptr() as *const c_char);
let app = msg0(app_cls, sel_shared);
if !app.is_null() && !prefs.is_null() {
let sel_scenes = sel_registerName(b"connectedScenes\0".as_ptr() as *const c_char);
let scenes_set = msg0(app, sel_scenes);
if !scenes_set.is_null() {
let sel_all = sel_registerName(b"allObjects\0".as_ptr() as *const c_char);
let arr = msg0(scenes_set, sel_all);
if !arr.is_null() {
let sel_count = sel_registerName(b"count\0".as_ptr() as *const c_char);
let sel_at = sel_registerName(b"objectAtIndex:\0".as_ptr() as *const c_char);
let sel_req = sel_registerName(
b"requestGeometryUpdateWithPreferences:errorHandler:\0".as_ptr() as *const c_char,
);
let sel_responds = sel_registerName(b"respondsToSelector:\0".as_ptr() as *const c_char);
let msg_responds: unsafe extern "C" fn(*mut c_void, *mut c_void, *mut c_void) -> bool =
std::mem::transmute(objc_msgSend as *const ());
let count = msg0_usize(arr, sel_count);
for i in 0..count {
let scene = msg1_usize(arr, sel_at, i);
if !scene.is_null() && msg_responds(scene, sel_responds, sel_req) {
msg2_ptr(scene, sel_req, prefs, std::ptr::null_mut());
}
}
}
}
}
}
// 2. Fallback: UIDevice setValue:forKey:@"orientation" + attemptRotationToDeviceOrientation
let dev_cls = objc_getClass(b"UIDevice\0".as_ptr() as *const c_char);
let num_cls = objc_getClass(b"NSNumber\0".as_ptr() as *const c_char);
let str_cls = objc_getClass(b"NSString\0".as_ptr() as *const c_char);
let vc_cls = objc_getClass(b"UIViewController\0".as_ptr() as *const c_char);
if !dev_cls.is_null() && !num_cls.is_null() && !str_cls.is_null() {
let sel_cur = sel_registerName(b"currentDevice\0".as_ptr() as *const c_char);
let dev = msg0(dev_cls, sel_cur);
let sel_num = sel_registerName(b"numberWithInteger:\0".as_ptr() as *const c_char);
let orient_val: usize = if landscape { 3 } else { 1 };
let num = msg1_usize(num_cls, sel_num, orient_val);
let sel_str = sel_registerName(b"stringWithUTF8String:\0".as_ptr() as *const c_char);
let msg_str: unsafe extern "C" fn(*mut c_void, *mut c_void, *const c_char) -> *mut c_void =
std::mem::transmute(objc_msgSend as *const ());
let key = msg_str(str_cls, sel_str, b"orientation\0".as_ptr() as *const c_char);
if !dev.is_null() && !num.is_null() && !key.is_null() {
let sel_set_val = sel_registerName(b"setValue:forKey:\0".as_ptr() as *const c_char);
msg2_ptr(dev, sel_set_val, num, key);
}
if !vc_cls.is_null() {
let sel_attempt = sel_registerName(b"attemptRotationToDeviceOrientation\0".as_ptr() as *const c_char);
msg1_void(vc_cls, sel_attempt);
}
}
}
}
/* ───────────────────────── 会话 ───────────────────────── */
#[tauri::command]
+1
View File
@@ -140,6 +140,7 @@ pub fn run() {
api::line_probe,
api::check_update,
api::open_url,
api::set_orientation,
api::api_login,
api::api_register,
api::api_logout,
+21 -4
View File
@@ -34,6 +34,7 @@
}
.plat-windows { --r-sm: 4px; --r-md: 8px; --r-lg: 8px; --r-ctl: 4px; --nav-h: 0px; }
.plat-macos { --r-sm: 6px; --r-md: 10px; --r-lg: 12px; --r-ctl: 6px; --nav-h: 0px; }
.plat-ios { --r-sm: 10px; --r-md: 14px; --r-lg: 18px; --r-ctl: 999px; -webkit-touch-callout: none; }
html.theme-light {
color-scheme: light;
--p-canvas: #f3f3f3;
@@ -152,7 +153,7 @@ html.theme-light .elev-3 { box-shadow: 0 10px 30px rgba(0,0,0,.1); }
.a-panel-out { animation: kf-panel-out .2s ease-in both; }
@keyframes kf-scale-in { from{opacity:0;transform:scale(.92)} to{opacity:1;transform:scale(1)} }
.a-scale-in { animation: kf-scale-in .22s cubic-bezier(.2,0,0,1) both; }
@keyframes kf-page-in { from{transform:translateX(100%)} to{transform:translateX(0)} }
@keyframes kf-page-in { from{transform:translateX(100%)} to{transform:none} }
.a-page-in { animation: kf-page-in .3s cubic-bezier(.2,0,0,1) both; }
@keyframes kf-page-out { from{transform:translateX(0)} to{transform:translateX(100%)} }
.a-page-out { animation: kf-page-out .22s cubic-bezier(.3,0,.8,.15) both; }
@@ -250,7 +251,8 @@ input[type="range"].hg-range::-webkit-slider-thumb { -webkit-appearance: none; w
原生全屏时红绿灯被系统隐藏(is-native-fs),让位收回,避免留一条空白。 */
.plat-macos .win-titlebar { padding-left: 84px; }
.plat-macos .win-titlebar.is-native-fs { padding-left: 14px; }
.plat-android .win-main { background: var(--p-bg); overflow: hidden; }
.plat-android .win-main,
.plat-ios .win-main { background: var(--p-bg); overflow: hidden; }
.win-page-in { animation: kf-page-in .26s cubic-bezier(.2,0,0,1) both; }
.win-page-out { animation: kf-page-out .2s ease-in both; }
@@ -483,13 +485,28 @@ input[type="range"].hg-range::-webkit-slider-thumb { -webkit-appearance: none; w
.player-surface .player-root,
.player-root { background: #15181d; }
/* —— 安卓沉浸全屏:横屏视频把舞台旋转 90°(不依赖系统旋转) —— */
/* —— 移动端沉浸全屏:固定铺满全屏视口,脱离外层滚动容器 scrollTop 影响 —— */
.fs-immersive {
position: fixed;
inset: 0;
width: 100vw; height: 100vh;
width: 100dvw; height: 100dvh;
z-index: 45;
background: #000;
overflow: hidden;
}
/* —— 移动端沉浸全屏(系统仍处于竖屏时的 CSS 90° 旋转兜底) —— */
.fs-landscape {
position: absolute;
position: fixed;
top: 50%; left: 50%; right: auto; bottom: auto;
width: 100vh; height: 100vw;
width: 100dvh; height: 100dvw;
transform: translate(-50%, -50%) rotate(90deg);
transform-origin: center center;
z-index: 45;
background: #000;
overflow: hidden;
}
.desktop-dock-panel {