Skip to content

Commit

Permalink
Fixed issue where printed files were not able to be viewed. Mac virtu…
Browse files Browse the repository at this point in the history
…al printer suddenly working too - not sure whether the other global variable fixed it :/
  • Loading branch information
Hemal Ruparelia committed Jan 21, 2018
1 parent 5bb7423 commit 020be24
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
2 changes: 1 addition & 1 deletion appUpdater.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const fs = require('fs');
const { app, dialog } = require('electron');
const { autoUpdater } = require('electron-updater');
const isDev = require('electron-is-dev');
const log = require('electron-log');
const log = require('electron-log'); //open ~/Library/Logs/mediref-desktop/log.log (may have to use 'open')

function appUpdater(mainWindow) {
// Don't initiate auto-updates in development and on Linux system
Expand Down
39 changes: 19 additions & 20 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,18 @@ const isDev = require('electron-is-dev');
let mainWindow = null;

global.fileToOpen = null; //Declare a global empty object variable to hold file path if a file is opened while the app is closed
global.gp = null;

//Clear the global fileToOpen variable once Mediref app renderer process has handled the file
ipcMain.on('file-handled', () => {
fileToOpen = null;
});

//Takes in a file path, reads the file, assigns it to the global fileToOpen and then emits an event if windown open
//Takes in a file path, reads the file, assigns it to the global fileToOpen and then emits an event if window open
function handleFilePath(filePath) {
mainWindow.send('Updater', 'Began handleFilePath line 18 of main.js');
gp = filePath;
const name = path.basename(filePath);
mainWindow.send('Updater', `Filename is ${name}`);
const type = mime.getType(filePath);
mainWindow.send('Updater', `Filetype is ${type}`);
const data = fs.readFileSync(filePath, 'base64');
const fileData = { name, data, type, path: filePath };
fileToOpen = fileData;
Expand All @@ -34,20 +33,20 @@ function handleFilePath(filePath) {
}

const shouldQuit = app.makeSingleInstance((commandLine, workingDirectory) => {
// Someone tried to run a second instance, we should focus our window.
if (mainWindow) {
if (mainWindow.isMinimized()) mainWindow.restore()
mainWindow.focus();
console.log(commandLine[2]);
var filePath = commandLine[2];
if(filePath != undefined){
handleFilePath(filePath);
}
}
// Someone tried to run a second instance, we should focus our window.
if (mainWindow) {
if (mainWindow.isMinimized()) mainWindow.restore();
mainWindow.focus();
console.log(commandLine[2]);
const filePath = commandLine[2];
if (filePath != undefined) {
handleFilePath(filePath);
}
}
});

if (shouldQuit) {
app.quit();
app.quit();
}

app.on('will-finish-launching', () => {
Expand All @@ -63,22 +62,23 @@ app.on('ready', () => {
nodeIntegration: false,
preload: __dirname + '/preload.js',
},
});
});
if (platform.isWindows) {
const filePath = process.argv[2];
if (filePath != undefined) {
handleFilePath(filePath);
}
}

mainWindow.maximize();

if (isDev) {
mainWindow.loadURL('http://localhost:3000/');
mainWindow.webContents.openDevTools();
} else {
mainWindow.loadURL('https://new.mediref.com.au/new');
}

mainWindow.maximize();

appUpdater(mainWindow);

setTimeout(() => {
Expand All @@ -87,8 +87,6 @@ app.on('ready', () => {
mainWindow.send('Updater', `Your OS: ${platform.name}`);
}, 5000);

// mainWindow.webContents.openDevTools();

// Create the Application's main menu
const menuTemplate = [
{
Expand Down Expand Up @@ -145,6 +143,7 @@ ipcMain.on('view-pdf', (event, url) => {
height: 800,
webPreferences: {
plugins: true,
webSecurity: false,
},
});
pdfWindow.loadURL(url);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mediref-desktop",
"version": "0.1.18",
"version": "0.1.19",
"repository": {
"type": "git",
"url": "https://github.com/HemalR/mediref-desktop.git"
Expand Down

0 comments on commit 020be24

Please sign in to comment.