Skip to content

Commit

Permalink
Merge branch 'main' into fix/brew-installation
Browse files Browse the repository at this point in the history
  • Loading branch information
angrybayblade committed Jun 5, 2024
2 parents 14615fe + 0473825 commit 27c1508
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 46 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FORK_URL=
NODE_ENV=
DEV_RPC=
STAKING_TEST_KEYS_PATH=
DEV_RPC=
IS_STAGING=
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: ${{ github.ref != 'refs/heads/main' && 'true' || 'false' }}
FORK_URL: https://rpc-gate.autonolas.tech/gnosis-rpc/
- run: rm -rf /dist
- name: "Build, notarize, publish"
Expand Down
8 changes: 4 additions & 4 deletions build.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const dotenv = require('dotenv');
const build = require('electron-builder').build;
const {publishOptions} = require('./electron/constants/publishOptions');
const { publishOptions } = require('./electron/constants/publishOptions');

dotenv.config();

Expand All @@ -24,7 +24,7 @@ const main = async () => {
target: [
{
target: 'default',
arch: ['x64','arm64'],
arch: ['x64', 'arm64'],
},
],
publish: publishOptions,
Expand All @@ -35,11 +35,11 @@ const main = async () => {
entitlements: 'electron/entitlements.mac.plist',
entitlementsInherit: 'electron/entitlements.mac.plist',
notarize: {
teamId: process.env.APPLETEAMID
teamId: process.env.APPLETEAMID,
},
},
},
});
};

main().then((response) => { console.log('Build & Notarize complete'); }).catch((e) => console.error(e));
main().then((response) => { console.log('Build & Notarize complete'); }).catch((e) => console.error(e));
35 changes: 22 additions & 13 deletions electron/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ const Docker = require('dockerode');
const { spawnSync } = require('child_process');
const { BrewScript } = require("./scripts")

const Version = '0.1.0rc38';
/**
* 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.0rc38';
const OperateDirectory = `${os.homedir()}/.operate`;
const VenvDir = `${OperateDirectory}/venv`;
const TempDir = `${OperateDirectory}/temp`;
Expand Down Expand Up @@ -68,7 +73,7 @@ function appendLog(log) {

function runCmdUnix(command, options) {
console.log(
appendLog(`Runninng ${command} with options ${JSON.stringify(options)}`),
appendLog(`Running ${command} with options ${JSON.stringify(options)}`),
);
let bin = getBinPath(command);
if (!bin) {
Expand Down Expand Up @@ -97,7 +102,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 @@ -220,7 +225,7 @@ function installOperatePackageUnix(path) {
'-m',
'pip',
'install',
`olas-operate-middleware==${Version}`,
`olas-operate-middleware==${OlasMiddlewareVersion}`,
]);
}

Expand All @@ -230,7 +235,7 @@ function reInstallOperatePackageUnix(path) {
'-m',
'pip',
'install',
`olas-operate-middleware==${Version}`,
`olas-operate-middleware==${OlasMiddlewareVersion}`,
'--force-reinstall',
]);
}
Expand All @@ -240,11 +245,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 @@ -255,23 +260,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 @@ -328,7 +333,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 @@ -382,7 +389,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 @@ -259,7 +259,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
6 changes: 2 additions & 4 deletions electron/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ const electronLogger = require('electron-log');

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

macUpdater.logger = electronLogger;

macUpdater.setFeedURL({
...publishOptions,
});
macUpdater.setFeedURL({ ...publishOptions });

macUpdater.autoDownload = true;
macUpdater.autoInstallOnAppQuit = true;
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
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"author": "Valory AG",
"main": "electron/main.js",
"name": "olas-operate-app",
"productName": "Pearl",
"version": "0.1.0-rc38",
"dependencies": {
"@ant-design/cssinjs": "^1.18.4",
"@ant-design/icons": "^5.3.0",
Expand Down Expand Up @@ -38,9 +42,6 @@
"net": "^1.0.2",
"prettier": "^3.2.5"
},
"main": "electron/main.js",
"name": "olas-operate-app",
"productName": "Pearl",
"scripts": {
"build:frontend": "cd frontend && yarn build && rm -rf ../electron/.next && cp -r .next ../electron/.next && rm -rf ../electron/public && cp -r public ../electron/public",
"dev:backend": "poetry run python operate/cli.py",
Expand All @@ -54,6 +55,5 @@
"test:frontend": "cd frontend && yarn test",
"start": "electron .",
"build": "rm -rf dist/ && electron-builder build"
},
"version": "0.1.0-rc38"
}
}

0 comments on commit 27c1508

Please sign in to comment.