Skip to content

Commit

Permalink
feat: integrated check-for-updates ipc, seperated configs for OTA and…
Browse files Browse the repository at this point in the history
… publish
  • Loading branch information
truemiller committed Jul 11, 2024
1 parent ae791ac commit e5d6709
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 26 deletions.
14 changes: 12 additions & 2 deletions build.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
/**
* This script is used to build the electron app **with notarization**. It is used for the final build and release process.
* This script is used to build, release, code sign and notarize the app.
* It is used for the final build and release process.
*/
import { config } from "dotenv"
import { build } from "electron-builder"
import { publishOptions } from "./electron/constants/options.mjs"

config();

const publishOptions = {
provider: 'github',
owner: 'valory-xyz',
repo: 'olas-operate-app',
releaseType: 'draft',
token: process.env.GH_TOKEN,
private: false,
publishAutoUpdate: true,
};

const main = async () => {
console.log("Building...");

Expand Down
10 changes: 0 additions & 10 deletions electron/constants/options.mjs

This file was deleted.

5 changes: 5 additions & 0 deletions electron/dev-app-update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
provider: github
owner: valory-xyz
repo: olas-operate-app
channel: latest
releaseType: draft
33 changes: 28 additions & 5 deletions electron/main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ async function launchNextAppDev() {
});
}

