Skip to content

Commit

Permalink
refactor: remove manual auto update (#177)
Browse files Browse the repository at this point in the history
Co-authored-by: frami <[email protected]>
  • Loading branch information
kuruk-mm and 2fd authored May 16, 2023
1 parent 8f39519 commit bb39b1a
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 192 deletions.
59 changes: 16 additions & 43 deletions electron/main.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
import { shell, app, BrowserWindow, ipcMain, Tray, Menu, crashReporter, systemPreferences } from 'electron'
import * as isDev from 'electron-is-dev'
import { getOSName, getFreePort } from './updater'
import { exit } from 'process'
import { autoUpdater } from 'electron-updater'
import { parseConfig } from './cmdParser'
import { getAppTitle, getAppBasePath } from './helpers'
import {
createWindow,
hideWindowInTray,
loadDecentralandWeb,
onOpenUrl,
reportNewLauncherVersion,
showWindowAndHideTray
} from './window'
import { createWindow, hideWindowInTray, loadDecentralandWeb, onOpenUrl, showWindowAndHideTray } from './window'
import { LauncherConfig, LauncherPaths } from './types'
import { isTrustedCertificate } from './certificateChecker'
import { reportError, initializeRollbar } from './rollbar'
import * as semver from 'semver'
import fs = require('fs')

const defaultConfig: LauncherConfig = {
Expand Down Expand Up @@ -99,34 +90,16 @@ if (getOSName() === 'windows') {

const checkUpdates = async (win: BrowserWindow): Promise<void> => {
try {
if (getOSName() === 'mac') {
// No updates in Mac until we signed the executable
const installedVersion = autoUpdater.currentVersion.version
autoUpdater.autoDownload = false
const result = await autoUpdater.checkForUpdates()
const newVersion = result?.updateInfo.version
console.log('Mac Result:', result)
console.log('Compare versions', installedVersion, 'vs', newVersion)

if (newVersion && semver.lt(installedVersion, newVersion)) {
const macDownloadUrl =
'https://github.com/decentraland/explorer-desktop-launcher/releases/latest/download/Decentraland.dmg'
await reportNewLauncherVersion(win, macDownloadUrl)
} else {
await loadDecentralandWeb(win) // Load decentraland web to report the error
}
const result = await autoUpdater.checkForUpdatesAndNotify()
console.log('Result:', result)
if (result === null || !result.downloadPromise) {
await loadDecentralandWeb(win)
} else {
const result = await autoUpdater.checkForUpdatesAndNotify()
console.log('Result:', result)
if (result === null || !result.downloadPromise) {
await loadDecentralandWeb(win)
} else {
await result.downloadPromise

console.log('Download completed')
const silent = process.platform === 'darwin' // Silent=true only on Mac
autoUpdater.quitAndInstall(silent, true)
}
await result.downloadPromise

console.log('Download completed')
const silent = process.platform === 'darwin' // Silent=true only on Mac
autoUpdater.quitAndInstall(silent, true)
}
} catch (err) {
console.error(`Check Updates error: ${err}`)
Expand Down Expand Up @@ -202,7 +175,7 @@ const startApp = async (): Promise<void> => {
await checkUpdates(win)
}

const microphoneResult = await askForMediaAccess('microphone');
const microphoneResult = await askForMediaAccess('microphone')
if (!microphoneResult) {
console.log('Microphone permission was not given')
}
Expand Down Expand Up @@ -247,7 +220,7 @@ app

function initializeCrashReport() {
var path = getAppBasePath()
if (!fs.existsSync(path)) fs.mkdir(path, () => { })
if (!fs.existsSync(path)) fs.mkdir(path, () => {})

app.setPath('crashDumps', path)

Expand All @@ -257,12 +230,12 @@ function initializeCrashReport() {
const askForMediaAccess = async (mediaType: 'microphone' | 'camera') => {
if (systemPreferences.askForMediaAccess) {
// Electron currently only implements this on macOS
const previous = await systemPreferences.getMediaAccessStatus(mediaType);
const result = await systemPreferences.askForMediaAccess(mediaType);
const next = await systemPreferences.getMediaAccessStatus(mediaType);
const previous = await systemPreferences.getMediaAccessStatus(mediaType)
const result = await systemPreferences.askForMediaAccess(mediaType)
const next = await systemPreferences.getMediaAccessStatus(mediaType)
console.log(`MediaAccess for ${mediaType} is went from ${previous} to ${next} (askForMediaAccess: ${result})`)
return result
}
// For other platforms we can't reasonably do anything other than assume we have access.
return true;
return true
}
18 changes: 5 additions & 13 deletions electron/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,6 @@ export const loadDefaultWeb = async (win: BrowserWindow) => {
await win.loadURL(`file://${__dirname}/../../public/index.html#v${app.getVersion()}`)
}

export const reportNewLauncherVersion = async (win: BrowserWindow, updateUrl: string) => {
await win.loadURL(`file://${__dirname}/../../public/new-version.html`)

win.webContents.send('setUrl', { url: updateUrl })
}

export const checkDeveloperConsole = (win: BrowserWindow) => {
if (isDev || main.config.developerMode) {
win.webContents.openDevTools({ mode: 'detach' })
Expand Down Expand Up @@ -132,13 +126,11 @@ export const loadDecentralandWeb = async (win: BrowserWindow) => {

const stage = main.config.developerMode ? 'zone' : 'org'
const url = new URL(main.config.customUrl || `http://play.decentraland.${stage}/?`)

if (main.config.desktopBranch)
url.searchParams.append('explorer-branch', main.config.desktopBranch)

if (main.config.customDesktopVersion)
url.searchParams.append('explorer-version', main.config.customDesktopVersion)


if (main.config.desktopBranch) url.searchParams.append('explorer-branch', main.config.desktopBranch)

if (main.config.customDesktopVersion) url.searchParams.append('explorer-version', main.config.customDesktopVersion)

const customParamObj = new URLSearchParams(main.config.customParams)
for (const [key, value] of Array.from(customParamObj.entries())) {
url.searchParams.append(key, value)
Expand Down
5 changes: 2 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "explorer-desktop-launcher",
"version": "0.1.51",
"version": "0.1.52",
"author": "decentraland",
"description": "Decentraland Desktop Launcher",
"homepage": ".",
Expand All @@ -15,7 +15,6 @@
"find-free-port": "^2.0.0",
"node-stream-zip": "^1.15.0",
"rollbar": "^2.26.1",
"semver": "^7.3.8",
"web-vitals": "^1.1.2"
},
"devDependencies": {
Expand Down Expand Up @@ -142,4 +141,4 @@
"last 1 safari version"
]
}
}
}
130 changes: 0 additions & 130 deletions public/new-version.html

This file was deleted.

0 comments on commit bb39b1a

Please sign in to comment.