const { app, BrowserWindow } = require('electron');
const {dialog} = require('electron');
const Backend = require('./src/Backend.js');

// Main window
let mainWin = null;

// Work window
let workWin = null;

global.sharedObject = {args: process.argv}

function mainWindow(){

    // Create main 
    mainWin = new BrowserWindow({width: 800, height: 600});

    // Set window properties
    mainWin.setResizable(false);

    // Load view into window
    mainWin.loadFile('index.html');
}

function workWindow(){

    // Create window 
    //workWin = new BrowserWindow({width: 1024, height: 800});
    workWin = new BrowserWindow({width: 800, height: 480});
    workWin.setResizable(false);
    workWin.loadFile('work.html');
}


app.on('ready', function(){

    const promise = new Promise(function(resolve, reject){
        // Get session progress
        Backend.session.progress('meetings.welogy.com', resolve, reject);

        // Set progress data
    });

    // Use the value (sync-like)
    promise.then(function(reply){
        var _reply = JSON.parse(reply);
        if (_reply.status=='started')
            workWindow();
        else
            mainWindow();
    },function(error){
        // Show messagebox with error message
        // @TODO
        console.log(error);
    });
});