.on('did-finish-load', function () {
   mainWindow.setTitle(app.getName()); // ja, noch einmal - sonst ist es der Titel der Website (im dock wenn hidden)
   // autoUpdater -----------------------------------------------------------------------------------------------------
   if (process.env.NODE_ENV !== 'development') {
     autoUpdater.setFeedURL(releaseUrl);
     autoUpdater
       .on('error', function (error) {
         console.log('auto-updater on error: ', error);
       })
       .on('checking-for-update', function () {
         console.log('checking-for-update');
         appMenu.mainMenu.items[0].submenu.items[1].enabled = false; // hmmm ... vllt
       })
       .on('update-available', function () {
         console.log('update-available');
         appMenu.mainMenu.items[0].submenu.items[1].label = 'Downloading update...'; // hmmm ... vllt
       })
       .on('update-not-available', function () {
         console.log('update-not-available');
         appMenu.mainMenu.items[0].submenu.items[1].label = 'No Update available...'; // hmmm ... vllt
         appMenu.mainMenu.items[0].submenu.items[1].enabled = true; // hmmm ... vllt
       })
       .on('update-downloaded', function () {
         console.log('update-downloaded');
         // autoUpdater.quitAndInstall();
         appMenu.mainMenu.items[0].submenu.items[1].label = 'Download update done...'; // hmmm ... vllt
       });
     autoUpdater.checkForUpdates();
   }
   // autoUpdater -----------------------------------------------------------------------------------------------------
 })
Exemple #2
0
 setTimeout(function() {
   if (/win32/.test(platform)) {
     https.get(updateUrl, function(res) {
       if (res.statusCode!=204) {
         mainWindow.webContents.send('update-ready', { platform: 'windows' });
       }
     }).on('error', function(err) {
       console.error("[ERROR]: could not check for windows update.");
     });
   } else {
     autoUpdater.setFeedURL(updateUrl);
     autoUpdater.checkForUpdates();
   }
 }, 2000);
