@@ -133,8 +133,10 @@ const updateAppName = async (androidResDir, appName) => {
133133 }
134134}
135135
136- const updateWebEnv = async ( androidResDir , webUrl , debug ) => {
136+ const updateWebEnv = async ( androidResDir , webUrl , debug , webview ) => {
137137 try {
138+ const { userAgent } = webview
139+
138140 // Assuming MainActivity.kt is in the standard location
139141 const mainActivityPath = path . join (
140142 androidResDir . replace ( 'res' , '' ) ,
@@ -167,6 +169,15 @@ const updateWebEnv = async (androidResDir, webUrl, debug) => {
167169 'private var debug = true'
168170 )
169171 }
172+
173+ // update webview userAgent
174+ if ( userAgent ) {
175+ updatedContent = updatedContent . replace (
176+ '// webView.settings.userAgentString = ""' ,
177+ `webView.settings.userAgentString = "${ userAgent } "`
178+ )
179+ }
180+
170181 await fs . writeFile ( mainActivityPath , updatedContent )
171182 console . log ( `✅ Updated web URL to: ${ webUrl } ` )
172183 } catch ( error ) {
@@ -270,6 +281,7 @@ const updateAndroidId = async (id) => {
270281
271282// Main execution
272283const main = async ( ) => {
284+ const { webview } = ppconfig . phone
273285 const {
274286 name,
275287 version,
@@ -282,6 +294,7 @@ const main = async () => {
282294 showName,
283295 debug,
284296 } = ppconfig . android
297+
285298 const outPath = path . resolve ( output )
286299 await generateAdaptiveIcons ( input , outPath )
287300
@@ -293,7 +306,7 @@ const main = async () => {
293306 await updateAppName ( dest , showName )
294307
295308 // Update web URL if provided
296- await updateWebEnv ( dest , webUrl , debug )
309+ await updateWebEnv ( dest , webUrl , debug , webview )
297310
298311 // 删除根目录的res
299312 await fs . remove ( outPath )
@@ -309,12 +322,12 @@ const main = async () => {
309322}
310323
311324// run
312- try {
313- ; ( async ( ) => {
325+ ; ( async ( ) => {
326+ try {
314327 console . log ( '🚀 worker start' )
315328 await main ( )
316329 console . log ( '🚀 worker end' )
317- } ) ( )
318- } catch ( error ) {
319- console . error ( '❌ Worker Error:' , error )
320- }
330+ } catch ( error ) {
331+ console . error ( '❌ Worker Error:' , error )
332+ }
333+ } ) ( )
0 commit comments