提交 151bb8a6 编写于 作者: fxy060608's avatar fxy060608

fix(app): splashscreen

上级 4ba1e9ab
......@@ -12101,7 +12101,7 @@ var serviceContext = (function (vue) {
}
function initSubscribeHandlers() {
const { subscribe, subscribeHandler } = UniServiceJSBridge;
const { subscribe, subscribeHandler, publishHandler } = UniServiceJSBridge;
onPlusMessage('subscribeHandler', ({ type, data, pageId }) => {
subscribeHandler(type, data, pageId);
});
......@@ -12118,6 +12118,11 @@ var serviceContext = (function (vue) {
subscribe(WEBVIEW_INSERTED, onWebviewInserted);
subscribe(WEBVIEW_REMOVED, onWebviewRemoved);
subscribe(ON_WXS_INVOKE_CALL_METHOD, onWxsInvokeCallMethod);
const routeOptions = getRouteOptions('/' + __uniConfig.entryPagePath);
if (routeOptions && !routeOptions.meta.isNVue) {
// 防止首页 webview 初始化过早, service 还未开始监听
publishHandler(ON_WEBVIEW_READY, {}, 1);
}
}
}
......
因为 它太大了无法显示 source diff 。你可以改为 查看blob
import { subscribeServiceMethod } from '@dcloudio/uni-core'
import { getRouteOptions, subscribeServiceMethod } from '@dcloudio/uni-core'
import {
ON_WXS_INVOKE_CALL_METHOD,
WEB_INVOKE_APPSERVICE,
......@@ -22,7 +22,7 @@ import {
import { onWxsInvokeCallMethod } from './wxs'
export function initSubscribeHandlers() {
const { subscribe, subscribeHandler } = UniServiceJSBridge
const { subscribe, subscribeHandler, publishHandler } = UniServiceJSBridge
onPlusMessage<{ type: string; data: Record<string, any>; pageId: number }>(
'subscribeHandler',
......@@ -48,5 +48,11 @@ export function initSubscribeHandlers() {
subscribe(WEBVIEW_INSERTED, onWebviewInserted)
subscribe(WEBVIEW_REMOVED, onWebviewRemoved)
subscribe(ON_WXS_INVOKE_CALL_METHOD, onWxsInvokeCallMethod)
const routeOptions = getRouteOptions('/' + __uniConfig.entryPagePath)
if (routeOptions && !routeOptions.meta.isNVue) {
// 防止首页 webview 初始化过早, service 还未开始监听
publishHandler(ON_WEBVIEW_READY, {}, 1)
}
}
}
import { useI18n } from '@dcloudio/uni-core'
import { SET_LOCALE_API, VD_SYNC } from '../../../constants'
import { ON_WEBVIEW_READY, SET_LOCALE_API, VD_SYNC } from '../../../constants'
import { onVdSync } from '../dom'
export function initSubscribeHandlers() {
const { subscribe } = UniViewJSBridge
subscribe(VD_SYNC, onVdSync)
subscribe(SET_LOCALE_API, useI18n().setLocale)
subscribe(ON_WEBVIEW_READY, onWebviewReady)
}
// service 主动会发起检测
function onWebviewReady() {
UniViewJSBridge.publishHandler('webviewReady')
}
......@@ -26,17 +26,22 @@ export function initSplashscreen(
}
manifestJson.plus.splashscreen.autoclose = true
manifestJson.plus.splashscreen.delay = 0
// 简单起见,直接设置环境变量,这样生成uniConfig时,直接读取判断
process.env.UNI_SPLASHSCREEN_ALWAYSSHOWBEFORERENDER = 'true'
} else {
// 不启用白屏检测
delete manifestJson.plus.splashscreen.target
if (manifestJson.plus.splashscreen.autoclose) {
// 启用 uni-app 框架关闭 splash
manifestJson.plus.splashscreen.autoclose = false // 原 5+ autoclose 改为 false
// 简单起见,直接设置环境变量,这样生成uniConfig时,直接读取判断
process.env.UNI_SPLASHSCREEN_AUTOCLOSE = 'true'
}
}
delete manifestJson.plus.splashscreen.alwaysShowBeforeRender
}
export function getSplashscreen(manifestJson: Record<string, any>) {
const splashscreenOptions = manifestJson['app-plus']?.splashscreen
return {
autoclose: splashscreenOptions.autoclose !== false,
alwaysShowBeforeRender:
splashscreenOptions.alwaysShowBeforeRender !== false,
}
}
......@@ -6,6 +6,7 @@ import {
getNVueFlexDirection,
getNVueStyleCompiler,
} from '../manifest'
import { getSplashscreen } from '../manifest/splashscreen'
interface AppUniConfig {
pages: string[]
......@@ -39,6 +40,7 @@ export function normalizeAppUniConfig(
pagesJson: UniApp.PagesJson,
manifestJson: Record<string, any>
) {
const { autoclose, alwaysShowBeforeRender } = getSplashscreen(manifestJson)
const config: AppUniConfig = {
pages: [],
globalStyle: pagesJson.globalStyle,
......@@ -51,11 +53,8 @@ export function normalizeAppUniConfig(
manifestJson['app-plus']?.renderer === 'native' ? 'native' : 'auto',
appname: manifestJson.name || '',
splashscreen: {
alwaysShowBeforeRender: process.env
.UNI_SPLASHSCREEN_ALWAYSSHOWBEFORERENDER
? true
: false,
autoclose: process.env.UNI_SPLASHSCREEN_AUTOCLOSE ? true : false,
alwaysShowBeforeRender,
autoclose,
},
compilerVersion: process.env.UNI_COMPILER_VERSION,
entryPagePath: pagesJson.pages[0].path,
......
......@@ -6,6 +6,7 @@ import resolve from 'resolve'
import { once } from '@dcloudio/uni-shared'
import { normalizePath } from './utils'
import { isInHBuilderX } from './hbx/env'
const DEFAULT_EXTENSIONS = ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json']
function resolveWithSymlinks(id: string, basedir: string): string {
......@@ -16,6 +17,7 @@ function resolveWithSymlinks(id: string, basedir: string): string {
preserveSymlinks: true,
})
}
export function relativeFile(from: string, to: string) {
const relativePath = normalizePath(path.relative(path.dirname(from), to))
return relativePath.startsWith('.') ? relativePath : './' + relativePath
......@@ -53,23 +55,25 @@ function initPaths() {
if (cliContext) {
const pathSet = new Set<string>()
pathSet.add(path.join(cliContext, 'node_modules'))
;[`@dcloudio/uni-` + process.env.UNI_PLATFORM, ...ownerModules].forEach(
(ownerModule) => {
let pkgPath: string = ''
try {
pkgPath = require.resolve(ownerModule + '/package.json', {
paths: [cliContext],
})
} catch (e) {}
if (pkgPath) {
resolveNodeModulePath(path.dirname(pkgPath)).forEach(
(nodeModulePath) => {
pathSet.add(nodeModulePath)
}
)
if (!isInHBuilderX()) {
;[`@dcloudio/uni-` + process.env.UNI_PLATFORM, ...ownerModules].forEach(
(ownerModule) => {
let pkgPath: string = ''
try {
pkgPath = require.resolve(ownerModule + '/package.json', {
paths: [cliContext],
})
} catch (e) {}
if (pkgPath) {
resolveNodeModulePath(path.dirname(pkgPath)).forEach(
(nodeModulePath) => {
pathSet.add(nodeModulePath)
}
)
}
}
}
)
)
}
paths.push(...pathSet)
debug('uni-paths')(paths)
}
......@@ -89,13 +93,20 @@ export function resolveBuiltIn(path: string) {
let componentsLibPath: string = ''
export function resolveComponentsLibPath() {
if (!componentsLibPath) {
componentsLibPath = path.join(
resolveWithSymlinks(
'@dcloudio/uni-components/package.json',
process.env.UNI_INPUT_DIR
),
'../lib'
)
if (isInHBuilderX()) {
componentsLibPath = path.join(
resolveBuiltIn('@dcloudio/uni-components/package.json'),
'../lib'
)
} else {
componentsLibPath = path.join(
resolveWithSymlinks(
'@dcloudio/uni-components/package.json',
process.env.UNI_INPUT_DIR
),
'../lib'
)
}
}
return componentsLibPath
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册