Skip to content

Commit

Permalink
Fix #10173 - Prevent lag in external monitors when using Mac + Chrome (
Browse files Browse the repository at this point in the history
  • Loading branch information
darkwing authored Apr 30, 2021
1 parent 5928bc0 commit 04ab1e7
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 1 deletion.
9 changes: 9 additions & 0 deletions app/scripts/controllers/app-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default class AppStateController extends EventEmitter {
timeoutMinutes: 0,
connectedStatusPopoverHasBeenShown: true,
defaultHomeActiveTabName: null,
browserEnvironment: {},
...initState,
});
this.timer = null;
Expand Down Expand Up @@ -158,4 +159,12 @@ export default class AppStateController extends EventEmitter {
timeoutMinutes * 60 * 1000,
);
}

/**
* Sets the current browser and OS environment
* @returns {void}
*/
setBrowserEnvironment(os, browser) {
this.store.updateState({ browserEnvironment: { os, browser } });
}
}
11 changes: 11 additions & 0 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,17 @@ export default class MetamaskController extends EventEmitter {
this.submitPassword(password);
}

// Lazily update the store with the current extension environment
this.extension.runtime.getPlatformInfo(({ os }) => {
this.appStateController.setBrowserEnvironment(
os,
// This method is presently only supported by Firefox
this.extension.runtime.getBrowserInfo === undefined
? 'chrome'
: 'firefox',
);
});

// TODO:LegacyProvider: Delete
this.publicConfigStore = this.createPublicConfigStore();
}
Expand Down
1 change: 1 addition & 0 deletions app/scripts/metamask-controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const ExtensionizerMock = {
onInstalled: {
addListener: () => undefined,
},
getPlatformInfo: async () => 'mac',
},
};

Expand Down
17 changes: 17 additions & 0 deletions ui/css/itcss/components/newui-sections.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,23 @@ $sub-mid-size-breakpoint-range: "screen and (min-width: #{$break-large}) and (ma
align-items: center;
}

// Fix for UI lag on external monitor: https://github.com/MetaMask/metamask-extension/issues/10173
.app.os-mac.browser-chrome::after {
content: "";
position: fixed;
top: 0;
left: 0;
width: 1px;
height: 1px;
background-color: $Grey-000;
animation: emptySpinningDiv 1s infinite linear;
}

@keyframes emptySpinningDiv {
0% { transform: rotate(0deg); }
to { transform: rotate(1turn); }
}

// Main container
.main-container {
z-index: $main-container-z-index;
Expand Down
9 changes: 8 additions & 1 deletion ui/pages/routes/routes.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export default class Routes extends Component {
autoLockTimeLimit: PropTypes.number,
pageChanged: PropTypes.func.isRequired,
prepareToLeaveSwaps: PropTypes.func,
browserEnvironment: PropTypes.object,
};

static contextTypes = {
Expand Down Expand Up @@ -275,6 +276,7 @@ export default class Routes extends Component {
submittedPendingTransactions,
isMouseUser,
prepareToLeaveSwaps,
browserEnvironment,
} = this.props;
const loadMessage =
loadingMessage || isNetworkLoading
Expand All @@ -296,9 +298,14 @@ export default class Routes extends Component {
({ id }) => id === sidebarTransaction.id,
);

const { os, browser } = browserEnvironment;
return (
<div
className={classnames('app', { 'mouse-user-styles': isMouseUser })}
className={classnames('app', {
[`os-${os}`]: os,
[`browser-${browser}`]: browser,
'mouse-user-styles': isMouseUser,
})}
dir={textDirection}
onClick={() => setMouseUserState(true)}
onKeyDown={(e) => {
Expand Down
1 change: 1 addition & 0 deletions ui/pages/routes/routes.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function mapStateToProps(state) {
isMouseUser: state.appState.isMouseUser,
providerId: getNetworkIdentifier(state),
autoLockTimeLimit,
browserEnvironment: state.metamask.browserEnvironment,
};
}

Expand Down

0 comments on commit 04ab1e7

Please sign in to comment.