<script>
	import {
		connectWs,
		closeWs
	} from '@/common/websocketManager.js';
	let globalWs = null;

	export default {
		onLaunch() {
			// #ifdef APP-PLUS
			// 检测是否为 Android
			if (plus.os.name === 'Android') {
				// 隐藏虚拟按键（底部横线）
				const mainActivity = plus.android.runtimeMainActivity();
				const Window = plus.android.importClass('android.view.Window');
				const View = plus.android.importClass('android.view.View');
			
				const window = mainActivity.getWindow();
				const decorView = window.getDecorView();
			
				// 隐藏导航栏
				const uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
					| View.SYSTEM_UI_FLAG_FULLSCREEN
					| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
			
				plus.android.invoke(decorView, 'setSystemUiVisibility', uiOptions);
			
				// 监听焦点变化，防止导航栏重新显示
				decorView.setOnSystemUiVisibilityChangeListener(
					new plus.android.implements('OnSystemUiVisibilityChangeListener', {
						onSystemUiVisibilityChange: function (visibility) {
							if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) === 0) {
								plus.android.invoke(decorView, 'setSystemUiVisibility', uiOptions);
							}
						}
					})
				);
			}
			// #endif
			
		},

		onShow() {
			console.log('App Show');
			if (uni.getStorageSync('userInfo')) {
				// 重置重连计数，确保立即重连
				connectWs()
			}
		},

		onHide() {
			console.log('App Hide');
			if (uni.getStorageSync('userInfo')) {
				// 可选择关闭 socket，或只是停止心跳
				closeWs()
			}
		}
	}
</script>

<style lang="scss">
	@import "./uni_modules/vk-uview-ui/index.scss";
	/* 每个页面公共css */
</style>