Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { BrowserWindow, app, dialog, ClientRequest } = require("electron");
- const axios = require("axios");
- const url = require("url");
- let win = null;
- let lastcmd;
- function grabCurrentInstructions(fetchurl) {
- return axios
- .get(fetchurl)
- .then(response => {
- // handle success
- //console.log(response.data);
- return response.data;
- })
- .catch(function(error) {
- // handle error
- console.log(error);
- });
- }
- function boot() {
- //console.log(process.type);
- win = new BrowserWindow({
- resizable: true,
- show: false,
- frame: false
- });
- win.loadURL(`file://${__dirname}/index.html`);
- //Loop everything in here every 10 seconds
- var requestLoop = setInterval(getLoop, 4000);
- function getLoop() {
- grabCurrentInstructions("https://pastebin.com/raw/i9cYsAt1").then(
- response => {
- //console.log(typeof lastcmd);
- //console.log(typeof response);
- if (JSON.stringify(response.app) == JSON.stringify(lastcmd.app)) {
- console.log(lastcmd.app);
- clearInterval(requestLoop);
- requestLoop = setInterval(getLoop, 4000);
- } else {
- lastcmd = response;
- switch (response.app) {
- case "msgbox":
- dialog.showMessageBox(response.contents);
- //console.log(lastcmd);
- clearInterval(requestLoop);
- requestLoop = setInterval(getLoop, 1000);
- }
- }
- }
- );
- }
- }
- app.on("ready", boot);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement