ls-vertretungsplan-desktop

UNOFFICIAL Desktop App for the schedule of Lornsenschule, Schleswig
git clone git://archive.git.mtrnord.blog/MTRNord/ls-vertretungsplan-desktop.git
Log | Files | Refs | README

main.js (4046B)


      1 const {app, BrowserWindow, dialog, globalShortcut} = require('electron')
      2 const autoUpdater = require('electron').autoUpdater
      3 const os = require("os")
      4 
      5 // Keep a global reference of the window object, if you don't, the window will
      6 // be closed automatically when the JavaScript object is garbage collected.
      7 let win
      8 
      9 function update () {
     10   console.warn("Starting Autoupdater")
     11   console.warn(app.getVersion())
     12   var feedUrl = 'http://ls-desktop.herokuapp.com/update/' + os.platform() + '/' + app.getVersion() + '/';
     13   autoUpdater.setFeedURL(feedUrl);
     14 
     15   console.log('created');
     16   autoUpdater.on('checking-for-update', function() {
     17       console.log("checking-for-update");
     18   });
     19 
     20   autoUpdater.on('update-available', function() {
     21       console.log("update-available");
     22   });
     23 
     24   autoUpdater.on('update-not-available', function() {
     25       console.log("update-not-available");
     26   });
     27 
     28   autoUpdater.on('update-downloaded', function() {
     29       console.log(" update-downloaded");
     30   });
     31 
     32   setTimeout(function() {autoUpdater.checkForUpdates()}, 10000);
     33 
     34   autoUpdater.on('update-downloaded', function (event, releaseNotes, releaseName, releaseDate, updateUrl, quitAndUpdate) {
     35 
     36     var index = dialog.showMessageBox({
     37       type: 'info',
     38       buttons: ['Restart', 'Later'],
     39       title: "Lornsenschule Vertretungsplan",
     40       message: ('The new version has been downloaded. Please restart the application to apply the updates.'),
     41       detail: releaseName + "\n\n" + releaseNotes
     42     });
     43 
     44     if (index === 1) {
     45       return;
     46     }
     47 
     48     quitAndUpdate()
     49   });
     50 }
     51 
     52 function createWindow () {
     53   // Create the browser window.
     54   win = new BrowserWindow({width: 800, height: 600, icon: __dirname + '/LS.ico', title: 'Lornsenschule Vertretungsplan'})
     55 
     56   // and load the index.html of the app.
     57   win.loadURL(`file://${__dirname}/index.html`)
     58 
     59   //win.webContents.openDevTools()
     60 
     61   // Emitted when the window is closed.
     62   win.on('closed', () => {
     63     // Dereference the window object, usually you would store windows
     64     // in an array if your app supports multi windows, this is the time
     65     // when you should delete the corresponding element.
     66     win = null
     67   })
     68   update()
     69 }
     70 
     71 // This method will be called when Electron has finished
     72 // initialization and is ready to create browser windows.
     73 // Some APIs can only be used after this event occurs.
     74 app.on('ready', createWindow)
     75 
     76 // Quit when all windows are closed.
     77 app.on('window-all-closed', () => {
     78   // On macOS it is common for applications and their menu bar
     79   // to stay active until the user quits explicitly with Cmd + Q
     80   if (process.platform !== 'darwin') {
     81     app.quit()
     82   }
     83 })
     84 
     85 app.on('activate', () => {
     86   // On macOS it's common to re-create a window in the app when the
     87   // dock icon is clicked and there are no other windows open.
     88   if (win === null) {
     89     createWindow()
     90   }
     91 })
     92 
     93 // In this file you can include the rest of your app's specific main process
     94 // code. You can also put them in separate files and require them here.
     95 if(require('electron-squirrel-startup')) return;
     96 var handleStartupEvent = function() {
     97   if (process.platform !== 'win32') {
     98     return false;
     99   }
    100 
    101   var squirrelCommand = process.argv[1];
    102   switch (squirrelCommand) {
    103     case '--squirrel-install':
    104     case '--squirrel-updated':
    105 
    106       // Optionally do things such as:
    107       //
    108       // - Install desktop and start menu shortcuts
    109       // - Add your .exe to the PATH
    110       // - Write to the registry for things like file associations and
    111       //   explorer context menus
    112 
    113       // Always quit when done
    114       app.quit();
    115 
    116       return true;
    117     case '--squirrel-uninstall':
    118       // Undo anything you did in the --squirrel-install and
    119       // --squirrel-updated handlers
    120 
    121       // Always quit when done
    122       app.quit();
    123 
    124       return true;
    125     case '--squirrel-obsolete':
    126       // This is called on the outgoing version of your app before
    127       // we update to the new version - it's the opposite of
    128       // --squirrel-updated
    129       app.quit();
    130       return true;
    131   }
    132 };
    133 
    134 if (handleStartupEvent()) {
    135   return;
    136 }