Fixed OSD font preview dialog breaking when opening multiple times.

10.5.x-maintenance
mikeller 2019-01-27 13:32:54 +13:00
parent 4c5dfe7f8e
commit 505ac5641b
1 changed files with 15 additions and 11 deletions

View File

@ -127,7 +127,7 @@ FONT.parseMCMFontFile = function (data) {
return FONT.data.characters; return FONT.data.characters;
}; };
FONT.openFontFile = function ($preview) { FONT.openFontFile = function (fontPreviewElement) {
return new Promise(function (resolve) { return new Promise(function (resolve) {
chrome.fileSystem.chooseEntry({ type: 'openFile', accepts: [{ description: 'MCM files', extensions: ['mcm'] }] }, function (fileEntry) { chrome.fileSystem.chooseEntry({ type: 'openFile', accepts: [{ description: 'MCM files', extensions: ['mcm'] }] }, function (fileEntry) {
FONT.data.loaded_font_file = fileEntry.name; FONT.data.loaded_font_file = fileEntry.name;
@ -200,7 +200,8 @@ FONT.upload = function ($progress) {
return MSP.promise(MSPCodes.MSP_OSD_CHAR_WRITE, FONT.msp.encode(i)); return MSP.promise(MSPCodes.MSP_OSD_CHAR_WRITE, FONT.msp.encode(i));
}) })
.then(function () { .then(function () {
OSD.GUI.jbox.close(); OSD.GUI.fontManager.close();
return MSP.promise(MSPCodes.MSP_SET_REBOOT); return MSP.promise(MSPCodes.MSP_SET_REBOOT);
}); });
}; };
@ -1632,14 +1633,14 @@ TABS.osd.initialize = function (callback) {
$('#content').load("./tabs/osd.html", function () { $('#content').load("./tabs/osd.html", function () {
// Generate font type select element // Generate font type select element
var fontselect = $('.fontpresets'); var fontPresetsElement = $('.fontpresets');
OSD.constants.FONT_TYPES.forEach(function (e, i) { OSD.constants.FONT_TYPES.forEach(function (e, i) {
var option = $('<option>', { var option = $('<option>', {
"data-font-file": e.file, "data-font-file": e.file,
value: e.file, value: e.file,
text: e.name text: e.name
}); });
fontselect.append($(option)); fontPresetsElement.append($(option));
}); });
var fontbuttons = $('.fontpresets_wrapper'); var fontbuttons = $('.fontpresets_wrapper');
@ -1652,7 +1653,7 @@ TABS.osd.initialize = function (callback) {
i18n.localizePage(); i18n.localizePage();
// Open modal window // Open modal window
OSD.GUI.jbox = new jBox('Modal', { OSD.GUI.fontManager = new jBox('Modal', {
width: 720, width: 720,
height: 420, height: 420,
closeButton: 'title', closeButton: 'title',
@ -2134,17 +2135,16 @@ TABS.osd.initialize = function (callback) {
}); });
// font preview window // font preview window
var $preview = $('.font-preview'); var fontPreviewElement = $('.font-preview');
// init structs once, also clears current font // init structs once, also clears current font
FONT.initData(); FONT.initData();
var $fontpresets = $('.fontpresets') fontPresetsElement.change(function (e) {
$fontpresets.change(function (e) {
var $font = $('.fontpresets option:selected'); var $font = $('.fontpresets option:selected');
$.get('./resources/osd/' + $font.data('font-file') + '.mcm', function (data) { $.get('./resources/osd/' + $font.data('font-file') + '.mcm', function (data) {
FONT.parseMCMFontFile(data); FONT.parseMCMFontFile(data);
FONT.preview($preview); FONT.preview(fontPreviewElement);
LogoManager.drawPreview(); LogoManager.drawPreview();
updateOsdView(); updateOsdView();
}); });
@ -2154,14 +2154,14 @@ TABS.osd.initialize = function (callback) {
var $font = $('.fontpresets option:selected'); var $font = $('.fontpresets option:selected');
$.get('./resources/osd/' + $font.data('font-file') + '.mcm', function (data) { $.get('./resources/osd/' + $font.data('font-file') + '.mcm', function (data) {
FONT.parseMCMFontFile(data); FONT.parseMCMFontFile(data);
FONT.preview($preview); FONT.preview(fontPreviewElement);
LogoManager.drawPreview(); LogoManager.drawPreview();
updateOsdView(); updateOsdView();
}); });
$('button.load_font_file').click(function () { $('button.load_font_file').click(function () {
FONT.openFontFile().then(function () { FONT.openFontFile().then(function () {
FONT.preview($preview); FONT.preview(fontPreviewElement);
LogoManager.drawPreview(); LogoManager.drawPreview();
updateOsdView(); updateOsdView();
}).catch(error => console.error(error)); }).catch(error => console.error(error));
@ -2273,6 +2273,10 @@ TABS.osd.initialize = function (callback) {
TABS.osd.cleanup = function (callback) { TABS.osd.cleanup = function (callback) {
PortHandler.flush_callbacks(); PortHandler.flush_callbacks();
if (OSD.GUI.fontManager) {
OSD.GUI.fontManager.destroy();
}
// unbind "global" events // unbind "global" events
$(document).unbind('keypress'); $(document).unbind('keypress');
$(document).off('click', 'span.progressLabel a'); $(document).off('click', 'span.progressLabel a');