// Fires after splash screen is loaded
ipcMain.on('check', async function (event, _argument) {
// Setup
try {
Expand Down Expand Up @@ -498,14 +499,10 @@ app.on('before-quit', async () => {
});

// UPDATER EVENTS
macUpdater.on('update-downloaded', () => {
macUpdater.once('update-downloaded', () => {
mainWindow.webContents.send('update-downloaded');
});

macUpdater.on('update-available', (info) => {
mainWindow.webContents.send('update-available', info);
});

macUpdater.on('download-progress', (progress) => {
mainWindow.webContents.send('download-progress', progress);
});
Expand All @@ -518,6 +515,32 @@ ipcMain.on('install-update', () => {
macUpdater.quitAndInstall();
});

// const checkForUpdates = async () => {
// macUpdater.once('update-available', (info) => {
// logger.electron('Update available.');
// logger.electron(`Version: ${info.version}`);
// resolve({
// available: true,
// version: info.version,
// message: info.releaseNotes,
// });
// });

// macUpdater.once('update-not-available', () => {
// logger.electron('No updates available.');
// resolve({ available: false, message: 'No updates available.' });
// });

// macUpdater.once('error', (error) => {
// logger.electron('Error in auto-updater:', error);
// reject(error);
// });

// macUpdater.checkForUpdates();
// };

ipcMain.handle('check-for-updates', async () => macUpdater.checkForUpdates());

// PROCESS SPECIFIC EVENTS (HANDLES NON-GRACEFUL TERMINATION)
process.on('uncaughtException', (error) => {
logger.electron('Uncaught Exception:', error);
Expand Down
3 changes: 2 additions & 1 deletion electron/preload.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ contextBridge.exposeInMainWorld('electronAPI', {
openPath: (filePath) => ipcRenderer.send('open-path', filePath),
saveLogs: (data) => ipcRenderer.invoke('save-logs', data),

// update downloads
// OTA updates
checkUpdates: () => ipcRenderer.invoke('check-for-updates'),
startDownload: () => ipcRenderer.send('start-download'),
quitAndInstall: () => ipcRenderer.send('install-update'),
});
1 change: 1 addition & 0 deletions electron/store.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const defaultSchema = {
version: { type: 'string', default: '' },
environmentName: { type: 'string', default: '' },
isInitialFunded: { type: 'boolean', default: false },
firstStakingRewardAchieved: { type: 'boolean', default: false },
Expand Down
15 changes: 12 additions & 3 deletions electron/update.mjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
import { MacUpdater } from 'electron-updater';

import { publishOptions } from './constants/options.mjs';
import { isDev } from './constants/env.mjs';
import { logger } from './utils/logger.mjs';

const macUpdater = new MacUpdater(publishOptions);
export const updateOptions = {
provider: 'github',
owner: 'valory-xyz',
repo: 'olas-operate-app',
releaseType: 'draft',
private: false,
};

macUpdater.setFeedURL({ ...publishOptions });
const macUpdater = new MacUpdater(updateOptions);

macUpdater.setFeedURL({ ...updateOptions });

macUpdater.autoDownload = false;
macUpdater.autoInstallOnAppQuit = false;
macUpdater.logger = logger;
macUpdater.forceDevUpdateConfig = isDev;

export { macUpdater };
7 changes: 4 additions & 3 deletions electron/utils/icons.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { nativeImage } from 'electron';

import { isMac } from '../constants/os.mjs';
import { isLinux, isMac } from '../constants/os.mjs';
import { logger } from './logger.mjs';

const TRAY_ICONS_PATHS = {
LOGGED_OUT: `${import.meta.dirname}/assets/icons/tray-logged-out.png`,
Expand All @@ -17,7 +18,7 @@ const TRAY_ICONS = {
};

try {
if (isMac) {
if (isMac || isLinux) {
// resize icons for macOS
const size = { width: 16, height: 16 };
TRAY_ICONS.LOGGED_OUT = TRAY_ICONS.LOGGED_OUT.resize(size);
Expand All @@ -26,7 +27,7 @@ try {
TRAY_ICONS.RUNNING = TRAY_ICONS.RUNNING.resize({ width: 16, height: 16 });
}
} catch (e) {
console.log('Error resizing tray icons', e);
logger.electron('Error resizing tray icons', e);
}

export { TRAY_ICONS, TRAY_ICONS_PATHS };
2 changes: 1 addition & 1 deletion electron/utils/logger.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const logger = winston.createLogger({
new winston.transports.File({
filename: 'electron.log',
dirname: paths.dotOperateDirectory,
level: 'electron',
levels: ['electron'],
format: combine(levelFilter('electron'), timestamp(), logFormat),
maxFiles: 1,
maxsize: 1024 * 1024 * 10,
Expand Down
9 changes: 8 additions & 1 deletion frontend/components/Settings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useMemo } from 'react';
import { UNICODE_SYMBOLS } from '@/constants/symbols';
import { PageState } from '@/enums/PageState';
import { SettingsScreen } from '@/enums/SettingsScreen';
import { useElectronApi } from '@/hooks/useElectronApi';
import { useMasterSafe } from '@/hooks/useMasterSafe';
import { usePageState } from '@/hooks/usePageState';
import { useSettings } from '@/hooks/useSettings';
Expand Down Expand Up @@ -49,6 +50,7 @@ export const Settings = () => {
const SettingsMain = () => {
const { backupSafeAddress } = useMasterSafe();
const { goto } = usePageState();
const { checkUpdates } = useElectronApi();

const truncatedBackupSafeAddress: string | undefined = useMemo(() => {
if (backupSafeAddress) {
Expand Down Expand Up @@ -89,6 +91,11 @@ const SettingsMain = () => {
<NoBackupWallet />
)}
</CardSection>
<CardSection borderbottom="true" vertical gap={8}>
<Button onClick={checkUpdates} color="primary" size="large">
Check for updates
</Button>
</CardSection>

<DebugInfoCard />
</Card>
Expand Down Expand Up @@ -120,7 +127,7 @@ const NoBackupWallet = () => {
<Button
type="primary"
size="large"
disabled={true} // not in this iteration?
disabled={true} // TODO: enable when feature is ready
onClick={() => gotoSettings(SettingsScreen.AddBackupWallet)}
>
Add backup wallet
Expand Down
2 changes: 2 additions & 0 deletions frontend/context/ElectronApiProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type ElectronApiContextProps = {
openPath?: (filePath: string) => void;

// download new updates
checkUpdates?: () => Promise<void>;
startDownload?: () => Promise<void>;
quitAndInstall?: () => void;
};
Expand All @@ -58,6 +59,7 @@ export const ElectronApiContext = createContext<ElectronApiContextProps>({
openPath: () => {},

// download updates
checkUpdates: async () => {},
startDownload: async () => {},
quitAndInstall: async () => {},
});
Expand Down

0 comments on commit e5d6709

Please sign in to comment.