@@ -43,6 +43,10 @@ const tippyConfig = {
4343 touch : /** @type {['hold', number] } */ ( [ 'hold' , 400 ] ) ,
4444} ;
4545
46+ const inWebview = '__webview__' in window ;
47+ if ( inWebview )
48+ document . documentElement . setAttribute ( 'webview' , '' ) ;
49+
4650Object . defineProperty ( Object . prototype , 'hasTitle' , {
4751 enumerable : false ,
4852 value ( ) {
@@ -73,7 +77,9 @@ let initBlocker = Promise.resolve();
7377async function injectScripts ( ) {
7478 const supportsSimd = await wasmFeatureDetect . simd ( ) ;
7579
76- let scripts = [ 'chat.js' , 'playerlist.js' , 'friends.js' , 'parties.js' , 'system.js' , 'preloads.js' , 'locations.js' , 'schedules.js' , 'report.js' , 'notifications.js' , '2kki.js' , 'play.js' , 'gamecanvas.js' , `ynoengine${ supportsSimd ? '-simd' : '' } .js` ] ;
80+ let scripts = [ 'chat.js' , 'playerlist.js' , 'friends.js' , 'parties.js' , 'system.js' , 'preloads.js' , 'locations.js' , 'schedules.js' , 'report.js' , 'notifications.js' , '2kki.js' , 'play.js' , 'gamecanvas.js' ] ;
81+ if ( ! inWebview )
82+ scripts . push ( `ynoengine${ supportsSimd ? '-simd' : '' } .js` ) ;
7783
7884 dependencyFiles [ 'play.css' ] = null ;
7985
@@ -98,12 +104,18 @@ async function injectScripts() {
98104 if ( gameId === '2kki' ) {
99105 gameVersion = document . querySelector ( 'meta[name="2kkiVersion"]' ) ?. content ?. replace ( ' Patch ' , 'p' ) ;
100106 }
107+
108+ if ( inWebview && ! getCookie ( sessionIdKey ) ) {
109+ setCookie ( sessionIdKey , await webviewSessionToken ( ) ) ;
110+ }
101111
102112 easyrpgPlayerLoadFuncs . push ( ( ) => {
103- easyrpgPlayer . initialized = true ;
104- easyrpgPlayer . api . setNametagMode ( config . nametagMode ) ;
105- easyrpgPlayer . api . setSoundVolume ( globalConfig . soundVolume ) ;
106- easyrpgPlayer . api . setMusicVolume ( globalConfig . musicVolume ) ;
113+ if ( ! inWebview ) {
114+ easyrpgPlayer . initialized = true ;
115+ easyrpgPlayer . api . setNametagMode ( config . nametagMode ) ;
116+ easyrpgPlayer . api . setSoundVolume ( globalConfig . soundVolume ) ;
117+ easyrpgPlayer . api . setMusicVolume ( globalConfig . musicVolume ) ;
118+ }
107119 const loadingOverlay = document . getElementById ( 'loadingOverlay' ) ;
108120 removeLoader ( loadingOverlay ) ;
109121 checkShowVersionUpdate ( ) . then ( ( ) => loadingOverlay . classList . add ( 'loaded' ) ) ;
@@ -114,14 +126,19 @@ async function injectScripts() {
114126 setInterval ( checkDependenciesModified , 300000 ) ;
115127 } , 10000 ) ;
116128 window . onbeforeunload = function ( ) {
117- return localizedMessages . leavePage ;
129+ if ( ! inWebview )
130+ return localizedMessages . leavePage ;
118131 } ;
119132 } ) ;
120133 if ( typeof onResize !== 'undefined' )
121134 easyrpgPlayerLoadFuncs . push ( onResize ) ;
122135
123136 await initBlocker ;
124137
138+ if ( inWebview )
139+ for ( let loadFunc of easyrpgPlayerLoadFuncs )
140+ loadFunc ( ) ;
141+ else
125142 createEasyRpgPlayer ( easyrpgPlayer )
126143 . then ( function ( Module ) {
127144 // Module is ready
@@ -816,7 +833,7 @@ function loadOrInitConfig(configObj, global, configName) {
816833 case 'rulesReviewed' :
817834 break ;
818835 }
819- } else {
836+ } else { // !global
820837 switch ( key ) {
821838 case 'privateMode' :
822839 if ( value )
0 commit comments