refactor: 只保留 Web,移除 Capacitor 原生壳
删除 android/、ios/ 两个 Capacitor 原生工程与 capacitor.config.ts、 ionic.config.json,以及 scripts/android、scripts/ios.sh 构建脚本; 根与 apps/web 的 @capacitor/* 依赖和相关 npm scripts 一并移除。 Web 侧去掉原生分支:登录只走云乐坊容器授权面板或顶层重定向, 暗色模式不再改原生状态栏,移除 Android 物理返回键处理。 保留 @nuxtjs/ionic(Web UI 框架)、云乐坊 window.ylf 桥接与 PWA。 决策记录见 docs/decisions/0004-web-only.md。
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
import { Capacitor } from '@capacitor/core'
|
||||
import { StatusBar, Style } from '@capacitor/status-bar'
|
||||
import { ionDarkClass } from '~/constants'
|
||||
|
||||
/**
|
||||
@@ -13,24 +11,14 @@ export const useDarkMode = createSharedComposable(() => {
|
||||
const color = useColorMode()
|
||||
const isDark = computed(() => color.value === 'dark')
|
||||
|
||||
async function setLightMode() {
|
||||
function setLightMode() {
|
||||
document.documentElement.classList.remove(ionDarkClass)
|
||||
syncThemeColor('#f2f2f6')
|
||||
|
||||
if (Capacitor.isNativePlatform()) {
|
||||
await StatusBar.setStyle({ style: Style.Light })
|
||||
await StatusBar.setBackgroundColor({ color: '#f2f2f6ff' })
|
||||
}
|
||||
}
|
||||
|
||||
async function setDarkMode() {
|
||||
function setDarkMode() {
|
||||
document.documentElement.classList.add(ionDarkClass)
|
||||
syncThemeColor('#000000')
|
||||
|
||||
if (Capacitor.isNativePlatform()) {
|
||||
await StatusBar.setStyle({ style: Style.Dark })
|
||||
await StatusBar.setBackgroundColor({ color: '#ff000000' })
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -39,7 +27,7 @@ export const useDarkMode = createSharedComposable(() => {
|
||||
setLightMode,
|
||||
setDarkMode,
|
||||
|
||||
async toggleDark() {
|
||||
toggleDark() {
|
||||
const targetMode = color.value === 'dark' ? 'light' : 'dark'
|
||||
color.preference = targetMode
|
||||
|
||||
|
||||
@@ -1,18 +1,12 @@
|
||||
import type { NativeYunlefunAuthorizationAdapter } from '~/adapters/yunlefunAuth'
|
||||
import type {
|
||||
YunlefunAuthController,
|
||||
YunlefunAuthSnapshot,
|
||||
} from '~/utils/yunlefunAuth'
|
||||
import { App } from '@capacitor/app'
|
||||
import { Browser } from '@capacitor/browser'
|
||||
import { Capacitor } from '@capacitor/core'
|
||||
import {
|
||||
callCloudbaseFunction,
|
||||
createCloudbaseIdentityAdapter,
|
||||
createNativeYunlefunAuthorizationAdapter,
|
||||
createWebYunlefunAuthorizationAdapter,
|
||||
} from '~/adapters/yunlefunAuth'
|
||||
import { stripNativeSsoCallbackHash } from '~/utils/nativeSso'
|
||||
import { createYunlefunAuthController } from '~/utils/yunlefunAuth'
|
||||
import { resolveYunlefunSsoConfig } from '~/utils/yunlefunSsoConfig'
|
||||
|
||||
@@ -21,8 +15,6 @@ interface YunlefunRuntimeConfig {
|
||||
yunlefunCloudbaseEnv?: string
|
||||
yunlefunSsoClientId?: string
|
||||
yunlefunSsoExchangeUrl?: string
|
||||
yunlefunSsoNativeClientId?: string
|
||||
yunlefunSsoNativeRedirectUri?: string
|
||||
yunlefunSsoOrigin?: string
|
||||
yunlefunSsoRedirectUri?: string
|
||||
yunlefunSsoRedirectUris?: string
|
||||
@@ -32,10 +24,7 @@ interface YunlefunRuntimeConfig {
|
||||
|
||||
let controller: YunlefunAuthController | undefined
|
||||
let cloudbaseEnv = ''
|
||||
let nativeAdapter: NativeYunlefunAuthorizationAdapter | undefined
|
||||
let initialization: Promise<void> | undefined
|
||||
let nativeUrlListenerInstalled = false
|
||||
let handlingNativeCallback = false
|
||||
|
||||
export function useYunlefunAuth() {
|
||||
const runtimeConfig = useRuntimeConfig() as unknown as YunlefunRuntimeConfig
|
||||
@@ -98,35 +87,16 @@ async function initializeOnce(
|
||||
if (!import.meta.client)
|
||||
return
|
||||
|
||||
const platform = Capacitor.isNativePlatform() ? 'native' : 'web'
|
||||
if (platform === 'web'
|
||||
&& window.location.pathname === '/auth/callback'
|
||||
&& new URLSearchParams(window.location.search).get('platform') === 'native') {
|
||||
const sanitizedPath = stripNativeSsoCallbackHash(window.location.href)
|
||||
if (sanitizedPath)
|
||||
window.history.replaceState(window.history.state, '', sanitizedPath)
|
||||
configurationMessage.value = '未能自动返回 Cook,请确认已安装最新版应用后重新授权'
|
||||
snapshot.value = {
|
||||
account: null,
|
||||
errorMessage: '',
|
||||
status: 'signed-out',
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
const result = resolveYunlefunSsoConfig({
|
||||
clientId: runtimeConfig.public.yunlefunSsoClientId,
|
||||
cloudbaseEnv: runtimeConfig.public.yunlefunCloudbaseEnv,
|
||||
exchangeUrl: runtimeConfig.public.yunlefunSsoExchangeUrl,
|
||||
nativeClientId: runtimeConfig.public.yunlefunSsoNativeClientId,
|
||||
nativeRedirectUri: runtimeConfig.public.yunlefunSsoNativeRedirectUri,
|
||||
redirectUri: runtimeConfig.public.yunlefunSsoRedirectUri,
|
||||
redirectUris: runtimeConfig.public.yunlefunSsoRedirectUris,
|
||||
scope: runtimeConfig.public.yunlefunSsoScope,
|
||||
ssoOrigin: runtimeConfig.public.yunlefunSsoOrigin,
|
||||
}, {
|
||||
currentOrigin: window.location.origin,
|
||||
platform,
|
||||
})
|
||||
|
||||
if (!result.ok) {
|
||||
@@ -140,59 +110,14 @@ async function initializeOnce(
|
||||
}
|
||||
|
||||
cloudbaseEnv = result.config.cloudbaseEnv
|
||||
const web = createWebYunlefunAuthorizationAdapter(result.config)
|
||||
nativeAdapter = createNativeYunlefunAuthorizationAdapter(result.config, async () => {
|
||||
const launch = await App.getLaunchUrl()
|
||||
return launch?.url ?? null
|
||||
})
|
||||
controller = createYunlefunAuthController({
|
||||
identity: createCloudbaseIdentityAdapter(result.config),
|
||||
native: nativeAdapter,
|
||||
platform,
|
||||
web,
|
||||
web: createWebYunlefunAuthorizationAdapter(result.config),
|
||||
})
|
||||
|
||||
if (platform === 'native' && !nativeUrlListenerInstalled) {
|
||||
nativeUrlListenerInstalled = true
|
||||
await App.addListener('appUrlOpen', async ({ url }) => {
|
||||
if (!controller || !nativeAdapter)
|
||||
return
|
||||
|
||||
handlingNativeCallback = true
|
||||
try {
|
||||
const authorization = await nativeAdapter.consumeUrl(url)
|
||||
if (!authorization)
|
||||
return
|
||||
|
||||
await controller.handleAuthorization(authorization)
|
||||
publishSnapshot(snapshot)
|
||||
if (controller.snapshot().status === 'signed-in')
|
||||
await navigateTo('/my', { replace: true })
|
||||
}
|
||||
finally {
|
||||
handlingNativeCallback = false
|
||||
}
|
||||
})
|
||||
await Browser.addListener('browserFinished', async () => {
|
||||
if (!controller
|
||||
|| handlingNativeCallback
|
||||
|| controller.snapshot().status !== 'signing-in') {
|
||||
return
|
||||
}
|
||||
|
||||
await nativeAdapter?.cancel().catch(() => undefined)
|
||||
await controller.handleAuthorization({
|
||||
ok: false,
|
||||
reason: 'access_denied',
|
||||
})
|
||||
publishSnapshot(snapshot)
|
||||
})
|
||||
}
|
||||
|
||||
await controller.initialize()
|
||||
publishSnapshot(snapshot)
|
||||
if (platform === 'web'
|
||||
&& window.location.pathname === '/auth/callback'
|
||||
if (window.location.pathname === '/auth/callback'
|
||||
&& controller.snapshot().status === 'signed-in') {
|
||||
await navigateTo('/my', { replace: true })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user