2018-02-27 16:20:49 +00:00
|
|
|
/// <reference path="chat.ts" />
|
|
|
|
/// <reference path="client.ts" />
|
|
|
|
/// <reference path="utils/modal.ts" />
|
2018-03-07 18:06:52 +00:00
|
|
|
/// <reference path="ui/modal/ModalConnect.ts" />
|
2018-04-16 18:38:35 +00:00
|
|
|
/// <reference path="ui/modal/ModalCreateChannel.ts" />
|
2018-10-20 17:58:06 +00:00
|
|
|
/// <reference path="ui/modal/ModalBanCreate.ts" />
|
2018-04-30 21:57:21 +00:00
|
|
|
/// <reference path="ui/modal/ModalBanClient.ts" />
|
2018-06-20 17:06:55 +00:00
|
|
|
/// <reference path="ui/modal/ModalYesNo.ts" />
|
2018-10-20 17:58:06 +00:00
|
|
|
/// <reference path="ui/modal/ModalBanList.ts" />
|
2018-04-11 15:56:09 +00:00
|
|
|
/// <reference path="settings.ts" />
|
2018-04-16 18:38:35 +00:00
|
|
|
/// <reference path="log.ts" />
|
2018-02-27 16:20:49 +00:00
|
|
|
|
2018-04-16 18:38:35 +00:00
|
|
|
let settings: Settings;
|
2018-04-11 15:56:09 +00:00
|
|
|
let globalClient: TSClient;
|
|
|
|
let chat: ChatBox;
|
|
|
|
|
2018-10-03 20:04:29 +00:00
|
|
|
const js_render = window.jsrender || $;
|
2018-10-06 13:13:45 +00:00
|
|
|
const native_client = window.require !== undefined;
|
|
|
|
|
2018-10-28 22:01:09 +00:00
|
|
|
function getUserMediaFunction() {
|
2018-12-23 21:56:04 +00:00
|
|
|
if((navigator as any).mediaDevices && (navigator as any).mediaDevices.getUserMedia)
|
|
|
|
return (settings, success, fail) => { (navigator as any).mediaDevices.getUserMedia(settings).then(success).catch(fail); };
|
|
|
|
return (navigator as any).getUserMedia || (navigator as any).webkitGetUserMedia || (navigator as any).mozGetUserMedia;
|
2018-10-28 22:01:09 +00:00
|
|
|
}
|
|
|
|
|
2018-10-06 13:13:45 +00:00
|
|
|
function setup_close() {
|
|
|
|
window.onbeforeunload = event => {
|
2018-12-28 14:39:23 +00:00
|
|
|
if(profiles.requires_save())
|
|
|
|
profiles.save();
|
2018-10-06 13:13:45 +00:00
|
|
|
|
2018-12-28 14:39:23 +00:00
|
|
|
if(!settings.static(Settings.KEY_DISABLE_UNLOAD_DIALOG, false)) {
|
|
|
|
if(!globalClient.serverConnection || !globalClient.serverConnection.connected) return;
|
2018-10-06 13:13:45 +00:00
|
|
|
|
2018-12-28 14:39:23 +00:00
|
|
|
if(!native_client) {
|
|
|
|
event.returnValue = "Are you really sure?<br>You're still connected!";
|
|
|
|
} else {
|
|
|
|
event.preventDefault();
|
|
|
|
event.returnValue = "question";
|
2018-10-06 13:13:45 +00:00
|
|
|
|
2018-12-28 14:39:23 +00:00
|
|
|
const {remote} = require('electron');
|
|
|
|
const dialog = remote.dialog;
|
|
|
|
|
|
|
|
dialog.showMessageBox(remote.getCurrentWindow(), {
|
2018-10-06 13:13:45 +00:00
|
|
|
type: 'question',
|
|
|
|
buttons: ['Yes', 'No'],
|
|
|
|
title: 'Confirm',
|
|
|
|
message: 'Are you really sure?\nYou\'re still connected!'
|
2018-12-28 14:39:23 +00:00
|
|
|
}, choice => {
|
|
|
|
if(choice === 0) {
|
|
|
|
window.onbeforeunload = undefined;
|
|
|
|
remote.getCurrentWindow().close();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2018-10-06 13:13:45 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2018-10-03 20:04:29 +00:00
|
|
|
|
2018-10-20 17:58:06 +00:00
|
|
|
declare function moment(...arguments) : any;
|
2018-10-14 11:27:48 +00:00
|
|
|
function setup_jsrender() : boolean {
|
2018-10-03 20:04:29 +00:00
|
|
|
if(!js_render) {
|
|
|
|
displayCriticalError("Missing jsrender extension!");
|
2018-10-14 11:27:48 +00:00
|
|
|
return false;
|
2018-10-03 20:04:29 +00:00
|
|
|
}
|
2018-10-07 16:21:28 +00:00
|
|
|
if(!js_render.views) {
|
|
|
|
displayCriticalError("Missing jsrender viewer extension!");
|
2018-10-14 11:27:48 +00:00
|
|
|
return false;
|
2018-10-07 16:21:28 +00:00
|
|
|
}
|
2018-10-03 20:04:29 +00:00
|
|
|
js_render.views.settings.allowCode(true);
|
|
|
|
js_render.views.tags("rnd", (argument) => {
|
2018-06-24 11:38:53 +00:00
|
|
|
let min = parseInt(argument.substr(0, argument.indexOf('~')));
|
|
|
|
let max = parseInt(argument.substr(argument.indexOf('~') + 1));
|
|
|
|
|
|
|
|
return (Math.round(Math.random() * (min + max + 1) - min)).toString();
|
|
|
|
});
|
2018-10-14 11:27:48 +00:00
|
|
|
|
2018-10-20 17:58:06 +00:00
|
|
|
js_render.views.tags("fmt_date", (...arguments) => {
|
|
|
|
return moment(arguments[0]).format(arguments[1]);
|
|
|
|
});
|
|
|
|
|
2018-12-08 22:13:33 +00:00
|
|
|
js_render.views.tags("tr", (...arguments) => {
|
|
|
|
return tr(arguments[0]);
|
|
|
|
});
|
|
|
|
|
2018-10-14 11:27:48 +00:00
|
|
|
$(".jsrender-template").each((idx, _entry) => {
|
|
|
|
if(!js_render.templates(_entry.id, _entry.innerHTML)) { //, _entry.innerHTML
|
|
|
|
console.error("Failed to cache template " + _entry.id + " for js render!");
|
|
|
|
} else
|
|
|
|
console.debug("Successfully loaded jsrender template " + _entry.id);
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-12-09 19:18:49 +00:00
|
|
|
async function initialize() {
|
2018-12-14 23:09:47 +00:00
|
|
|
const display_load_error = message => {
|
|
|
|
if(typeof(display_critical_load) !== "undefined")
|
|
|
|
display_critical_load(message);
|
|
|
|
else
|
|
|
|
displayCriticalError(message);
|
|
|
|
};
|
|
|
|
|
2018-12-15 12:06:41 +00:00
|
|
|
try {
|
|
|
|
await i18n.initialize();
|
|
|
|
} catch(error) {
|
|
|
|
console.error(tr("Failed to initialized the translation system!\nError: %o"), error);
|
|
|
|
displayCriticalError("Failed to setup the translation system");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-14 23:09:47 +00:00
|
|
|
try {
|
|
|
|
if(!setup_jsrender())
|
|
|
|
throw "invalid load";
|
|
|
|
} catch (error) {
|
|
|
|
display_load_error(tr("Failed to setup jsrender"));
|
|
|
|
console.error(tr("Failed to load jsrender! %o"), error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try { //Initialize main template
|
|
|
|
const main = $("#tmpl_main").renderTag();
|
|
|
|
$("body").append(main);
|
|
|
|
} catch(error) {
|
2018-12-30 00:38:13 +00:00
|
|
|
console.error(error);
|
2018-12-14 23:09:47 +00:00
|
|
|
display_load_error(tr("Failed to setup main page!"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-11 15:56:09 +00:00
|
|
|
AudioController.initializeAudioController();
|
2018-12-28 14:39:23 +00:00
|
|
|
if(!profiles.identities.setup_teamspeak()) {
|
2018-12-09 19:18:49 +00:00
|
|
|
console.error(tr("Could not setup the TeamSpeak identity parser!"));
|
2018-12-05 19:46:33 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-12-28 14:39:23 +00:00
|
|
|
profiles.load();
|
2018-04-11 15:56:09 +00:00
|
|
|
|
2018-12-09 19:18:49 +00:00
|
|
|
try {
|
|
|
|
await ppt.initialize();
|
|
|
|
} catch(error) {
|
|
|
|
console.error(tr("Failed to initialize ppt!\nError: %o"), error);
|
|
|
|
displayCriticalError(tr("Failed to initialize ppt!"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function main() {
|
|
|
|
//http://localhost:63343/Web-Client/index.php?_ijt=omcpmt8b9hnjlfguh8ajgrgolr&default_connect_url=true&default_connect_type=teamspeak&default_connect_url=localhost%3A9987&disableUnloadDialog=1&loader_ignore_age=1
|
|
|
|
|
2018-04-16 18:38:35 +00:00
|
|
|
settings = new Settings();
|
2018-03-24 22:38:01 +00:00
|
|
|
globalClient = new TSClient();
|
2018-04-11 15:56:09 +00:00
|
|
|
/** Setup the XF forum identity **/
|
2018-12-28 14:39:23 +00:00
|
|
|
profiles.identities.setup_forum();
|
2018-04-11 15:56:09 +00:00
|
|
|
|
2018-03-24 22:38:01 +00:00
|
|
|
chat = new ChatBox($("#chat"));
|
|
|
|
globalClient.setup();
|
2018-03-10 08:03:29 +00:00
|
|
|
|
2018-04-16 18:38:35 +00:00
|
|
|
|
2018-10-06 13:13:45 +00:00
|
|
|
if(!settings.static(Settings.KEY_DISABLE_UNLOAD_DIALOG, false) && !native_client) {
|
|
|
|
|
2018-04-16 18:38:35 +00:00
|
|
|
}
|
2018-03-24 22:38:01 +00:00
|
|
|
//Modals.spawnConnectModal();
|
|
|
|
//Modals.spawnSettingsModal();
|
2018-04-16 18:38:35 +00:00
|
|
|
//Modals.createChannelModal(undefined);
|
2018-03-24 22:38:01 +00:00
|
|
|
|
2018-12-30 00:38:13 +00:00
|
|
|
if(settings.static("connect_default") && settings.static("connect_address", "")) {
|
|
|
|
const profile_uuid = settings.static("connect_profile") as string;
|
|
|
|
const profile = profiles.find_profile(profile_uuid) || profiles.default_profile();
|
|
|
|
const address = settings.static("connect_address", "");
|
|
|
|
const username = settings.static("connect_username", "Another TeaSpeak user");
|
2018-04-30 21:57:21 +00:00
|
|
|
|
2018-12-30 00:38:13 +00:00
|
|
|
globalClient.startConnection(address, profile, username);
|
|
|
|
}
|
2018-04-30 21:57:21 +00:00
|
|
|
/*
|
2018-06-24 11:38:53 +00:00
|
|
|
let tag = $("#tmpl_music_frame").renderTag({
|
|
|
|
//thumbnail: "img/loading_image.svg"
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$("#music-test").replaceWith(tag);
|
2018-04-30 21:57:21 +00:00
|
|
|
|
2018-10-28 17:25:43 +00:00
|
|
|
Modals.spawnSettingsModal();
|
2018-06-20 17:06:55 +00:00
|
|
|
/*
|
|
|
|
Modals.spawnYesNo("Are your sure?", "Do you really want to exit?", flag => {
|
|
|
|
console.log("Response: " + flag);
|
|
|
|
})
|
|
|
|
*/
|
2018-09-30 19:50:59 +00:00
|
|
|
|
2018-10-06 13:13:45 +00:00
|
|
|
setup_close();
|
2018-11-03 23:39:29 +00:00
|
|
|
|
|
|
|
let _resize_timeout: NodeJS.Timer;
|
2018-10-06 13:13:45 +00:00
|
|
|
$(window).on('resize', () => {
|
2018-11-03 23:39:29 +00:00
|
|
|
if(_resize_timeout)
|
|
|
|
clearTimeout(_resize_timeout);
|
|
|
|
_resize_timeout = setTimeout(() => {
|
|
|
|
globalClient.channelTree.handle_resized();
|
|
|
|
}, 1000);
|
2018-10-06 13:13:45 +00:00
|
|
|
});
|
2018-04-19 16:42:34 +00:00
|
|
|
}
|
|
|
|
|
2018-12-30 00:38:13 +00:00
|
|
|
loader.register_task(loader.Stage.LOADED, {
|
|
|
|
name: "async main invoke",
|
|
|
|
function: async () => {
|
|
|
|
try {
|
|
|
|
await initialize();
|
|
|
|
main();
|
|
|
|
if(!audio.player.initialized()) {
|
|
|
|
log.info(LogCategory.VOICE, tr("Initialize audio controller later!"));
|
|
|
|
if(!audio.player.initializeFromGesture) {
|
|
|
|
console.error(tr("Missing audio.player.initializeFromGesture"));
|
|
|
|
} else
|
|
|
|
$(document).one('click', event => audio.player.initializeFromGesture());
|
|
|
|
}
|
|
|
|
} catch (ex) {
|
|
|
|
console.error(ex.stack);
|
|
|
|
if(ex instanceof ReferenceError || ex instanceof TypeError)
|
|
|
|
ex = ex.name + ": " + ex.message;
|
|
|
|
displayCriticalError("Failed to invoke main function:<br>" + ex);
|
2018-09-25 15:39:38 +00:00
|
|
|
}
|
2018-12-30 00:38:13 +00:00
|
|
|
},
|
|
|
|
priority: 10
|
2018-10-06 13:13:45 +00:00
|
|
|
});
|
2018-12-30 00:38:13 +00:00
|
|
|
|