Skip to content

Commit

Permalink
Positioning bugs, better async calls, logging fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
matejmosko committed Oct 5, 2017
1 parent 391591a commit 287c97b
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 69 deletions.
35 changes: 27 additions & 8 deletions js/console-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
debugMode = false;
setupSettings();

if (arguments[0] == "debug"){
if (arguments[0] == "debug") {
debugMode = true;
}

Expand Down Expand Up @@ -104,7 +104,7 @@
ipc.send('toggleRules');
});

document.getElementById("projectorBtn").addEventListener("click", function() { // Toggle visibility og Projector Window
document.getElementById("projectorBtn").addEventListener("click", function() { // Toggle visibility of Projector Window
ipc.send('toggleProjector');
});

Expand All @@ -131,13 +131,19 @@
document.getElementById("openFile").addEventListener("click", function() {
dialog.showOpenDialog({
defaultPath: settings.get("defaultPath") || app.getPath("home"),
filters: [
{ name: 'impress.js presentations', extensions: ['md', 'mkd', 'markdown', 'html', 'htm', 'zip'] },
{ name: 'All Files', extensions: ['*'] }
]
filters: [{
name: 'impress.js presentations',
extensions: ['md', 'mkd', 'markdown', 'html', 'htm', 'zip']
},
{
name: 'All Files',
extensions: ['*']
}
]
}, function(fileNames) {
settings.set("defaultPath", path.dirname(fileNames[0]))
if (fileNames === undefined) {
saveLogs(i18n.__("No file selected"));
console.log(i18n.__("No file selected"));
return;
}
Expand Down Expand Up @@ -188,6 +194,7 @@

// Add the error event listener
unzipper.on('error', function(err) {
saveLogs(i18n.__('Unzip with decompress-zip failed'), err);
console.log(i18n.__('Unzip with decompress-zip failed'), err);
});

Expand All @@ -203,6 +210,7 @@
});
break;
default:
saveLogs(i18n.__("Something went wrong. Wrong file is loaded."));
console.log(i18n.__("Something went wrong. Wrong file is loaded."));
}
});
Expand Down Expand Up @@ -232,6 +240,7 @@
try {
html = el.getElementById("impress").outerHTML; // Grab <div id="impress">...</div> and place it inside our template.
} catch (err) {
saveLogs("There is a problem with a file you selected");
console.log("There is a problem with a file you selected");
return;
}
Expand Down Expand Up @@ -267,7 +276,9 @@
saveViewer();
showTimer('projection');
totalSeconds = 0;
document.getElementById("projectionTimer").addEventListener("click", function() { totalSeconds = 0; });
document.getElementById("projectionTimer").addEventListener("click", function() {
totalSeconds = 0;
});
running = true;
document.body.classList.add('running');
mousetrap.bind(['space'], function() {
Expand All @@ -279,6 +290,7 @@
if (debugMode) {
webview0.openDevTools();
webview0.addEventListener('console-message', (e) => {
saveLogs('Guest page logged a message:', e.message);
console.log('Guest page logged a message:', e.message);
})
}
Expand Down Expand Up @@ -331,7 +343,13 @@
`;
let rendered = ms.render(tplSlideList, {
"slides": slideList,
"isCurrent": function() { if (this.step == current) { return "current"; } else { return "future"; } }
"isCurrent": function() {
if (this.step == current) {
return "current";
} else {
return "future";
}
}
});
document.getElementById("impressOverview").innerHTML = rendered;

Expand Down Expand Up @@ -436,6 +454,7 @@
}
break;
default:
saveLogs(i18n.__("There is something new coming from impress.js."));
console.log(i18n.__("There is something new coming from impress.js."));
}
});
Expand Down
141 changes: 80 additions & 61 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function saveTemplates() {
"jsPath": path.resolve(app.getAppPath(), "./js"),
"consolePath": JSON.stringify(path.resolve(app.getAppPath(), "./js/console-script.js")),
"projectorPath": JSON.stringify(path.resolve(app.getAppPath(), "./js/projector-script.js")),
"i18n": function() { // This is a function that translates i18n found in templates.
"i18n": function() { // This is a function that translates {{{i18n}}} strings found in templates.
return function(text, render) {
return render(i18n.__(text));
};
Expand All @@ -94,36 +94,39 @@ function saveTemplates() {
localeViewerFake = ms.render(tplViewerFake, mustacheOptions);
fs.writeFile(path.resolve(app.getPath('userData'), './viewer.html'), localeViewerFake, (err) => {
if (err) throw err;
fs.readFile(path.resolve(__dirname, './templates/console.tpl'), 'utf8', (err, tplConsole) => { // Read console.tpl (main console interface) asynchronously
if (err) throw err;
let localeConsole = ms.render(tplConsole, mustacheOptions);
fs.writeFile(path.resolve(app.getPath('userData'), './console.html'), localeConsole, (err) => {
if (err) throw err;
createWindow();
});
});
fs.readFile(path.resolve(__dirname, './templates/projector.tpl'), 'utf8', (err, tplProjector) => {
let localeProjector = ms.render(tplProjector, mustacheOptions);
fs.writeFile(path.resolve(app.getPath('userData'), './projector.html'), localeProjector, (err) => {
if (err) throw err;
createProjector();
});
});
});
});
fs.readFile(path.resolve(__dirname, './templates/console.tpl'), 'utf8', (err, tplConsole) => { // Read console.tpl (main console interface) asynchronously
if (err) throw err;
let localeConsole = ms.render(tplConsole, mustacheOptions);
fs.writeFile(path.resolve(app.getPath('userData'), './console.html'), localeConsole, (err) => {
if (err) throw err;
});
});
fs.readFile(path.resolve(__dirname, './templates/projector.tpl'), 'utf8', (err, tplProjector) => {
let localeProjector = ms.render(tplProjector, mustacheOptions);
fs.writeFile(path.resolve(app.getPath('userData'), './projector.html'), localeProjector, (err) => {
if (err) throw err;
});
});
}

function storeWindowState() {
windowState.main.isMaximized = impWindows.main.isMaximized();
windowState.projector.isMaximized = impWindows.projector.isMaximized();
if (!windowState.main.isMaximized) {
// only update bounds if the window isn't currently maximized
windowState.main.bounds = impWindows.main.getBounds();
if (typeof(impWindows.main) === "object") {
windowState.main.isMaximized = impWindows.main.isMaximized();
if (!windowState.main.isMaximized) {
// only update bounds if the window isn't currently maximized
windowState.main.bounds = impWindows.main.getBounds();
}
}
if (!windowState.projector.isMaximized) {
// only update bounds if the window isn't currently maximized
windowState.projector.bounds = impWindows.projector.getBounds();
if (typeof(impWindows.projector) === "object") {
windowState.projector.isMaximized = impWindows.projector.isMaximized();
if (!windowState.projector.isMaximized) {
// only update bounds if the window isn't currently maximized
windowState.projector.bounds = impWindows.projector.getBounds();
}
}

settings.set('windowstate', windowState);
};

Expand All @@ -142,7 +145,7 @@ function createWindow() {
backgroundColor: '#13132A'
});

if (windowState.main !== "undefined" && windowState.main.isMaximized) {
if (typeof(windowState.main) === "object" && windowState.main.isMaximized) {
impWindows.main.maximize();
}

Expand All @@ -156,18 +159,23 @@ function createWindow() {
impWindows.main.on('ready-to-show', function() {
impWindows.main.show();
impWindows.main.focus();
impWindows.main.on('resize', function() {
storeWindowState();
});
impWindows.main.on('move', function() {
storeWindowState();
});
});

impWindows.main.webContents.on('did-frame-finish-load', function() {
//impWindows.main.webContents.executeJavaScript(require(path.resolve(app.getAppPath(), "./js/console-script.js")));
});

impWindows.main.on('close', event => {
storeWindowState();
event.preventDefault(); //this prevents it from closing. The `closed` event will not fire now
impWindows.main.webContents.send('quitModal');

ipcMain.on('reallyQuit', (event) => {
storeWindowState();
app.exit();
});
});
Expand All @@ -178,12 +186,7 @@ function createWindow() {
// when you should delete the corresponding element.
impWindows.main = null;
});
impWindows.main.on('resize', function() {
storeWindowState();
});
impWindows.main.on('move', function() {
storeWindowState();
});

if (debugMode) {
impWindows.main.webContents.openDevTools()
}
Expand All @@ -204,10 +207,6 @@ function createProjector() {
show: false
});

if (windowState.projector !== "undefined" && windowState.projector.isMaximized) {
impWindows.projector.maximize();
}

// and load the index.html of the app.
impWindows.projector.loadURL(url.format({
pathname: path.resolve(app.getPath('userData'), './projector.html'),
Expand All @@ -223,22 +222,7 @@ function createProjector() {
// when you should delete the corresponding element.
impWindows.projector = null;
});
impWindows.projector.on('close', event => {
event.preventDefault(); //this prevents it from closing. The `closed` event will not fire now
impWindows.main.webContents.send('buttonSwitch', "projectorBtn", false);
impWindows.main.webContents.send('buttonSwitch', "fullscreenBtn", false);
impWindows.projector.hide();
});
impWindows.projector.on('leave-full-screen', () => {
impWindows.main.webContents.send('buttonSwitch', "fullscreenBtn", false);
});
impWindows.projector.on('enter-full-screen', () => {
impWindows.main.webContents.send('buttonSwitch', "fullscreenBtn", true);
impWindows.main.webContents.send('buttonSwitch', "projectorBtn", true);
});
impWindows.projector.webContents.on('did-finish-load', () => {

});
// Window positioning and size
impWindows.projector.on('resize', () => {
storeWindowState();
const [width, height] = impWindows.projector.getContentSize();
Expand All @@ -258,6 +242,11 @@ function createProjector() {
impWindows.projector.on('move', function() {
storeWindowState();
});

if (typeof(windowState.projector) === "object" && windowState.projector.isMaximized) {
impWindows.projector.maximize();
}

ipcMain.on('toggleFullscreen', (event) => {
if (impWindows.projector.isFullScreen()) {
impWindows.projector.setFullScreen(false);
Expand All @@ -266,24 +255,56 @@ function createProjector() {
}
});

impWindows.projector.webContents.on('did-finish-load', () => {
impWindows.projector.hide();
});
if (debugMode) {
impWindows.projector.webContents.openDevTools()
}
}

function setupProjectorButtons() {
// Button events
impWindows.projector.on('hide', event => {
impWindows.main.webContents.send('buttonSwitch', "projectorBtn", false);
impWindows.main.webContents.send('buttonSwitch', "fullscreenBtn", false);
});

impWindows.projector.on('show', event => {
impWindows.main.webContents.send('buttonSwitch', "projectorBtn", true);
});

impWindows.projector.on('close', event => {
event.preventDefault(); //this prevents it from closing. The `closed` event will not fire now
impWindows.projector.hide();
});
impWindows.projector.on('leave-full-screen', () => {
impWindows.main.webContents.send('buttonSwitch', "fullscreenBtn", false);
});
impWindows.projector.on('enter-full-screen', () => {
impWindows.main.webContents.send('buttonSwitch', "fullscreenBtn", true);
impWindows.main.webContents.send('buttonSwitch', "projectorBtn", true);
});

ipcMain.on('toggleProjector', (event) => {
if (impWindows.projector.isVisible()) {
impWindows.projector.hide();
impWindows.main.webContents.send('buttonSwitch', "projectorBtn", false);
} else {
impWindows.projector.show();
impWindows.main.webContents.send('buttonSwitch', "projectorBtn", true);

}
});
if (debugMode) {
impWindows.projector.webContents.openDevTools()
}
}

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', saveTemplates);
app.on('ready', function() {
saveTemplates();
createWindow();
createProjector();
setupProjectorButtons();
});
//app.on('ready', );

// Quit when all windows are closed.
Expand All @@ -295,8 +316,6 @@ app.on('window-all-closed', function() {
}
});



app.on('activate', function() {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
Expand Down

0 comments on commit 287c97b

Please sign in to comment.