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

Add Desktop UI #78

Merged
merged 21 commits into from Oct 28, 2022
Merged

Add Desktop UI #78

merged 21 commits into from Oct 28, 2022

Conversation

OGPoyraz
Copy link
Member

@OGPoyraz OGPoyraz commented Oct 12, 2022

Important Note: This PR is going to get merged into include-desktop-ui-builder PR (already approved), then I will merge include-desktop-ui-builder into main-desktop

How to run it locally?

No changes in the mmd start scripts. Follow the steps on app/scripts/desktop/Readme.md

Important parts of the MMD-UI

Locales

Most of the code(i18nProvider, getMessage, translate function etc.) was copied from MM with few changes. In the long run, it would be more maintainable for us to have separated locales; hence I've put the MMD locales in a separate folder.

State Management

I wanted to keep the same tooling as the MM, so I kept Redux.
I believe we will need some data persistence in the MMD (E.g desktop app settings). For that purpose I've used redux-persist with electron-store

Styling

To use MM components, we are injecting the monolith CSS of MM. (See app/desktop-ui.html)
It's not ideal, but good to go for the beginning. Since we import MM css file, I've added mmd.scss to the MM index scss so we create and use our styles under desktop-ui.

Communication between Renderer and Main process

It's worth mentioning; we are registering listeners in the desktop-ui/index.js (E.g registerUpdatePairStatus) if we need that state in the higher scope.
And for the other way; we invoke a message from the renderer (E.g desktop-ui/pages/pair/pair.component.js see handleOTPChange)

Known issues

window.require('electron')

There are weird bundling issues if we try to import things from electron package.
To reproduce: Find & replace const { ipcRenderer } = window.require('electron'); to import { ipcRenderer } from 'electron'

Flaky active connection state

The state communication between MMD and MM is getting improved by Vinicius PR, so be aware if you see some discrepancies through your local tests
I've added Temporary Pair Page Link in the deactivated state so you can easily navigate the pair page if needed.

No message is sent back to MMD if the user disconnects from MM

We will have a look at this issue soon.

OTP component

Not an issue but worth mentioning. For the sake of moving fast, I've used a very basic(0 dependency) package to handle OTP input. We can create our own if we need it in the future.

Todos

  • Error pages
  • Unit tests

@OGPoyraz OGPoyraz requested a review from a team as a code owner October 12, 2022 07:36
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1 user-scalable=no">
<title>MetaMask</title>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just add "MetaMask Desktop" here, but probably It will be replaced by the UI Pairing flow ticket.

Copy link
Contributor

@vinistevam vinistevam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's really good to see it's working using MM build scripts 🥇 .
Just run lint:fix and 👍

@OGPoyraz OGPoyraz force-pushed the include-desktop-ui-builder branch 2 times, most recently from d56be00 to fef377a Compare October 13, 2022 07:53
@OGPoyraz OGPoyraz force-pushed the include-desktop-ui-builder branch 2 times, most recently from 7b47b56 to 1ff1514 Compare October 20, 2022 07:31
desktop-ui/App.js Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
@OGPoyraz OGPoyraz changed the title Include Desktop UI builder scripts Include Desktop UI Oct 25, 2022
@OGPoyraz OGPoyraz changed the title Include Desktop UI Add Desktop UI Oct 25, 2022
@OGPoyraz OGPoyraz force-pushed the include-desktop-ui-builder branch 4 times, most recently from ceb1bf7 to 7ac9ce0 Compare October 26, 2022 10:24
@@ -0,0 +1,9 @@
import launchDesktopUi from '../../ui/desktop';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make it explicit that this is running in a renderer process and not part of the background, shall we call this something like ui.js and move it inside the desktop directory?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense, I've tried to solve it quickly, but if we move that file into a different folder, we need to make many modifications to build scripts.

For example, changing the desktop entry point in standartEntryPoints(development/build/scripts.js#232) to desktop/ui causes different bundler requirements (bundler getting confused about folders, e.g lavamoat options development/build/scripts.js#557).

It's not the best but rather than moving the file, I've renamed it to desktop-ui.js. Shall we create a task for that and have a look later on?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed, changing the structure will complicate the build scripts. I'm in favour to create a task in the refactor section to tackle it later.

@@ -175,27 +175,31 @@ class DesktopApp extends EventEmitter {

private async createStatusWindow() {
const statusWindow = new BrowserWindow({
width: 800,
height: 400,
width: process.env.METAMASK_DEBUG ? 1800 : 1000,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a little big to load with as it hits the bounds of my 16" laptop at the default zoom level. Maybe start small but let the user maximise or persist after resize?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@@ -175,27 +175,31 @@ class DesktopApp extends EventEmitter {

private async createStatusWindow() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we change all these references for clarity and maybe refer to this as the main window?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

webPreferences: {
preload: path.resolve(__dirname, './status-preload.js'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whether we ultimately use a preload script or not, we can delete this file and any old logic if not used.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added back this line to use version and other use cases from status-preload.ts

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@socket-security
Copy link

socket-security bot commented Oct 27, 2022

Socket Security Report

👍 No new dependency issues detected in pull request

Socket.dev scan summary
Issue Status
Did you mean? ✅ no new possible package typos
Install scripts ✅ no new install scripts
Telemetry ✅ no new telemetry
Troll package ✅ no new troll packages
Malware ✅ no new malware
Native code ✅ no new native modules
Bin Script Confusion ✅ no new bin script confusions
Bin script shell injection ✅ no new bin script shell injection
Bot Commands

To ignore an alert, reply with a comment starting with @SocketSecurity ignore followed by a space separated list of package-name@version specifiers. e.g. @SocketSecurity ignore foo@1.0.0 bar@2.4.2

Powered by socket.dev

@@ -46,7 +47,7 @@ module.exports = function createStaticAssetTasks({
composeSeries(
...copyTargetsProd.map((target) => {
return async function copyStaticAssets() {
await performCopy(target);
await performCopy(target, includeDesktopUi);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need to add includeDesktopUi.. it is already available in the higher scope. Also that method signature only has 1 arg 😅

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, it's been forgotten one :D

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@@ -13,12 +13,13 @@
"start": "yarn build:dev dev --apply-lavamoat=false",
"build:desktop": "./development/build-desktop.sh",
"build:desktop:mv3": "ENABLE_MV3=true ./development/build-desktop.sh",
"build:desktop:extension": "DESKTOP=EXTENSION yarn start --build-type flask",
"build:desktop:extension": "DESKTOP=EXTENSION yarn start --build-type flask --include-desktop-ui true",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should split this.. Currently this will generate the bundle for the extension and the desktop app ui. Those are 2 different things and should be dealt separately (even if the bundle process is the same).

IMO it would make more sense if the build:desktop would actually generate both the main and renderer process "bundles" (as both are part of the desktop app)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants