Fixed js render setup for the client

canary
WolverinDEV 2020-08-23 10:48:15 +02:00
parent 7100e090ad
commit 41edb6053e
4 changed files with 43 additions and 40 deletions

View File

@ -1,4 +1,3 @@
import * as moment from "moment";
import * as loader from "tc-loader";
import {settings, Settings} from "tc-shared/settings";
import * as profiles from "tc-shared/profiles/ConnectionProfile";
@ -31,6 +30,8 @@ import {global_client_actions} from "tc-shared/events/GlobalEvents";
import {FileTransferState, TransferProvider,} from "tc-shared/file/Transfer";
import {MenuEntryType, spawn_context_menu} from "tc-shared/ui/elements/ContextMenu";
import {copy_to_clipboard} from "tc-shared/utils/helpers";
import {checkForUpdatedApp} from "tc-shared/update";
import {setupJSRender} from "tc-shared/ui/jsrender";
import ContextMenuEvent = JQuery.ContextMenuEvent;
import "svg-sprites/client-icons";
@ -45,43 +46,6 @@ import {ConnectRequestData} from "tc-shared/ipc/ConnectHandler";
import "./video-viewer/Controller";
import "./update/UpdaterWeb";
import {checkForUpdatedApp} from "tc-shared/update";
declare global {
interface Window {
open_connected_question: () => Promise<boolean>;
}
}
function setup_jsrender() : boolean {
if(!$.views) {
loader.critical_error("Missing jsrender viewer extension!");
return false;
}
$.views.settings.allowCode(true);
$.views.tags("rnd", (argument) => {
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();
});
$.views.tags("fmt_date", (...args) => {
return moment(args[0]).format(args[1]);
});
$.views.tags("tr", (...args) => {
return /* @tr-ignore */ tr(args[0]);
});
$(".jsrender-template").each((idx, _entry) => {
if(!$.templates(_entry.id, _entry.innerHTML)) {
log.error(LogCategory.GENERAL, tr("Failed to setup cache for js renderer template %s!"), _entry.id);
} else
log.trace(LogCategory.GENERAL, tr("Successfully loaded jsrender template %s"), _entry.id);
});
return true;
}
async function initialize() {
try {
@ -578,7 +542,7 @@ loader.register_task(loader.Stage.JAVASCRIPT_INITIALIZING, {
name: "jrendere initialize",
function: async () => {
try {
if(!setup_jsrender())
if(!setupJSRender())
throw "invalid load";
} catch (error) {
loader.critical_error(tr("Failed to setup jsrender"));

View File

@ -1,6 +1,7 @@
import * as loader from "tc-loader";
import {Stage} from "tc-loader";
import {KeyCode} from "tc-shared/PPTListener";
import * as $ from "jquery";
export enum ElementType {
HEADER,
@ -65,7 +66,7 @@ export class ModalProperties {
closeListener: (() => void) | (() => void)[] = () => {};
registerCloseListener(listener: () => void) : this {
if(this.closeListener) {
if($.isArray(this.closeListener))
if(Array.isArray(this.closeListener))
this.closeListener.push(listener);
else
this.closeListener = [this.closeListener, listener];

35
shared/js/ui/jsrender.ts Normal file
View File

@ -0,0 +1,35 @@
import * as loader from "tc-loader";
import * as moment from "moment";
import * as log from "tc-shared/log";
import {LogCategory} from "tc-shared/log";
export function setupJSRender() : boolean {
if(!$.views) {
loader.critical_error("Missing jsrender viewer extension!");
return false;
}
$.views.settings.allowCode(true);
$.views.tags("rnd", (argument) => {
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();
});
$.views.tags("fmt_date", (...args) => {
return moment(args[0]).format(args[1]);
});
$.views.tags("tr", (...args) => {
return /* @tr-ignore */ tr(args[0]);
});
$(".jsrender-template").each((idx, _entry) => {
if(!$.templates(_entry.id, _entry.innerHTML)) {
log.error(LogCategory.GENERAL, tr("Failed to setup cache for js renderer template %s!"), _entry.id);
} else
log.trace(LogCategory.GENERAL, tr("Successfully loaded jsrender template %s"), _entry.id);
});
return true;
}

View File

@ -10,6 +10,7 @@ import {findPopoutHandler} from "tc-shared/ui/react-elements/external-modal/Popo
import {Registry} from "tc-shared/events";
import {WebModalRenderer} from "tc-shared/ui/react-elements/external-modal/PopoutRendererWeb";
import {ClientModalRenderer} from "tc-shared/ui/react-elements/external-modal/PopoutRendererClient";
import {setupJSRender} from "tc-shared/ui/jsrender";
let modalRenderer: ModalRenderer;
let modalInstance: AbstractModal;
@ -27,6 +28,8 @@ loader.register_task(Stage.JAVASCRIPT_INITIALIZING, {
await import("tc-shared/proto");
await i18n.initialize();
ipc.setup();
setupJSRender();
}
});