Skip to content

Commit

Permalink
[DDW-920] RTS flags UI/UX improvements (#2842)
Browse files Browse the repository at this point in the history
Co-authored-by: Danilo Prates <daniloprates@gmail.com>
Co-authored-by: Daniel Main <daniel.main.cernhoff@icloud.com>
  • Loading branch information
3 people committed Jan 29, 2022
1 parent 45183bd commit 76ba01b
Show file tree
Hide file tree
Showing 42 changed files with 1,184 additions and 290 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Features

- Added dynamic RTS flags setting ([PR 2758](https://github.com/input-output-hk/daedalus/pull/2758/files))
- Improved UI/UX of RTS flags settings ([PR 2842](https://github.com/input-output-hk/daedalus/pull/2842))
- Updated messages about Cardano node sync on the initial screen ([PR 2827](https://github.com/input-output-hk/daedalus/pull/2827)) ([PR 2831](https://github.com/input-output-hk/daedalus/pull/2831))

### Chores
Expand Down
4 changes: 4 additions & 0 deletions source/common/ipc/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,3 +519,7 @@ export type deriveAddressMainResponse = string;
export const SHOW_ADDRESS_CHANNEL = 'SHOW_ADDRESS_CHANNEL';
export type showAddressRendererRequest = showAddressRendererRequestType;
export type showAddressMainResponse = void;

export const TOGGLE_RTS_FLAGS_MODE_CHANNEL = 'TOGGLE_RTS_FLAGS_MODE_CHANNEL';
export type ToggleRTSFlagsModeRendererRequest = void;
export type ToggleRTSFlagsModeMainResponse = void;
1 change: 1 addition & 0 deletions source/common/ipc/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export const DIALOGS = {
ABOUT: 'ABOUT_DIALOG',
DAEDALUS_DIAGNOSTICS: 'DAEDALUS_DIAGNOSTICS_DIALOG',
ITN_REWARDS_REDEMPTION: 'ITN_REWARDS_REDEMPTION_DIALOG',
TOGGLE_RTS_FLAGS_MODE: 'TOGGLE_RTS_FLAGS_MODE_DIALOG',
};

export const NOTIFICATIONS = {
Expand Down
1 change: 1 addition & 0 deletions source/common/types/cardano-node.types.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ export type CardanoStatus = {
hasBeenConnected: boolean,
cardanoNodePID: number,
cardanoWalletPID: number,
isRTSFlagsModeEnabled: boolean,
};

export type NetworkMagicType = Array<?number>;
Expand Down
1 change: 1 addition & 0 deletions source/common/types/environment.types.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export type Environment = {
os: string,
cpu: string,
ram: number,
hasMetHardwareRequirements: boolean,
installerVersion: string,
version: string,
isWindows: boolean,
Expand Down
2 changes: 2 additions & 0 deletions source/main/cardano/CardanoNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { CardanoSelfnodeLauncher } from './CardanoSelfnodeLauncher';
import { launcherConfig } from '../config';
import type { NodeConfig } from '../config';
import type { Logger } from '../../common/types/logging.types';
import { containsRTSFlags } from '../utils/containsRTSFlags';

/* eslint-disable consistent-return */

Expand Down Expand Up @@ -225,6 +226,7 @@ export class CardanoNode {
return Object.assign({}, this._status, {
cardanoNodePID: get(this, '_node.pid', 0),
cardanoWalletPID: get(this, '_node.wpid', 0),
isRTSFlagsModeEnabled: containsRTSFlags(this._config.rtsFlags),
});
}

Expand Down
2 changes: 0 additions & 2 deletions source/main/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@ export const BLOCK_REPLAY_PROGRESS_CHECK_INTERVAL = 1 * 1000; // 1 seconds | uni
export const FALLBACK_TOKEN_METADATA_SERVER_URL =
'https://metadata.cardano-testnet.iohkdev.io';

export const MINIMUM_AMOUNT_OF_RAM_FOR_RTS_FLAGS = 16 * 1024 * 1024 * 1024; // 16gb RAM

// Used by mock-token-metadata-server
export const MOCK_TOKEN_METADATA_SERVER_URL = 'http://localhost';
export const MOCK_TOKEN_METADATA_SERVER_PORT =
Expand Down
6 changes: 6 additions & 0 deletions source/main/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ import {
checkIsLinux,
} from '../common/utils/environmentCheckers';

// TODO figure out better place for it - can't import from config.js as it would be a circular dep
// https://input-output.atlassian.net/browse/DDW-928
export const RECOMMENDED_RAM_IN_BYTES = 16 * 1024 * 1024 * 1024;

/* ==================================================================
= Evaluations =
================================================================== */
Expand Down Expand Up @@ -49,6 +53,7 @@ const PLATFORM_VERSION = os.release();
const OS = OS_NAMES[PLATFORM] || PLATFORM;
const cpu = os.cpus();
const ram = os.totalmem();
const hasMetHardwareRequirements = ram >= RECOMMENDED_RAM_IN_BYTES;
const isBlankScreenFixActive = includes(process.argv.slice(1), '--safe-mode');
const BUILD = process.env.BUILD_NUMBER || 'dev';
const BUILD_NUMBER = uniq([API_VERSION, BUILD]).join('.');
Expand Down Expand Up @@ -97,6 +102,7 @@ export const environment: Environment = Object.assign(
isLinux,
isBlankScreenFixActive,
keepLocalClusterRunning,
hasMetHardwareRequirements,
},
process.env
);
48 changes: 24 additions & 24 deletions source/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os from 'os';
import path from 'path';
import { app, dialog, BrowserWindow, screen, shell } from 'electron';
import type { Event } from 'electron';
import { client } from 'electron-connect';
import EventEmitter from 'events';
import { requestElectronStore } from './ipc/electronStoreConversation';
Expand All @@ -21,16 +22,14 @@ import mainErrorHandler from './utils/mainErrorHandler';
import {
launcherConfig,
pubLogsFolderPath,
stateDirectoryPath,
RTS_FLAGS,
MINIMUM_AMOUNT_OF_RAM_FOR_RTS_FLAGS,
stateDirectoryPath,
} from './config';
import { setupCardanoNode } from './cardano/setup';
import { CardanoNode } from './cardano/CardanoNode';
import { safeExitWithCode } from './utils/safeExitWithCode';
import { buildAppMenus } from './utils/buildAppMenus';
import { getLocale } from './utils/getLocale';
import { getRtsFlags, setRtsFlagsAndRestart } from './utils/rtsFlags';
import { detectSystemLocale } from './utils/detectSystemLocale';
import { ensureXDGDataIsSet } from './cardano/config';
import { rebuildApplicationMenu } from './ipc/rebuild-application-menu';
Expand All @@ -51,6 +50,12 @@ import {
restoreSavedWindowBounds,
saveWindowBoundsOnSizeAndPositionChange,
} from './windows/windowBounds';
import {
getRtsFlagsSettings,
storeRtsFlagsSettings,
} from './utils/rtsFlagsSettings';
import { toggleRTSFlagsModeChannel } from './ipc/toggleRTSFlagsModeChannel';
import { containsRTSFlags } from './utils/containsRTSFlags';

/* eslint-disable consistent-return */

Expand Down Expand Up @@ -110,6 +115,12 @@ const safeExit = async () => {
}
};

const handleWindowClose = async (event: ?Event) => {
logger.info('mainWindow received <close> event. Safe exiting Daedalus now.');
event?.preventDefault();
await safeExit();
};

const onAppReady = async () => {
setupLogging();
logUsedVersion(
Expand Down Expand Up @@ -166,23 +177,12 @@ const onAppReady = async () => {
);
saveWindowBoundsOnSizeAndPositionChange(mainWindow, requestElectronStore);

const getCurrentRtsFlags = () => {
const rtsFlagsFromStorage = getRtsFlags(network);
if (!rtsFlagsFromStorage) {
if (os.totalmem() < MINIMUM_AMOUNT_OF_RAM_FOR_RTS_FLAGS) {
setRtsFlagsAndRestart(environment.network, RTS_FLAGS);
return RTS_FLAGS;
}
return [];
}
return rtsFlagsFromStorage;
};
const currentRtsFlags = getRtsFlagsSettings(network) || [];

const rtsFlags = getCurrentRtsFlags();
logger.info(
`Setting up Cardano Node... with flags: ${JSON.stringify(rtsFlags)}`
`Setting up Cardano Node... with flags: ${JSON.stringify(currentRtsFlags)}`
);
cardanoNode = setupCardanoNode(launcherConfig, mainWindow, rtsFlags);
cardanoNode = setupCardanoNode(launcherConfig, mainWindow, currentRtsFlags);

buildAppMenus(mainWindow, cardanoNode, userLocale, {
isNavigationEnabled: false,
Expand Down Expand Up @@ -233,6 +233,12 @@ const onAppReady = async () => {

getSystemLocaleChannel.onRequest(() => Promise.resolve(systemLocale));

toggleRTSFlagsModeChannel.onReceive(() => {
const flagsToSet = containsRTSFlags(currentRtsFlags) ? [] : RTS_FLAGS;
storeRtsFlagsSettings(environment.network, flagsToSet);
return handleWindowClose();
});

const handleCheckDiskSpace = handleDiskSpace(mainWindow, cardanoNode);
const onMainError = (error: string) => {
if (error.indexOf('ENOSPC') > -1) {
Expand All @@ -249,13 +255,7 @@ const onAppReady = async () => {
client.create(mainWindow);
}

mainWindow.on('close', async (event) => {
logger.info(
'mainWindow received <close> event. Safe exiting Daedalus now.'
);
event.preventDefault();
await safeExit();
});
mainWindow.on('close', handleWindowClose);

// Security feature: Prevent creation of new browser windows
// https://github.com/electron/electron/blob/master/docs/tutorial/security.md#14-disable-or-limit-creation-of-new-windows
Expand Down
12 changes: 12 additions & 0 deletions source/main/ipc/toggleRTSFlagsModeChannel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// @flow
import { TOGGLE_RTS_FLAGS_MODE_CHANNEL } from '../../common/ipc/api';
import type {
ToggleRTSFlagsModeMainResponse,
ToggleRTSFlagsModeRendererRequest,
} from '../../common/ipc/api';
import { MainIpcChannel } from './lib/MainIpcChannel';

export const toggleRTSFlagsModeChannel: MainIpcChannel<
ToggleRTSFlagsModeRendererRequest,
ToggleRTSFlagsModeMainResponse
> = new MainIpcChannel(TOGGLE_RTS_FLAGS_MODE_CHANNEL);
2 changes: 1 addition & 1 deletion source/main/menus/MenuActions.types.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow
export type MenuActions = {
toggleBlankScreenFix: Function,
setRtsFlags: Function,
openToggleRTSFlagsModeDialog: Function,
openAboutDialog: Function,
openDaedalusDiagnosticsDialog: Function,
openItnRewardsRedemptionDialog: Function,
Expand Down
30 changes: 2 additions & 28 deletions source/main/menus/osx.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ import { environment } from '../environment';
import { showUiPartChannel } from '../ipc/control-ui-parts';
import { NOTIFICATIONS } from '../../common/ipc/constants';
import { generateSupportRequestLink } from '../../common/utils/reporting';
import { getRtsFlags } from '../utils/rtsFlags';
import { buildKnownIssueFixesSubmenu } from './submenuBuilders';

const id = 'menu';
const { isBlankScreenFixActive, network } = environment;
const rtsFlags = getRtsFlags(network);
const rtsFlagsEnabled: boolean = !!rtsFlags?.length && rtsFlags.length > 0;

export const osxMenu = (
app: App,
Expand Down Expand Up @@ -142,30 +139,7 @@ export const osxMenu = (
{
label: translation('helpSupport'),
submenu: compact([
{
label: translation('helpSupport.knownIssues'),
click() {
const faqLink = translation('helpSupport.knownIssuesUrl');
shell.openExternal(faqLink);
},
},
{
label: translation('helpSupport.blankScreenFix'),
type: 'checkbox',
checked: isBlankScreenFixActive,
click(item) {
actions.toggleBlankScreenFix(item);
},
},
{
label: translation('helpSupport.usingRtsFlags'),
type: 'checkbox',
checked: rtsFlagsEnabled,
click(item) {
actions.setRtsFlags(!rtsFlagsEnabled);
item.checked = rtsFlagsEnabled;
},
},
...buildKnownIssueFixesSubmenu(actions, translations, translation),
{ type: 'separator' },
{
label: translation('helpSupport.safetyTips'),
Expand Down
45 changes: 45 additions & 0 deletions source/main/menus/submenuBuilders.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// @flow
import { shell } from 'electron';
import type { MenuItem } from 'electron';
import { getRtsFlagsSettings } from '../utils/rtsFlagsSettings';
import { environment } from '../environment';
import type { MenuActions } from './MenuActions.types';
import { getTranslation } from '../utils/getTranslation';

export const buildKnownIssueFixesSubmenu = (
actions: MenuActions,
translations: {},
translate: Function = getTranslation(translations, 'menu')
): MenuItem[] => {
const { isBlankScreenFixActive, network } = environment;
const rtsFlags = getRtsFlagsSettings(network);
const areRTSFlagsEnabled = !!rtsFlags?.length && rtsFlags.length > 0;

return [
{
label: translate('helpSupport.knownIssues'),
click() {
const faqLink = translate('helpSupport.knownIssuesUrl');
shell.openExternal(faqLink);
},
},
{
label: translate('helpSupport.blankScreenFix'),
type: 'checkbox',
checked: isBlankScreenFixActive,
click(item) {
actions.toggleBlankScreenFix(item);
},
},
{
label: translate('helpSupport.usingRtsFlags'),
type: 'checkbox',
checked: areRTSFlagsEnabled,
click(item) {
actions.openToggleRTSFlagsModeDialog(!areRTSFlagsEnabled);
// keep previous setting until app restart
item.checked = areRTSFlagsEnabled;
},
},
];
};
32 changes: 3 additions & 29 deletions source/main/menus/win-linux.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ import { environment } from '../environment';
import { NOTIFICATIONS } from '../../common/ipc/constants';
import { showUiPartChannel } from '../ipc/control-ui-parts';
import { generateSupportRequestLink } from '../../common/utils/reporting';
import { getRtsFlags } from '../utils/rtsFlags';
import { buildKnownIssueFixesSubmenu } from './submenuBuilders';

const id = 'menu';
const { isWindows, isBlankScreenFixActive, network } = environment;
const rtsFlags = getRtsFlags(network);
const rtsFlagsEnabled: boolean = !!rtsFlags?.length && rtsFlags.length > 0;

export const winLinuxMenu = (
app: App,
Expand Down Expand Up @@ -123,7 +120,7 @@ export const winLinuxMenu = (
{
type: 'separator',
},
isWindows
environment.isWindows
? {
label: translation('view.toggleFullScreen'),
accelerator: 'F11',
Expand Down Expand Up @@ -154,30 +151,7 @@ export const winLinuxMenu = (
{
label: translation('helpSupport'),
submenu: compact([
{
label: translation('helpSupport.knownIssues'),
click() {
const faqLink = translation('helpSupport.knownIssuesUrl');
shell.openExternal(faqLink);
},
},
{
label: translation('helpSupport.blankScreenFix'),
type: 'checkbox',
checked: isBlankScreenFixActive,
click(item) {
actions.toggleBlankScreenFix(item);
},
},
{
label: translation('helpSupport.usingRtsFlags'),
type: 'checkbox',
checked: rtsFlagsEnabled,
click(item) {
actions.setRtsFlags(!rtsFlagsEnabled);
item.checked = rtsFlagsEnabled;
},
},
...buildKnownIssueFixesSubmenu(actions, translations, translation),
{ type: 'separator' },
{
label: translation('helpSupport.safetyTips'),
Expand Down
Loading

0 comments on commit 76ba01b

Please sign in to comment.