2020-07-13 09:29:16 +00:00
import "./shared" ;
2020-04-01 13:36:37 +00:00
import * as loader from "../loader/loader" ;
2020-08-07 23:03:19 +00:00
import { ApplicationLoader , SourcePath } from "../loader/loader" ;
2020-07-13 09:29:16 +00:00
import { script_name } from "../loader/utils" ;
2020-07-20 17:08:13 +00:00
import { loadManifest , loadManifestTarget } from "../maifest" ;
2019-08-30 21:06:39 +00:00
2020-03-30 11:44:18 +00:00
declare global {
interface Window {
native_client : boolean ;
2019-08-30 21:06:39 +00:00
}
2020-03-30 11:44:18 +00:00
}
2019-08-30 21:06:39 +00:00
2020-03-30 23:27:59 +00:00
function cache_tag() {
const ui = ui_version ( ) ;
return "?_ts=" + ( ! ! ui && ui !== "unknown" ? ui : Date.now ( ) ) ;
}
2020-03-30 11:44:18 +00:00
let _ui_version ;
export function ui_version() {
if ( typeof ( _ui_version ) !== "string" ) {
const version_node = document . getElementById ( "app_version" ) ;
if ( ! version_node ) return undefined ;
2019-08-30 21:06:39 +00:00
2020-03-30 11:44:18 +00:00
const version = version_node . hasAttribute ( "value" ) ? version_node . getAttribute ( "value" ) : undefined ;
if ( ! version ) return undefined ;
2019-08-30 21:06:39 +00:00
2020-03-30 11:44:18 +00:00
return ( _ui_version = version ) ;
2019-08-30 21:06:39 +00:00
}
2020-03-30 11:44:18 +00:00
return _ui_version ;
2019-08-30 21:06:39 +00:00
}
2020-07-13 09:29:16 +00:00
const LoaderTaskCallback = taskId = > ( script : SourcePath , state ) = > {
if ( state !== "loading" )
return ;
loader . setCurrentTaskName ( taskId , script_name ( script , false ) ) ;
} ;
2019-08-30 21:06:39 +00:00
/* all javascript loaders */
const loader_javascript = {
2020-07-13 09:29:16 +00:00
load_scripts : async taskId = > {
loader . setCurrentTaskName ( taskId , "manifest" ) ;
2020-07-20 17:08:13 +00:00
await loadManifest ( ) ;
await loadManifestTarget ( __build . entry_chunk_name , taskId ) ;
2019-08-30 21:06:39 +00:00
}
} ;
const loader_webassembly = {
test_webassembly : async ( ) = > {
/ * W e d o n t r e q u i r e d W e b A s s e m b l y a n y m o r e f o r f u n d a m e n t a l f u n c t i o n s , o n l y f o r a u t o d e c o d i n g
if ( typeof ( WebAssembly ) === "undefined" || typeof ( WebAssembly . compile ) === "undefined" ) {
console . log ( navigator . browserSpecs ) ;
if ( navigator . browserSpecs . name == 'Safari' ) {
if ( parseInt ( navigator . browserSpecs . version ) < 11 ) {
displayCriticalError ( "You require Safari 11 or higher to use the web client!<br>Safari " + navigator . browserSpecs . version + " does not support WebAssambly!" ) ;
return ;
}
}
else {
// Do something for all other browsers.
}
displayCriticalError ( "You require WebAssembly for TeaSpeak-Web!" ) ;
throw "Missing web assembly" ;
}
* /
}
} ;
loader . register_task ( loader . Stage . INITIALIZING , {
name : "secure tester" ,
function : async ( ) = > {
/* we need https or localhost to use some things like the storage API */
if ( typeof isSecureContext === "undefined" )
2020-07-13 09:29:16 +00:00
( < any > window ) [ "isSecureContext" ] = location . protocol !== 'https:' || location . hostname === 'localhost' ;
2019-08-30 21:06:39 +00:00
if ( ! isSecureContext ) {
loader . critical_error ( "TeaWeb cant run on unsecured sides." , "App requires to be loaded via HTTPS!" ) ;
throw "App requires a secure context!"
}
} ,
priority : 20
} ) ;
loader . register_task ( loader . Stage . INITIALIZING , {
name : "webassembly tester" ,
function : loader_webassembly . test_webassembly ,
priority : 20
} ) ;
loader . register_task ( loader . Stage . JAVASCRIPT , {
2020-07-13 09:29:16 +00:00
name : "scripts" ,
2019-08-30 21:06:39 +00:00
function : loader_javascript . load_scripts ,
priority : 10
} ) ;
loader . register_task ( loader . Stage . TEMPLATES , {
name : "templates" ,
2020-07-13 09:29:16 +00:00
function : async taskId = > {
2020-03-30 23:27:59 +00:00
await loader . templates . load_multiple ( [
2020-02-22 13:30:17 +00:00
"templates.html" ,
2020-03-27 15:15:15 +00:00
"templates/modal/musicmanage.html" ,
"templates/modal/newcomer.html" ,
2020-03-30 23:27:59 +00:00
] , {
cache_tag : cache_tag ( ) ,
max_parallel_requests : - 1
2020-07-13 09:29:16 +00:00
} , LoaderTaskCallback ( taskId ) ) ;
2020-02-22 13:30:17 +00:00
} ,
2019-08-30 21:06:39 +00:00
priority : 10
} ) ;
2019-08-31 16:31:01 +00:00
loader . register_task ( loader . Stage . SETUP , {
name : "page setup" ,
function : async ( ) = > {
const body = document . body ;
/* top menu */
{
const container = document . createElement ( "div" ) ;
container . setAttribute ( 'id' , "top-menu-bar" ) ;
body . append ( container ) ;
}
/* template containers */
{
const container = document . createElement ( "div" ) ;
container . setAttribute ( 'id' , "templates" ) ;
body . append ( container ) ;
}
/* sounds container */
{
const container = document . createElement ( "div" ) ;
container . setAttribute ( 'id' , "sounds" ) ;
body . append ( container ) ;
}
/* mouse move container */
{
const container = document . createElement ( "div" ) ;
container . setAttribute ( 'id' , "mouse-move" ) ;
body . append ( container ) ;
}
/* tooltip container */
{
const container = document . createElement ( "div" ) ;
container . setAttribute ( 'id' , "global-tooltip" ) ;
container . append ( document . createElement ( "a" ) ) ;
body . append ( container ) ;
}
} ,
priority : 10
} ) ;
2019-09-18 23:25:57 +00:00
/* test if we're getting loaded within a TeaClient preview window */
loader . register_task ( loader . Stage . SETUP , {
name : "TeaClient tester" ,
function : async ( ) = > {
//@ts-ignore
if ( typeof __teaclient_preview_notice !== "undefined" && typeof __teaclient_preview_error !== "undefined" ) {
loader . critical_error ( "Why you're opening TeaWeb within the TeaSpeak client?!" ) ;
throw "we're already a TeaClient!" ;
}
} ,
priority : 100
} ) ;
2020-07-20 17:08:13 +00:00
export default class implements ApplicationLoader {
execute() {
/* TeaClient */
2020-08-07 23:03:19 +00:00
if ( window . require ) {
2020-07-20 17:08:13 +00:00
if ( __build . target !== "client" ) {
loader . critical_error ( "App seems not to be compiled for the client." , "This app has been compiled for " + __build . target ) ;
return ;
}
window . native_client = true ;
2020-04-01 13:36:37 +00:00
2020-08-07 23:03:19 +00:00
const path = __non_webpack_require__ ( "path" ) ;
const remote = __non_webpack_require__ ( 'electron' ) . remote ;
2020-03-30 11:44:18 +00:00
2020-07-20 17:08:13 +00:00
const render_entry = path . join ( remote . app . getAppPath ( ) , "/modules/" , "renderer" ) ;
2020-08-07 23:03:19 +00:00
const render = __non_webpack_require__ ( render_entry ) ;
2020-04-01 13:36:37 +00:00
2020-07-20 17:08:13 +00:00
loader . register_task ( loader . Stage . INITIALIZING , {
name : "teaclient initialize" ,
function : render . initialize ,
priority : 40
} ) ;
} else {
if ( __build . target !== "web" ) {
loader . critical_error ( "App seems not to be compiled for the web." , "This app has been compiled for " + __build . target ) ;
return ;
}
2020-04-01 19:47:33 +00:00
2020-07-20 17:08:13 +00:00
window . native_client = false ;
}
2019-08-30 21:06:39 +00:00
2020-03-30 11:44:18 +00:00
loader . execute_managed ( ) ;
}
2019-08-30 21:06:39 +00:00
}