Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Update app name on topbar based on version #159

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ jobs:
env:
NODE_ENV: production
DEV_RPC: https://rpc-gate.autonolas.tech/gnosis-rpc/
IS_STAGING: ${{ contains(github.ref, 'staging') }}
FORK_URL: https://rpc-gate.autonolas.tech/gnosis-rpc/
- run: rm -rf /dist
- name: "Build, notarize, publish"
Expand Down
3 changes: 1 addition & 2 deletions electron/constants/publishOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ const publishOptions = {
token: process.env.GH_TOKEN,
private: false,
publishAutoUpdate: true,
releaseType: process.env.IS_STAGING === 'true' ? 'prerelease' : 'release',
channel: process.env.IS_STAGING === 'true' ? 'alpha' : 'latest',
releaseType: 'draft',
};

module.exports = { publishOptions };
35 changes: 22 additions & 13 deletions electron/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ const process = require('process');
const { spawnSync } = require('child_process');
const Docker = require('dockerode');

const Version = '0.1.0rc26';
/**
* current version of the pearl release
* - use "" (nothing as a suffix) for latest release candidate, for example "0.1.0rc26"
* - use "alpha" for alpha release, for example "0.1.0rc26-alpha"
*/
const OlasMiddlewareVersion = '0.1.0rc26';
const OperateDirectory = `${os.homedir()}/.operate`;
const VenvDir = `${OperateDirectory}/venv`;
const VersionFile = `${OperateDirectory}/version.txt`;
Expand Down Expand Up @@ -46,7 +51,7 @@ function appendLog(log) {
function runCmdUnix(command, options) {
fs.appendFileSync(
OperateInstallationLog,
`Runninng ${command} with options ${JSON.stringify(options)}`,
`Running ${command} with options ${JSON.stringify(options)}`,
{ encoding: 'utf-8' },
);
let bin = getBinPath(command);
Expand Down Expand Up @@ -78,7 +83,7 @@ function runSudoUnix(command, options) {
if (!bin) {
throw new Error(`Command ${command} not found`);
}
return new Promise(function (resolve, reject) {
return new Promise(function (resolve, _reject) {
sudo.exec(
`${bin} ${options}`,
SudoOptions,
Expand Down Expand Up @@ -157,7 +162,7 @@ function installOperatePackageUnix(path) {
'-m',
'pip',
'install',
`olas-operate-middleware==${Version}`,
`olas-operate-middleware==${OlasMiddlewareVersion}`,
]);
}

Expand All @@ -167,7 +172,7 @@ function reInstallOperatePackageUnix(path) {
'-m',
'pip',
'install',
`olas-operate-middleware==${Version}`,
`olas-operate-middleware==${OlasMiddlewareVersion}`,
'--force-reinstall',
]);
}
Expand All @@ -177,11 +182,11 @@ function installOperateCli(path) {
if (fs.existsSync(installPath)) {
fs.rmSync(installPath);
}
return new Promise((resolve, reject) => {
return new Promise((resolve, _reject) => {
fs.copyFile(
`${OperateDirectory}/venv/bin/operate`,
installPath,
function (error, stdout, stderr) {
function (error, _stdout, _stderr) {
resolve(!error);
},
);
Expand All @@ -192,23 +197,23 @@ function createDirectory(path) {
if (fs.existsSync(path)) {
return;
}
return new Promise((resolve, reject) => {
return new Promise((resolve, _reject) => {
fs.mkdir(path, { recursive: true }, (error) => {
resolve(!error);
});
});
}

function writeVersion() {
fs.writeFileSync(VersionFile, Version);
fs.writeFileSync(VersionFile, OlasMiddlewareVersion);
}

function versionBumpRequired() {
if (!fs.existsSync(VersionFile)) {
return true;
}
const version = fs.readFileSync(VersionFile).toString();
return version != Version;
const olasMiddlewareVersionInFile = fs.readFileSync(VersionFile).toString();
return olasMiddlewareVersionInFile != OlasMiddlewareVersion;
}

function removeLogFile() {
Expand Down Expand Up @@ -265,7 +270,9 @@ async function setupDarwin(ipcChannel) {

console.log(appendLog('Checking if upgrade is required'));
if (versionBumpRequired()) {
console.log(appendLog(`Upgrading pearl daemon to ${Version}`));
console.log(
appendLog(`Upgrading pearl daemon to ${OlasMiddlewareVersion}`),
);
reInstallOperatePackageUnix(OperateDirectory);
writeVersion();
removeLogFile();
Expand Down Expand Up @@ -322,7 +329,9 @@ async function setupUbuntu(ipcChannel) {

console.log(appendLog('Checking if upgrade is required'));
if (versionBumpRequired()) {
console.log(appendLog(`Upgrading pearl daemon to ${Version}`));
console.log(
appendLog(`Upgrading pearl daemon to ${OlasMiddlewareVersion}`),
);
reInstallOperatePackageUnix(OperateDirectory);
writeVersion();
removeLogFile();
Expand Down
5 changes: 4 additions & 1 deletion electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,10 @@ const createMainWindow = () => {
mainWindow.hide();
});

setupStoreIpc(ipcMain, mainWindow);
const storeInitialValues = {
environmentName: process.env.IS_STAGING ? 'staging' : '',
};
setupStoreIpc(ipcMain, mainWindow, storeInitialValues);

if (isDev) {
mainWindow.webContents.openDevTools();
Expand Down
32 changes: 15 additions & 17 deletions electron/store.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
// set schema to validate store data
const schema = {
isInitialFunded: {
type: 'boolean',
default: false,
},
firstStakingRewardAchieved: {
type: 'boolean',
default: false,
},
firstRewardNotificationShown: {
type: 'boolean',
default: false,
},
const defaultSchema = {
environmentName: { type: 'string', default: '' },
isInitialFunded: { type: 'boolean', default: false },
firstStakingRewardAchieved: { type: 'boolean', default: false },
firstRewardNotificationShown: { type: 'boolean', default: false },
};

const setupStoreIpc = async (ipcChannel, mainWindow) => {
const setupStoreIpc = async (ipcChannel, mainWindow, storeInitialValues) => {
const Store = (await import('electron-store')).default;

/** @type import Store from 'electron-store' */
const store = new Store({
schema,
// set default values for store
const schema = Object.assign({}, defaultSchema);
Object.keys(schema).forEach((key) => {
if (storeInitialValues[key] !== undefined) {
schema[key].default = storeInitialValues[key];
}
});

/** @type import Store from 'electron-store' */
const store = new Store({ schema });

store.onDidAnyChange((data) => {
if (mainWindow?.webContents)
mainWindow.webContents.send('store-changed', data);
Expand Down
5 changes: 4 additions & 1 deletion electron/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ const { publishOptions } = require('./constants/publishOptions');
const electronUpdater = require('electron-updater');
const electronLogger = require('electron-log');

const macUpdater = new electronUpdater.MacUpdater({ ...publishOptions });
const macUpdater = new electronUpdater.MacUpdater({
...publishOptions,
channels: ['latest', 'beta', 'alpha'], // automatically update to all channels
});

macUpdater.logger = electronLogger;

Expand Down
6 changes: 5 additions & 1 deletion frontend/components/Layout/TopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import styled from 'styled-components';

import { COLOR } from '@/constants';
import { useElectronApi } from '@/hooks/useElectronApi';
import { useStore } from '@/hooks/useStore';

const { Text } = Typography;

Expand Down Expand Up @@ -48,6 +49,9 @@ const TopBarContainer = styled.div`

export const TopBar = () => {
const electronApi = useElectronApi();
const store = useStore();
const envName = store?.storeState?.environmentName;

return (
<TopBarContainer>
<TrafficLights>
Expand All @@ -56,7 +60,7 @@ export const TopBar = () => {
<DisabledLight />
</TrafficLights>

<Text>Pearl (alpha)</Text>
<Text>{`Pearl (alpha) ${envName ? `(${envName})` : ''}`.trim()}</Text>
</TopBarContainer>
);
};
1 change: 1 addition & 0 deletions frontend/types/ElectronApi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export type ElectronStore = {
environmentName?: string;
isInitialFunded?: boolean;
firstStakingRewardAchieved?: boolean;
firstRewardNotificationShown?: boolean;
Expand Down
Loading