Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/hap-server/src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ export default {
moduleList: []
}
}
export let browerOptions = {
options: {}
}
9 changes: 7 additions & 2 deletions packages/hap-server/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import { setCustomConfig, colorconsole } from '@hap-toolkit/shared-utils'
import config from './config'
import config, { browerOptions } from './config'
import { launch, stop } from './server'
import { remotePreview } from './preview/remote-preview'
import { beforeStart, createPreview } from './preview'
Expand Down Expand Up @@ -56,7 +56,12 @@ function launchServer(options) {
function stopServer() {
return stop()
}

/**
* 更新ide需要传给webView的参数
*/
export function updateWebViewOptions(options) {
browerOptions.options = Object.assign(browerOptions.options, options)
}
/**
* remotePreview IDE扫码预览的命令行实现
*/
Expand Down
5 changes: 3 additions & 2 deletions packages/hap-server/src/preview/create-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import util from 'util'
import KoaRouter from 'koa-router'
import koaSend from 'koa-send'
import JSZip from 'jszip'

import { browerOptions } from '../config'
import { KnownError, getLaunchPage, logger, eventBus } from '@hap-toolkit/shared-utils'

import { renderPage, trimSlash, removeAnsiColor } from './shared'
Expand Down Expand Up @@ -218,6 +218,7 @@ export default async function createRouter(previewTarget) {
const currentLanguage = JSON.parse(
process.env.VSCODE_NLS_CONFIG || '{"locale":"zh-CN"}'
).locale
const mediaQueryParams = browerOptions.options.mediaQueryParams || {}
const html = await renderPage(TPL_PAGE_PATH, {
title: manifest.name,
routeName: requestRoute,
Expand All @@ -227,7 +228,7 @@ export default async function createRouter(previewTarget) {
scriptNotFound: !scriptExists(script),
webJsUrl: genWebJsUrl(ctx.conf.options.webVersion),
language: currentLanguage,
mediaQueryParams: JSON.stringify(ctx.conf.options.mediaQueryParams) // 传给页面的媒介查询参数
mediaQueryParams: JSON.stringify(mediaQueryParams) // 传给页面的媒介查询参数
})
ctx.type = 'text/html'
ctx.body = html
Expand Down
6 changes: 3 additions & 3 deletions packages/hap-server/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ import {
globalConfig,
clearProjectRecord
} from '@hap-toolkit/shared-utils'

import { browerOptions } from './config'
const moduler = [require('@hap-toolkit/debugger')]

let server = null
export async function launch(conf) {
return new Promise(async (resolve) => {
Expand All @@ -34,7 +33,8 @@ export async function launch(conf) {
Object.assign(conf.defaults, { serverPort })
// 暴露环境配置
app.context.conf = conf

browerOptions.options = Object.assign(browerOptions.options, conf)
// console.log(browerOptions)
// 清空调试设备记录
const { clearRecords, openBrowser } = conf.options
if (clearRecords) {
Expand Down
13 changes: 11 additions & 2 deletions packages/hap-toolkit/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

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

/**
Expand Down Expand Up @@ -58,4 +58,13 @@ function launchWithWatch(options) {
})
}

export { compile, stopWatch, launchServer, stopServer, launchWithWatch, stopAll, BuildModeManager }
export {
compile,
stopWatch,
launchServer,
stopServer,
launchWithWatch,
stopAll,
BuildModeManager,
updateWebViewOptions
}
Loading