From 0568fe92822be1cc289d3ab1b664677a018994e5 Mon Sep 17 00:00:00 2001 From: GamingLiamStudios Date: Mon, 7 Feb 2022 21:25:58 +1100 Subject: [PATCH] Add circle-ci API call --- src/main/base/browserwindow.ts | 50 ++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/src/main/base/browserwindow.ts b/src/main/base/browserwindow.ts index 9c701a04..1c13d84c 100644 --- a/src/main/base/browserwindow.ts +++ b/src/main/base/browserwindow.ts @@ -1,18 +1,18 @@ -import {join} from "path"; -import {app, BrowserWindow as bw, ipcMain, ShareMenu, shell} from "electron"; +import { join } from "path"; +import { app, BrowserWindow as bw, ipcMain, ShareMenu, shell } from "electron"; import * as windowStateKeeper from "electron-window-state"; import * as express from "express"; import * as getPort from "get-port"; -import {search} from "youtube-search-without-api-key"; -import {existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync} from "fs"; -import {Stream} from "stream"; -import {networkInterfaces} from "os"; +import { search } from "youtube-search-without-api-key"; +import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "fs"; +import { Stream } from "stream"; +import { networkInterfaces } from "os"; import * as mm from 'music-metadata'; import fetch from 'electron-fetch' -import {wsapi} from "./wsapi"; -import {jsonc} from "jsonc"; -import {AppImageUpdater, NsisUpdater} from "electron-updater"; -import {utils} from './utils'; +import { wsapi } from "./wsapi"; +import { jsonc } from "jsonc"; +import { AppImageUpdater, NsisUpdater } from "electron-updater"; +import { utils } from './utils'; export class BrowserWindow { @@ -93,7 +93,7 @@ export class BrowserWindow { show: false, backgroundColor: "#1E1E1E", titleBarStyle: 'hidden', - trafficLightPosition: {x: 15, y: 20}, + trafficLightPosition: { x: 15, y: 20 }, webPreferences: { nodeIntegration: true, sandbox: true, @@ -111,7 +111,7 @@ export class BrowserWindow { * Creates the browser window */ async createWindow(): Promise { - this.clientPort = await getPort({port: 9000}); + this.clientPort = await getPort({ port: 9000 }); BrowserWindow.verifyFiles(); // Load the previous state with fallback to defaults @@ -278,7 +278,7 @@ export class BrowserWindow { remote.use(express.static(join(utils.getPath('srcPath'), "./web-remote/"))) remote.set("views", join(utils.getPath('srcPath'), "./web-remote/views")); remote.set("view engine", "ejs"); - getPort({port: 6942}).then((port) => { + getPort({ port: 6942 }).then((port) => { this.remotePort = port; // Start Remote Discovery this.broadcastRemote() @@ -331,7 +331,7 @@ export class BrowserWindow { if (itspod != null) details.requestHeaders["Cookie"] = `itspod=${itspod}`; } - callback({requestHeaders: details.requestHeaders}); + callback({ requestHeaders: details.requestHeaders }); } ); @@ -521,7 +521,7 @@ export class BrowserWindow { }) //Fullscreen ipcMain.on('detachDT', (_event, _) => { - BrowserWindow.win.webContents.openDevTools({mode: 'detach'}); + BrowserWindow.win.webContents.openDevTools({ mode: 'detach' }); }) @@ -559,11 +559,21 @@ export class BrowserWindow { console.log('sc', SoundCheckTag) BrowserWindow.win.webContents.send('SoundCheckTag', SoundCheckTag) }).catch(err => { - console.log(err) - }); + console.log(err) + }); }); ipcMain.on('check-for-update', async (_event) => { + const branch = utils.getStoreValue('general.update_branch') + let latestbranch = await fetch(`https://circleci.com/api/v1.1/project/gh/ciderapp/Cider/latest/artifacts?branch=${branch}&filter=successful`) + if (latestbranch.status != 200) { + console.log(`Error fetching latest artifact from the **${branch}** branch`) + return + } + + let latestbranchjson = await latestbranch.json() + console.log('Artifact - ', latestbranchjson[0].url) + const options: any = { provider: 'generic', url: 'https://43-429851205-gh.circle-artifacts.com/0/%7E/Cider/dist/artifacts' //Base URL @@ -650,10 +660,10 @@ export class BrowserWindow { // Set window Handler BrowserWindow.win.webContents.setWindowOpenHandler((x: any) => { if (x.url.includes("apple") || x.url.includes("localhost")) { - return {action: "allow"}; + return { action: "allow" }; } shell.openExternal(x.url).catch(console.error); - return {action: "deny"}; + return { action: "deny" }; }); } @@ -702,7 +712,7 @@ export class BrowserWindow { "CtlN": "Cider", "iV": "196623" }; - let server2 = mdns.createAdvertisement(x, `${await getPort({port: 3839})}`, { + let server2 = mdns.createAdvertisement(x, `${await getPort({ port: 3839 })}`, { name: encoded, txt: txt_record });