exports.init = (platform, arch, ver) => {
  // When starting up we should not expect an update to be available
  appActions.setUpdateStatus(UpdateStatus.UPDATE_NONE)

  // Browser version X.X.X
  version = ver

  var baseUrl = exports.updateUrl(appConfig.updates, platform, arch)
  debug(`updateUrl = ${baseUrl}`)

  scheduleUpdates()

  // This will fail if we are in dev
  try {
    autoUpdater.setFeedURL(baseUrl)
  } catch (err) {
    console.log(err)
  }
}
app.on('ready', function() {

  // Application Menu
  var appMenu = menu.buildFromTemplate([
    {
      label: 'OpenBazaar',
      submenu: [
        {
          label: 'Quit OpenBazaar',
          accelerator: 'CmdOrCtrl+Q',
          click: function() {
            app.quit();
          }
        }
      ]
    },
    {
      label: 'Edit',
      submenu: [
        { label: "Undo", accelerator: "CmdOrCtrl+Z", selector: "undo:" },
        { label: "Redo", accelerator: "Shift+CmdOrCtrl+Z", selector: "redo:" },
        { type: "separator" },
        { label: "Cut", accelerator: "CmdOrCtrl+X", selector: "cut:" },
        { label: "Copy", accelerator: "CmdOrCtrl+C", selector: "copy:" },
        { label: "Paste", accelerator: "CmdOrCtrl+V", selector: "paste:" },
        { label: "Select All", accelerator: "CmdOrCtrl+A", selector: "selectAll:" }
      ]
    },
    {
      label: 'View',
      submenu: [
        {
          label: 'Reload',
          accelerator: 'CmdOrCtrl+R',
          click: function(item, focusedWindow) {
            if (focusedWindow) {
              focusedWindow.reload();
            }
          }
        },
        {
          label: 'Toggle Developer Tools',
          accelerator: (function() {
            if (platform == 'mac') {
              return 'Alt+Command+I';
            } else {
              return 'Ctrl+Shift+I';
            }
          })(),
          click: function(item, focusedWindow) {
            if (focusedWindow) {
              focusedWindow.toggleDevTools();
            }
          }
        },
      ]
    },
    {
    label: 'Window',
    submenu: [
      {
        label: 'Minimize',
        accelerator: 'Command+M',
        selector: 'performMiniaturize:'
      },
      {
        label: 'Close',
        accelerator: 'Command+W',
        selector: 'performClose:'
      },
      {
        type: 'separator'
      },
      {
        label: 'Bring All to Front',
        selector: 'arrangeInFront:'
      }
    ]
  }
  ]);
  menu.setApplicationMenu(appMenu);

  // put logic here to set tray icon based on OS
  var osTrayIcon = 'openbazaar-mac-system-tray.png';

  trayMenu = new tray(__dirname + '/imgs/' + osTrayIcon);
  var contextMenu = menu.buildFromTemplate([
    {
      label: 'Start Local Server', type: 'normal', click: function () {
      start_local_server();
    }
    },
    {
      label: 'Shutdown Local Server', type: 'normal', click: function () {
      request('http://localhost:18469/api/v1/shutdown', function (error, response, body) {
        if (!error && response.statusCode == 200) {
          console.log('Shutting down server');
        } else {
          console.log('Server does not seem to be running.');
        }
      });
    }
    },
    {type: 'separator'},
    {label: 'View Debug Log', type: 'normal', click: function() {
      // Open Debug Log Wherever It Is
      find_debug_log();
    }},
    {type: 'separator'},
    {
      label: 'Quit', type: 'normal', accelerator: 'Command+Q', click: function () {
      app.quit();
    }
    }
  ]);

  function find_debug_log() {
    var filename = "../OpenBazaar-Server/ob.cfg";
    var config = ini.parse(fs.readFileSync(filename, 'utf-8'));
    if(config.CONSTANTS.DATA_FOLDER) {
      console.log('Using DATA_FOLDER: ' + config.CONSTANTS.DATA_FOLDER);
      require('child_process').exec(config.CONSTANTS.DATA_FOLDER + '/debug.log');
    } else {
      console.log('Using default DATA_FOLDER location');
      var home_folder = process.env.HOME || process.env.USERPROFILE;
      require('child_process').exec(home_folder + '/OpenBazaar/debug.log');
    }
  }

  trayMenu.setContextMenu(contextMenu);

  // Create the browser window.
  mainWindow = new BrowserWindow({
    "width": 1200,
    "height": 720,
    "min-width": 1024,
    "min-height": 700,
    "center": true,
    "title": "OpenBazaar",
    "frame": false,
    "icon": "imgs/openbazaar-icon.png",
    "title-bar-style": "hidden"
  });

  // and load the index.html of the app.
  if(open_url) {
    mainWindow.loadURL('file://' + __dirname + '/index.html' + open_url);
  } else {
    mainWindow.loadURL('file://' + __dirname + '/index.html');
  }

  // Open the devtools.
  // Uncomment if you want tools to open on startup
  // mainWindow.openDevTools({detach: true});

  // Emitted when the window is closed.
  mainWindow.on('closed', function() {
    // Dereference the window object, usually you would store windows
    // in an array if your app supports multi windows, this is the time
    // when you should delete the corresponding element.
    mainWindow = null;

    if(subpy) {
      subpy.kill('SIGHUP');
    }
  });

  mainWindow.on('close', function() {
    app.quit();
  });

  app.on('activate', function() {
    mainWindow.show();
  });

  autoUpdater.on("error", function(err, msg) {
    console.log(msg); //print msg , you can find the cash reason.
  });

  autoUpdater.on("update-not-available", function(msg) {
    mainWindow.webContents.executeJavaScript("console.log('Update not available! Your software is up to date.')");
  });

  autoUpdater.on("update-available", function() {
    mainWindow.webContents.executeJavaScript("console.log('Update available! Downloading now...')");
  });

  autoUpdater.on("update-downloaded", function(e, releaseNotes, releaseName, releaseDate, updateUrl, quitAndUpdate) {
    mainWindow.webContents.executeJavaScript("console.log('Update downloaded." + updateUrl + "')");
    mainWindow.webContents.executeJavaScript('$(".js-softwareUpdate").removeClass("softwareUpdateHidden");');
  });

  ipcMain.on('installUpdate', function(event) {
    console.log('Installing Update');
    autoUpdater.quitAndInstall();
  });

  var feedURL = 'http://updates.openbazaar.org:5000/update/' + platform + '/' + version;
  autoUpdater.setFeedURL(feedURL);
  mainWindow.webContents.executeJavaScript("console.log('Checking for new versions at " + feedURL + " ...')");
  autoUpdater.checkForUpdates();

});
Exemple #5
0
app.on('ready', function() {

  // Application Menu
  var appMenu = menu.buildFromTemplate([
    {
      label: 'OpenBazaar',
      submenu: [
        {
          label: 'Quit OpenBazaar',
          accelerator: 'CmdOrCtrl+Q',
          click: function() {
            app.quit();
          }
        }
      ]
    },
    {
      label: 'Edit',
      submenu: [
        { label: "Undo", accelerator: "CmdOrCtrl+Z", selector: "undo:" },
        { label: "Redo", accelerator: "Shift+CmdOrCtrl+Z", selector: "redo:" },
        { type: "separator" },
        { label: "Cut", accelerator: "CmdOrCtrl+X", selector: "cut:" },
        { label: "Copy", accelerator: "CmdOrCtrl+C", selector: "copy:" },
        { label: "Paste", accelerator: "CmdOrCtrl+V", selector: "paste:" },
        { label: "Select All", accelerator: "CmdOrCtrl+A", selector: "selectAll:" }
      ]
    },
    {
      label: 'View',
      submenu: [
        {
          label: 'Reload',
          accelerator: 'CmdOrCtrl+R',
          click: function(item, focusedWindow) {
            if (focusedWindow) {
              focusedWindow.reload();
            }
          }
        },
        {
          label: 'Toggle Developer Tools',
          accelerator: (function() {
            if (platform == 'mac') {
              return 'Alt+Command+I';
            }
            return 'Ctrl+Shift+I';
          })(),
          click: function(item, focusedWindow) {
            if (focusedWindow) {
              focusedWindow.toggleDevTools();
            }
          }
        },
        {
          label: 'Toggle Full Screen',
          accelerator: (function() {
            if (platform == 'mac') {
              return 'Ctrl+Command+F';
            }
            return 'F11';
          })(),
          click: function() {
            var fullScreen;

            if (mainWindow) {
              fullScreen = !mainWindow.isFullScreen();
              mainWindow.setFullScreen(fullScreen);

              if (fullScreen) {
                mainWindow.webContents.send('fullscreen-enter');
              } else {
                mainWindow.webContents.send('fullscreen-exit');
              }
            }
          }
        }    
      ]
    },
    {
    label: 'Window',
    submenu: [
      {
        label: 'Minimize',
        selector: 'performMiniaturize:',
        accelerator: 'Command+M'
      }
    ]
  }
  ]);
  menu.setApplicationMenu(appMenu);

  // put logic here to set tray icon based on OS
  var osTrayIcon = 'openbazaar-mac-system-tray.png';

  trayMenu = new tray(__dirname + '/imgs/' + osTrayIcon);
  var contextMenu = menu.buildFromTemplate([
    {
      label: 'Start Local Server', type: 'normal', click: function () {
      start_local_server();
    }
    },
    {
      label: 'Shutdown Local Server', type: 'normal', click: function () {
        request('http://*****:*****@openbazaar.org?subject=OpenBazaar Debug Report&body=' + body);

    }},
    {type: 'separator'},
    {
      label: 'Quit', type: 'normal', accelerator: 'Command+Q', click: function () {
      app.quit();
    }
    }
  ]);

  trayMenu.setContextMenu(contextMenu);

  // Create the browser window.
  mainWindow = new browserWindow({
    "width": 1200,
    "height": 760,
    "minWidth": 1024,
    "minHeight": 700,
    "center": true,
    "title": "OpenBazaar",
    "frame": false,
    "icon": "imgs/openbazaar-icon.png",
    "titleBarStyle": "hidden"
  });

  // and load the index.html of the app.
  if(open_url) {
    mainWindow.loadURL('file://' + __dirname + '/index.html' + open_url);
  } else {
    mainWindow.loadURL('file://' + __dirname + '/index.html');
  }

  // Open the devtools.
  // Uncomment if you want tools to open on startup
  //mainWindow.openDevTools({detach: true});

  // Emitted when the window is closed.
  mainWindow.on('closed', function() {
    // Dereference the window object, usually you would store windows
    // in an array if your app supports multi windows, this is the time
    // when you should delete the corresponding element.
    mainWindow = null;

    if (launched_from_installer) kill_local_server();
  });

  mainWindow.on('close', function() {
    app.quit();
  });

  app.on('activate', function() {
    mainWindow.show();
  });

  autoUpdater.on("error", function(err, msg) {
    console.log(msg); //print msg , you can find the cash reason.
  });

  autoUpdater.on("update-not-available", function(msg) {
    mainWindow.webContents.executeJavaScript("console.log('Update not available! Your software is up to date.')");
  });

  autoUpdater.on("update-available", function() {
    mainWindow.webContents.executeJavaScript("console.log('Update available! Downloading now...')");
  });

  autoUpdater.on("update-downloaded", function(e, releaseNotes, releaseName, releaseDate, updateUrl, quitAndUpdate) {
    mainWindow.webContents.executeJavaScript("console.log('Update downloaded." + updateUrl + "')");
    mainWindow.webContents.executeJavaScript('$(".js-softwareUpdate").removeClass("softwareUpdateHidden");');
  });

  ipcMain.on('installUpdate', function() {
    console.log('Installing Update');
    autoUpdater.quitAndInstall();
  });

  var feedURL = 'http://updates.openbazaar.org:5000/update/' + platform + '/' + version;
  autoUpdater.setFeedURL(feedURL);
  mainWindow.webContents.executeJavaScript("console.log('Checking for new versions at " + feedURL + " ...')");

  // Check for updates every hour
  autoUpdater.checkForUpdates();
  setInterval(function () {
      autoUpdater.checkForUpdates();
  }, 3600000);

});