Skip to content

Commit

Permalink
maybe working?
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaellehmkuhl committed Oct 10, 2024
1 parent c15a9a7 commit f7251b2
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 1 deletion.
3 changes: 3 additions & 0 deletions dev-app-update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
owner: bluerobotics
repo: cockpit
provider: github
80 changes: 80 additions & 0 deletions electron/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { app, BrowserWindow, protocol, screen } from 'electron'
import electronUpdater, { type AppUpdater } from 'electron-updater'
import { join } from 'path'

export const ROOT_PATH = {
Expand Down Expand Up @@ -36,6 +37,24 @@ function createWindow(): void {
}
}

// Function to log messages to the testSpan element
/**
* Log a message to the testSpan element in the main window
* @param {string} message - The message to log
* @returns {void}
*/
function internalLog(message: string): void {
if (!mainWindow || mainWindow.isDestroyed()) {
console.log('Main window is not available.')
return
}

console.log(message)
mainWindow.webContents.executeJavaScript(`
console.log('${message}')
`)
}

app.on('window-all-closed', () => {
console.log('Closing application.')
mainWindow = null
Expand All @@ -61,3 +80,64 @@ protocol.registerSchemesAsPrivileged([
])

app.whenReady().then(createWindow)

/**
* Get auto updater instance
* @returns {AppUpdater}
* @see https://www.electron.build/auto-update
*/
function getAutoUpdater(): AppUpdater {
// Using destructuring to access autoUpdater due to the CommonJS module of 'electron-updater'.
// It is a workaround for ESM compatibility issues, see https://github.com/electron-userland/electron-builder/issues/7976.
const { autoUpdater } = electronUpdater
autoUpdater.logger = require('electron-log')
// @ts-ignore
autoUpdater.logger.transports.file.level = 'info'
return autoUpdater
}

app.whenReady().then(() => {
internalLog('Electron app is ready.')

// Check for software updates
internalLog('Will start update checking routine...')

const autoUpdater = getAutoUpdater()
autoUpdater.forceDevUpdateConfig = true

autoUpdater.on('checking-for-update', () => {
internalLog('Checking for update...')
})
autoUpdater.on('update-available', (info) => {
internalLog('Update available.')
internalLog(JSON.stringify(info))
})
autoUpdater.on('update-not-available', (info) => {
internalLog('Update not available.')
internalLog(JSON.stringify(info))
})
autoUpdater.on('error', (err) => {
internalLog('Error in auto-updater. ' + err)
})
autoUpdater.on('download-progress', (progressObj) => {
let log_message = 'Download speed: ' + progressObj.bytesPerSecond
log_message = log_message + ' - Downloaded ' + progressObj.percent + '%'
log_message = log_message + ' (' + progressObj.transferred + '/' + progressObj.total + ')'
internalLog(log_message)
})
autoUpdater.on('update-downloaded', (info) => {
internalLog('Update downloaded')
internalLog(JSON.stringify(info))
})

autoUpdater
.checkForUpdates()
.then((e) => {
internalLog(e)
})
.catch((e) => {
internalLog(e)
})

internalLog(`Cockpit version: ${app.getVersion()}`)
})
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cockpit",
"version": "0.0.0",
"version": "1.2.1",
"private": true,
"main": "dist/electron/main.js",
"description": "An intuitive and customizable cross-platform ground control station for remote vehicles of all types.",
Expand Down Expand Up @@ -121,6 +121,10 @@
],
"appId": "org.bluerobotics.cockpit",
"productName": "Cockpit",
"publish": {
"provider": "github",
"owner": "bluerobotics"
},
"mac": {
"category": "public.app-category.utilities",
"icon": "public/pwa-512x512.png"
Expand Down

0 comments on commit f7251b2

Please sign in to comment.