Commit 4721d7f0 authored by Jan Loewe's avatar Jan Loewe 💬
Browse files

feat(electron-updater): add base settings

parent 93940e0d
Loading
Loading
Loading
Loading
Loading
+8 −7
Original line number Diff line number Diff line
stages:
  - build
  - release

nuxt:
  stage: build
@@ -17,8 +16,8 @@ nuxt:
    paths:
      - dist/

release:
  stage: release
electron:
  stage: build
  image: node
  cache:
    paths:
@@ -26,8 +25,10 @@ release:
      - .yarn
  before_script:
    - yarn install --frozen-lockfile
  only:
    - master
  script:
    - tar -zcf dist.tar.gz dist
    - npx semantic-release
    - npm run electron:build
  dependencies:
    - nuxt
  artifacts:
    paths:
      - electron-dist/
+2 −0
Original line number Diff line number Diff line
@@ -26,6 +26,8 @@
    "concurrently": "^4.1.0",
    "cross-env": "^5.2.0",
    "dcc-js": "git+https://gitlab+deploy-token-3:kWgoAX9JH_2yDsZKMUD1@gitlab1.ptb.de/jloewe/dcc-js.git",
    "electron-log": "^3.0.5",
    "electron-updater": "^4.0.6",
    "nuxt": "^2.6.3",
    "nuxt-i18n": "^5.12.1",
    "screenfull": "^4.2.0",

src/index.dev.js

0 → 100644
+45 −0
Original line number Diff line number Diff line
const isDev = (process.env.NODE_ENV === "development");

const port = process.env.PORT || 3000;
const host = process.env.HOST || "127.0.0.1";

const url = `http://${host}:${port}`;
// Electron
let win = null; // Current window
const {app, BrowserWindow} = require("electron");
const http = require("http");
const path = require("path");
const newWin = () => {
  win = new BrowserWindow({
    icon: path.join(__dirname, "static/icon.png"),
    webPreferences: {
      webSecurity: false
    }
  });
  win.maximize();
  win.on("closed", () => win = null);
  if (isDev) {
    // Install vue dev tool and open chrome dev tools
    const { default: installExtension, VUEJS_DEVTOOLS } = require("electron-devtools-installer");
    installExtension(VUEJS_DEVTOOLS.id).then(name => {
      console.log(`Added Extension:  ${name}`);
      win.webContents.openDevTools();
    }).catch(err => console.log("An error occurred: ", err));
    // Wait for nuxt to build
    const pollServer = () => {
      http.get(url, (res) => {
        if (res.statusCode === 200) {
          win.loadURL(url);
        } else {
          setTimeout(pollServer, 300);
        }
      }).on("error", pollServer);
    };
    pollServer();
  } else {
    return win.loadFile("dist/index.html");
  }
};
app.on("ready", newWin);
app.on("window-all-closed", () => app.quit());
app.on("activate", () => win === null && newWin());
+112 −44
Original line number Diff line number Diff line
const isDev = (process.env.NODE_ENV === "development");

const port = process.env.PORT || 3000;
const host = process.env.HOST || "127.0.0.1";

const url = `http://${host}:${port}`;
// Electron
let win = null; // Current window
const {app, BrowserWindow} = require("electron");
const http = require("http");
const path = require("path");
const newWin = () => {
  win = new BrowserWindow({
    icon: path.join(__dirname, "static/icon.png"),
    webPreferences: {
      webSecurity: false
const { app, BrowserWindow, Menu, protocol, ipcMain } = require("electron");
const log = require("electron-log");
const { autoUpdater } = require("electron-updater");

autoUpdater.setFeedURL({
  provider: "generic",
  url: "https://gitlab1.ptb.de/d-ptb/dcc/gemimeg-tool/-/jobs/artifacts/feat-electron-updater/raw/electron-dist?job=electron"
});
autoUpdater.logger = log;
autoUpdater.logger.transports.file.level = "info";
log.info("App starting...");

let template = [];
if (process.platform === "darwin") {
  // OS X
  const name = app.getName();
  template.unshift({
    label: name,
    submenu: [
      {
        label: "About " + name,
        role: "about"
      },
      {
        label: "Quit",
        accelerator: "Command+Q",
        click() {
          app.quit();
        }
      }
    ]
  });
  win.maximize();
  win.on("closed", () => win = null);
  if (isDev) {
    // Install vue dev tool and open chrome dev tools
    const { default: installExtension, VUEJS_DEVTOOLS } = require("electron-devtools-installer");
    installExtension(VUEJS_DEVTOOLS.id).then(name => {
      console.log(`Added Extension:  ${name}`);
      win.webContents.openDevTools();
    }).catch(err => console.log("An error occurred: ", err));
    // Wait for nuxt to build
    const pollServer = () => {
      http.get(url, (res) => {
        if (res.statusCode === 200) {
          win.loadURL(url);
        } else {
          setTimeout(pollServer, 300);
}
      }).on("error", pollServer);
    };
    pollServer();
  } else {
    return win.loadFile("dist/index.html");

let win;

function sendStatusToWindow(text) {
  log.info(text);
  win.webContents.send("message", text);
}
};
app.on("ready", newWin);
app.on("window-all-closed", () => app.quit());
app.on("activate", () => win === null && newWin());

function createDefaultWindow() {
  win = new BrowserWindow();
  win.webContents.openDevTools();
  win.on("closed", () => {
    win = null;
  });
  win.loadURL(`file://${__dirname}/dist/index.html#v${app.getVersion()}`);
  return win;
}

autoUpdater.on("checking-for-update", () => {
  sendStatusToWindow("Checking for update...");
});
autoUpdater.on("update-available", (ev, info) => {
  sendStatusToWindow("Update available.");
});
autoUpdater.on("update-not-available", (ev, info) => {
  sendStatusToWindow("Update not available.");
});
autoUpdater.on("error", (ev, err) => {
  sendStatusToWindow("Error in auto-updater.");
});
autoUpdater.on("download-progress", (ev, progressObj) => {
  sendStatusToWindow("Download progress...");
});
autoUpdater.on("update-downloaded", (ev, info) => {
  sendStatusToWindow("Update downloaded; will install in 5 seconds");
});
app.on("ready", function() {
  // Create the Menu
  const menu = Menu.buildFromTemplate(template);
  Menu.setApplicationMenu(menu);

  createDefaultWindow();
});
app.on("window-all-closed", () => {
  app.quit();
});

//-------------------------------------------------------------------
// Auto updates
//
// For details about these events, see the Wiki:
// https://github.com/electron-userland/electron-builder/wiki/Auto-Update#events
//
// The app doesn't need to listen to any events except `update-downloaded`
//
// Uncomment any of the below events to listen for them.  Also,
// look in the previous section to see them being used.
//-------------------------------------------------------------------
// autoUpdater.on('checking-for-update', () => {
// })
// autoUpdater.on('update-available', (ev, info) => {
// })
// autoUpdater.on('update-not-available', (ev, info) => {
// })
// autoUpdater.on('error', (ev, err) => {
// })
// autoUpdater.on('download-progress', (ev, progressObj) => {
// })
autoUpdater.on("update-downloaded", (ev, info) => {
  // Wait 5 seconds, then quit and install
  // In your application, you don't need to wait 5 seconds.
  // You could call autoUpdater.quitAndInstall(); immediately
  setTimeout(function() {
    autoUpdater.quitAndInstall();
  }, 5000);
});

app.on("ready", function() {
  autoUpdater.checkForUpdates();
});
+0 −0

File changed.

Preview suppressed by a .gitattributes entry or the file's encoding is unsupported.