Skip to content

Commit c4a93df

Browse files
oneyouziyucongshuang
andauthored
新增一个方法更新需要传给webview的参数 (#105)
* 新增改变参数的方法 * 新增改变参数的方法 --------- Co-authored-by: yucongshuang <[email protected]>
1 parent fe8c76f commit c4a93df

File tree

5 files changed

+27
-9
lines changed

5 files changed

+27
-9
lines changed

packages/hap-server/src/config/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ export default {
1616
moduleList: []
1717
}
1818
}
19+
export let browerOptions = {
20+
options: {}
21+
}

packages/hap-server/src/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import { setCustomConfig, colorconsole } from '@hap-toolkit/shared-utils'
7-
import config from './config'
7+
import config, { browerOptions } from './config'
88
import { launch, stop } from './server'
99
import { remotePreview } from './preview/remote-preview'
1010
import { beforeStart, createPreview } from './preview'
@@ -56,7 +56,12 @@ function launchServer(options) {
5656
function stopServer() {
5757
return stop()
5858
}
59-
59+
/**
60+
* 更新ide需要传给webView的参数
61+
*/
62+
export function updateWebViewOptions(options) {
63+
browerOptions.options = Object.assign(browerOptions.options, options)
64+
}
6065
/**
6166
* remotePreview IDE扫码预览的命令行实现
6267
*/

packages/hap-server/src/preview/create-router.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import util from 'util'
1010
import KoaRouter from 'koa-router'
1111
import koaSend from 'koa-send'
1212
import JSZip from 'jszip'
13-
13+
import { browerOptions } from '../config'
1414
import { KnownError, getLaunchPage, logger, eventBus } from '@hap-toolkit/shared-utils'
1515

1616
import { renderPage, trimSlash, removeAnsiColor } from './shared'
@@ -218,6 +218,7 @@ export default async function createRouter(previewTarget) {
218218
const currentLanguage = JSON.parse(
219219
process.env.VSCODE_NLS_CONFIG || '{"locale":"zh-CN"}'
220220
).locale
221+
const mediaQueryParams = browerOptions.options.mediaQueryParams || {}
221222
const html = await renderPage(TPL_PAGE_PATH, {
222223
title: manifest.name,
223224
routeName: requestRoute,
@@ -227,7 +228,7 @@ export default async function createRouter(previewTarget) {
227228
scriptNotFound: !scriptExists(script),
228229
webJsUrl: genWebJsUrl(ctx.conf.options.webVersion),
229230
language: currentLanguage,
230-
mediaQueryParams: JSON.stringify(ctx.conf.options.mediaQueryParams) // 传给页面的媒介查询参数
231+
mediaQueryParams: JSON.stringify(mediaQueryParams) // 传给页面的媒介查询参数
231232
})
232233
ctx.type = 'text/html'
233234
ctx.body = html

packages/hap-server/src/server.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ import {
1414
globalConfig,
1515
clearProjectRecord
1616
} from '@hap-toolkit/shared-utils'
17-
17+
import { browerOptions } from './config'
1818
const moduler = [require('@hap-toolkit/debugger')]
19-
2019
let server = null
2120
export async function launch(conf) {
2221
return new Promise(async (resolve) => {
@@ -34,7 +33,8 @@ export async function launch(conf) {
3433
Object.assign(conf.defaults, { serverPort })
3534
// 暴露环境配置
3635
app.context.conf = conf
37-
36+
browerOptions.options = Object.assign(browerOptions.options, conf)
37+
// console.log(browerOptions)
3838
// 清空调试设备记录
3939
const { clearRecords, openBrowser } = conf.options
4040
if (clearRecords) {

packages/hap-toolkit/src/index.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import { BuildModeManager } from '@hap-toolkit/shared-utils'
7-
import { launchServer, stopServer } from '@hap-toolkit/server'
7+
import { launchServer, stopServer, updateWebViewOptions } from '@hap-toolkit/server'
88
import { compile, stopWatch } from './commands/compile'
99

1010
/**
@@ -58,4 +58,13 @@ function launchWithWatch(options) {
5858
})
5959
}
6060

61-
export { compile, stopWatch, launchServer, stopServer, launchWithWatch, stopAll, BuildModeManager }
61+
export {
62+
compile,
63+
stopWatch,
64+
launchServer,
65+
stopServer,
66+
launchWithWatch,
67+
stopAll,
68+
BuildModeManager,
69+
updateWebViewOptions
70+
}

0 commit comments

Comments
 (0)