Warning: mysqli_num_fields() expects parameter 1 to be mysqli_result, boolean given in /www/wwwroot/dev.zhalaotie.com/wp-includes/wp-db.php on line 3215

Warning: mysqli_num_fields() expects parameter 1 to be mysqli_result, boolean given in /www/wwwroot/dev.zhalaotie.com/wp-includes/wp-db.php on line 3215
electron 退出时,执行某个操作(发送 http 请求) – 扎老铁
Warning: mysqli_num_fields() expects parameter 1 to be mysqli_result, boolean given in /www/wwwroot/dev.zhalaotie.com/wp-includes/wp-db.php on line 3215

Warning: mysqli_num_fields() expects parameter 1 to be mysqli_result, boolean given in /www/wwwroot/dev.zhalaotie.com/wp-includes/wp-db.php on line 3215
Warning: mysqli_num_fields() expects parameter 1 to be mysqli_result, boolean given in /www/wwwroot/dev.zhalaotie.com/wp-includes/wp-db.php on line 3215
class="post-51721 post type-post status-publish format-standard hentry">

electron 退出时,执行某个操作(发送 http 请求)

 

const electron = require('electron')
// Module to control application life.
const app = electron.app
// Module to create native browser window.
const BrowserWindow = electron.BrowserWindow

const path = require('path')
const url = require('url')
var request = require('request');
let baseUrl = 'http://localhost:42969/';

var req = function(url,callback ) {
  console.log("request " + url);
  return request(url, function (error, response, body) {
     if(error){
       console.error("Error request " + url, body);
     }
     else if (response && response.statusCode == 200) {
       console.log("Success request " + url,body);
     }else{
     }
     callback(error, response, body);
   });
};

  
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow;

function createWindow () {
  
    // Create the browser window.
    mainWindow = new BrowserWindow({width: 1024, height: 768,autoHideMenuBar:true,icon: path.join(__dirname, '../icon.ico')})
  
    // and load the index.html of the app.
    // mainWindow.loadURL(url.format({
    //   // pathname: path.join(__dirname, 'dist/index.html'),
    //   pathname: path.join(__dirname, 'index.html'),
    //   protocol: 'file:',
    //   slashes: true
    // }))
  
    app.commandLine.appendSwitch('allow-file-access');
  
    mainWindow.loadURL(url.format({
      // pathname: path.join(__dirname, 'dist/index.html'),
      pathname: path.join(__dirname, 'index.html'),
      protocol: 'file:',
      slashes: true
    }))
    // url.format(url.parse('file://' + __dirname + '/somepath/home.html'))
  
    // Open the DevTools.
    // mainWindow.webContents.openDevTools()
  
    // 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
    })
  
    //  mainWindow.on('reload', function () {
    //     mainWindow.loadURL(url.format({
    //   // pathname: path.join(__dirname, 'dist/index.html'),
    //   pathname: path.join(__dirname, 'index.html'),
    //   protocol: 'file:',
    //   slashes: true
    //   }));
    // })
  
  
}

var stopWorker=function(callback){
 return req(baseUrl + "/DeviceStatus/Stop", callback);
};

req(baseUrl + "/DeviceStatus/Start", function (error, response, body) {
  
});

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();
  }
});

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

// 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', createWindow);

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.
  if (mainWindow === null) {
    createWindow();
  }
});

// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.


// see doc https://github.com/electron/electron/blob/master/docs-translations/zh-CN/api/app.md
// Quit when all windows are closed.
app.on('window-all-closed', function () {
  stopWorker(function (error, response, body) { 
    // On OS X it is common for applications and their menu bar
  // to stay active until the user quits explicitly with Cmd + Q
   // if (process.platform !== 'darwin') {
     app.quit();
    //}
  });
});

app.on('will-quit', function () {
  stopWorker();
});


  // var isStarted =0;// sessionStorage.getItem("iot_SessionHasStarted");
    // if (!isStarted) {
    //     // 如果用户刷新页面,则不要启动服务了,进客户端实例启动时,自动开启服务
    //   sessionStorage.setItem("iot_SessionHasStarted",1);
    //   var baseUrl = localStorage.getItem("iot_baseUrl");
    //   var req = function (url) {
    //     var fileRequest = new XMLHttpRequest();
    //     fileRequest.open('GET', url);
    //     fileRequest.onerror = function (err) {
    //       console.error("Error request " + url, err);
    //     };
    //     fileRequest.onreadystatechange = function () {
    //       if (fileRequest.readyState === 4) {
    //         var text = fileRequest.responseText;
    //         if (fileRequest.status === 200 || fileRequest.status == 0) {
    //           console.log("success request " + url);
    //         } else {
    //           console.error("Error request " + url, text);
    //         }
    //       }
    //     };
    //     fileRequest.send();
    //   }
    //   req(baseUrl + "/DeviceStatus/Start");
    // }

 

 

 

发表评论

电子邮件地址不会被公开。