@@ -44,6 +44,10 @@ const tippyConfig = {
4444 touch : /** @type {['hold', number] } */ ( [ 'hold' , 400 ] ) ,
4545} ;
4646
47+ const inWebview = '__webview__' in window ;
48+ if ( inWebview )
49+ document . documentElement . setAttribute ( 'webview' , '' ) ;
50+
4751Object . defineProperty ( Object . prototype , 'hasTitle' , {
4852 enumerable : false ,
4953 value ( ) {
@@ -74,7 +78,9 @@ let initBlocker = Promise.resolve();
7478async function injectScripts ( ) {
7579 const supportsSimd = await wasmFeatureDetect . simd ( ) ;
7680
77- 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` ] ;
81+ 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' ] ;
82+ if ( ! inWebview )
83+ scripts . push ( `ynoengine${ supportsSimd ? '-simd' : '' } .js` ) ;
7884
7985 dependencyFiles [ 'play.css' ] = null ;
8086
@@ -99,12 +105,18 @@ async function injectScripts() {
99105 if ( gameId === '2kki' ) {
100106 gameVersion = document . querySelector ( 'meta[name="2kkiVersion"]' ) ?. content ?. replace ( ' Patch ' , 'p' ) ;
101107 }
108+
109+ if ( inWebview && ! getCookie ( sessionIdKey ) ) {
110+ setCookie ( sessionIdKey , await webviewSessionToken ( ) ) ;
111+ }
102112
103113 easyrpgPlayerLoadFuncs . push ( ( ) => {
104- easyrpgPlayer . initialized = true ;
105- easyrpgPlayer . api . setNametagMode ( config . nametagMode ) ;
106- easyrpgPlayer . api . setSoundVolume ( globalConfig . soundVolume ) ;
107- easyrpgPlayer . api . setMusicVolume ( globalConfig . musicVolume ) ;
114+ if ( ! inWebview ) {
115+ easyrpgPlayer . initialized = true ;
116+ easyrpgPlayer . api . setNametagMode ( config . nametagMode ) ;
117+ easyrpgPlayer . api . setSoundVolume ( globalConfig . soundVolume ) ;
118+ easyrpgPlayer . api . setMusicVolume ( globalConfig . musicVolume ) ;
119+ }
108120 const loadingOverlay = document . getElementById ( 'loadingOverlay' ) ;
109121 removeLoader ( loadingOverlay ) ;
110122 checkShowVersionUpdate ( ) . then ( ( ) => loadingOverlay . classList . add ( 'loaded' ) ) ;
@@ -115,14 +127,19 @@ async function injectScripts() {
115127 setInterval ( checkDependenciesModified , 300000 ) ;
116128 } , 10000 ) ;
117129 window . onbeforeunload = function ( ) {
118- return localizedMessages . leavePage ;
130+ if ( ! inWebview )
131+ return localizedMessages . leavePage ;
119132 } ;
120133 } ) ;
121134 if ( typeof onResize !== 'undefined' )
122135 easyrpgPlayerLoadFuncs . push ( onResize ) ;
123136
124137 await initBlocker ;
125138
139+ if ( inWebview )
140+ for ( let loadFunc of easyrpgPlayerLoadFuncs )
141+ loadFunc ( ) ;
142+ else
126143 createEasyRpgPlayer ( easyrpgPlayer )
127144 . then ( function ( Module ) {
128145 // Module is ready
@@ -846,7 +863,7 @@ function loadOrInitConfig(configObj, global, configName) {
846863 case 'rulesReviewed' :
847864 break ;
848865 }
849- } else {
866+ } else { // !global
850867 switch ( key ) {
851868 case 'privateMode' :
852869 if ( value )
0 commit comments