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/building electron with todesktop #418

Merged
merged 76 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
8be62f0
➕ add electron dependency
fredk3 Mar 15, 2024
1cc2568
🚧 Setting up for electron
fredk3 Mar 15, 2024
76a5346
💄 add a top padding on desktop
fredk3 Mar 15, 2024
07578a6
🙈 Ignore todesktop env file
fredk3 Mar 15, 2024
338707e
♻️ Replace all places with the headless package for electron target
fredk3 Mar 16, 2024
2f7efe0
🚧 something...
fredk3 Mar 16, 2024
85314c1
⚗️ Try including `node_modules` in files uploaded to todesktop
fredk3 Mar 16, 2024
b934da2
:rewind: restore search api route to `canary` to avoid merge conflicts
fredk3 Mar 16, 2024
0c0916c
🚧 WIP
fredk3 Mar 18, 2024
0218031
⚗️ try using postinstall method to build app on todesktop servers
fredk3 Mar 19, 2024
b2ac182
🚧 wip
fredk3 Mar 19, 2024
dfc7ca2
🔥 remove unused code
fredk3 Mar 19, 2024
dd00691
🔧 override `packageJson` script in `todesktop.json`
fredk3 Mar 19, 2024
729d22d
🔧 don't run `prepare` script
fredk3 Mar 19, 2024
1623bb1
⚗️ include package.json for debugging
fredk3 Mar 19, 2024
cd7cffe
🔧 update config
fredk3 Mar 19, 2024
222c90c
♻️ Include default env
fredk3 Mar 19, 2024
5e9274d
🔧 remove electron version from `todesktop.json`
fredk3 Mar 19, 2024
0743a32
🔧 use a more modern npmVersion
fredk3 Mar 19, 2024
82fde2d
🔧 use more modern node version
fredk3 Mar 20, 2024
3a36173
🔧 include subdirectories with the mac build
fredk3 Mar 20, 2024
113e089
🙈 do not track `.env` files
fredk3 Mar 20, 2024
6442c25
🚚 refactor the project structure
fredk3 Mar 21, 2024
43cea26
🙈 update `.gitignore`
fredk3 Mar 21, 2024
9dbd5d4
♻️ refactor
fredk3 Mar 21, 2024
ceac3b4
🔥 remove electron code
fredk3 Mar 21, 2024
dfe0325
📝 update README
fredk3 Mar 21, 2024
ee44175
🚧 starting the CI integration
fredk3 Mar 21, 2024
e7d20bb
👷 Add CI for todesktop build
fredk3 Mar 21, 2024
d315a02
♻️ use the correct setup for preparing electron
fredk3 Mar 21, 2024
f5947fb
✨ THE BUILD WORKS !!!
fredk3 Mar 21, 2024
6d228e3
♻️ start electron next server on random port
fredk3 Mar 21, 2024
95df676
🎨 fix prettier format
fredk3 Mar 21, 2024
7f333e6
♻️ Use `electron-log` to see server logs
fredk3 Mar 22, 2024
4904bdd
🔊 Log everything
fredk3 Mar 22, 2024
c5da28f
🔊 log generateStaticParams
fredk3 Mar 22, 2024
c15aa31
⬆️ upgrade next to canary (fixes rollapp bug)
fredk3 Mar 23, 2024
4235ca5
🚚 rename ci file
fredk3 Mar 23, 2024
60d6b5c
👷 add API for triggering desktop app build & release
fredk3 Mar 23, 2024
5930e53
👷 update CI file
fredk3 Mar 23, 2024
827b5c4
♻️ ci api done (?)
fredk3 Mar 23, 2024
883d60c
👷 add `workflow_dispatch` to CI script
fredk3 Mar 26, 2024
befa3e3
👷 rename todesktop ci build
fredk3 Mar 26, 2024
5afa69f
👷 add simple workflow to debug
fredk3 Mar 26, 2024
ced5380
♻️ some fixes
fredk3 Mar 26, 2024
cc6df24
♻️ run simple workflow
fredk3 Mar 26, 2024
c8a70c1
👷 make the ci available from the API triggers
fredk3 Mar 26, 2024
2b1a25c
♻️ refactor CI
fredk3 Mar 26, 2024
da8e11c
♻️ use turbo cache tokens
fredk3 Mar 26, 2024
1dd0e25
🔧 add `prepare-electron` task to turbo.json
fredk3 Mar 26, 2024
ce635a5
🐛 escape `.` in sed command
fredk3 Mar 26, 2024
a3373ab
💚 try using double quotes
fredk3 Mar 26, 2024
cd3687b
💚 fix sed syntax for backup file
fredk3 Mar 26, 2024
e73216e
👷 add more steps to the CI workflow
fredk3 Mar 26, 2024
d878f20
♻️ add CI for building and testing the electron app on each PR
fredk3 Mar 26, 2024
e283fd8
👷 make CI optional for build/test of the electron app
fredk3 Mar 26, 2024
fa41f18
💄 use a app icon with padding around for accordance with MacOS
fredk3 Mar 26, 2024
ca1c96a
💄 adapt UI to the top bar on electron
fredk3 Mar 27, 2024
04123e6
🚧 some changes
fredk3 Mar 27, 2024
43ea405
💄 adjust padding top
fredk3 Mar 27, 2024
db6ab2d
💡 remove unnecessary comment
fredk3 Mar 27, 2024
acf4f1f
🐛 use `0px` as the fallback value for the title bar
fredk3 Mar 27, 2024
46dd417
👷 separate build & test jobs and add timeout on test
fredk3 Mar 27, 2024
ed86146
💚 copy env variables in the CI build
fredk3 Mar 27, 2024
16e7896
💚 fix CI run hierarchy
fredk3 Mar 27, 2024
113fe3e
💚 include env variables in CI build
fredk3 Mar 27, 2024
bf9f927
♻️ rename window title
fredk3 Mar 27, 2024
6b47206
♻️ do not cache the output of `prepare-electron`
fredk3 Mar 27, 2024
bc498ea
♻️ some changes
fredk3 Mar 27, 2024
5702895
💄 show icons in search options in modal
fredk3 Mar 28, 2024
d0e4348
💄 modify drag region for desktop app
fredk3 Mar 28, 2024
90efedd
💄 reduce header height for desktop
fredk3 Mar 28, 2024
716173e
💄 fix draggable region in desktop app
fredk3 Mar 28, 2024
66342bc
📝 update README
fredk3 Mar 28, 2024
43359bf
🚸 handle `cmd+arrow left` & `cmd+arrow right`
fredk3 Mar 28, 2024
8acfa73
🎨 format with prettier
fredk3 Mar 28, 2024
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
55 changes: 55 additions & 0 deletions .github/workflows/build-test-desktop-app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: CI for the desktop app
on:
pull_request:
workflow_dispatch:

jobs:
build-desktop-app:
runs-on: ubuntu-latest
environment: test
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20.11.1
- name: Build electron app
run: |
npm ci
cat <<EOF > apps/web/.env
INTERNAL_INTEGRATION_API_URL=${INTERNAL_INTEGRATION_API_URL}
NEXT_PUBLIC_SVM_METRICS="https://fr64dzklc3.execute-api.us-west-2.amazonaws.com/prod"
NEXT_PUBLIC_ADOBE_EMBED_API_KEY="a165f09589fc4cd29a574b37d1212a96"
NEXT_PUBLIC_TARGET='electron'
EOF
npx turbo run build --filter web
npx turbo run prepare-electron --filter web
cd apps/desktop
npm install -g @todesktop/cli@1.9.1
todesktop build
env:
TODESKTOP_ACCESS_TOKEN: ${{ secrets.TODESKTOP_ACCESS_TOKEN }}
TODESKTOP_EMAIL: ${{ secrets.TODESKTOP_EMAIL }}
INTERNAL_INTEGRATION_API_URL: ${{ secrets.INTERNAL_INTEGRATION_API_URL }}
NEXT_PUBLIC_SVM_METRICS: "https://fr64dzklc3.execute-api.us-west-2.amazonaws.com/prod"
NEXT_PUBLIC_ADOBE_EMBED_API_KEY: "a165f09589fc4cd29a574b37d1212a96"
NEXT_PUBLIC_TARGET: "electron"
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}

test-desktop-app:
needs: build-desktop-app
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20.11.1
- name: Smoke test electron app
run: |
npm install -g @todesktop/cli@1.9.1
cd apps/desktop
todesktop smoke-test
env:
TODESKTOP_ACCESS_TOKEN: ${{ secrets.TODESKTOP_ACCESS_TOKEN }}
TODESKTOP_EMAIL: ${{ secrets.TODESKTOP_EMAIL }}
1 change: 1 addition & 0 deletions .github/workflows/prettier-check.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Prettier Check
on:
pull_request:
workflow_dispatch:

jobs:
check-formatting:
Expand Down
71 changes: 71 additions & 0 deletions .github/workflows/release-desktop-app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Build and Release Desktop App
on:
workflow_dispatch:

jobs:
build-desktop-app:
runs-on: ubuntu-latest
environment: production
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20.11.1
- name: Build electron app
run: |
npm ci
cat <<EOF > apps/web/.env
INTERNAL_INTEGRATION_API_URL=${INTERNAL_INTEGRATION_API_URL}
NEXT_PUBLIC_SVM_METRICS="https://fr64dzklc3.execute-api.us-west-2.amazonaws.com/prod"
NEXT_PUBLIC_ADOBE_EMBED_API_KEY="a165f09589fc4cd29a574b37d1212a96"
NEXT_PUBLIC_TARGET='electron'
EOF
npx turbo run build --filter web
npx turbo run prepare-electron --filter web
cd apps/desktop
npm install -g @todesktop/cli@1.9.1
todesktop build
env:
TODESKTOP_ACCESS_TOKEN: ${{ secrets.TODESKTOP_ACCESS_TOKEN }}
TODESKTOP_EMAIL: ${{ secrets.TODESKTOP_EMAIL }}
INTERNAL_INTEGRATION_API_URL: ${{ secrets.INTERNAL_INTEGRATION_API_URL }}
NEXT_PUBLIC_SVM_METRICS: "https://fr64dzklc3.execute-api.us-west-2.amazonaws.com/prod"
NEXT_PUBLIC_ADOBE_EMBED_API_KEY: "a165f09589fc4cd29a574b37d1212a96"
NEXT_PUBLIC_TARGET: "electron"
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}

test-desktop-app:
runs-on: ubuntu-latest
needs: build-desktop-app
timeout-minutes: 45
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20.11.1
- name: Smoke test electron app
run: |
npm install -g @todesktop/cli@1.9.1
cd apps/desktop
todesktop smoke-test
env:
TODESKTOP_ACCESS_TOKEN: ${{ secrets.TODESKTOP_ACCESS_TOKEN }}
TODESKTOP_EMAIL: ${{ secrets.TODESKTOP_EMAIL }}

release-desktop-app:
needs: test-desktop-app
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20.11.1
- name: Smoke test electron app
run: |
npm install -g @todesktop/cli@1.9.1
cd apps/desktop
todesktop release --latest
env:
TODESKTOP_ACCESS_TOKEN: ${{ secrets.TODESKTOP_ACCESS_TOKEN }}
TODESKTOP_EMAIL: ${{ secrets.TODESKTOP_EMAIL }}
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ yarn-error.log*
.env.development.local
.env.test.local
.env.production.local

.env.desktop
# turbo
.turbo

# package builds
dist/
cache/
cache/
standalone/
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@
"[typescriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"editor.defaultFormatter": "esbenp.prettier-vscode"
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"typescript.preferences.importModuleSpecifier": "non-relative"
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
This is a monorepo built with [Turborepo](https://turbo.build/repo). These are the workspaces inside:

- `apps/web`: the main app built with [Next.js](https://nextjs.org/)
- `apps/desktop`: the desktop app built with electron, this is just a wrapper around the web app
- `packages/@modularcloud/headless`: headless utils used to fetch data from the different chains
- `packages/tsconfig`: `tsconfig.json`s used throughout the monorepo
- `packages/eslint-config-custom`: `eslint` configurations (includes `eslint-config-next` and `eslint-config-prettier`)
Expand Down
5 changes: 5 additions & 0 deletions apps/desktop/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apps/
packages/
resolver/
package.json
package-lock.json
50 changes: 50 additions & 0 deletions apps/desktop/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Modular Cloud desktop app

## How to run the project

1. Setup the environment variables needed to build the project with electron by modifying `app/web/.env` :

```shell
INTERNAL_INTEGRATION_API_URL=<private-api-for-getting-network-chains>
NEXT_PUBLIC_SVM_METRICS="https://fr64dzklc3.execute-api.us-west-2.amazonaws.com/prod"
NEXT_PUBLIC_ADOBE_EMBED_API_KEY="a165f09589fc4cd29a574b37d1212a96"
NEXT_PUBLIC_TARGET='electron'
```

2. Build the nextjs app :

```shell
# go to the root
cd ../..

# build the nextjs app
npx turbo run build --filter web
```

You may get an error when building the app,
for that you can go to the web folder and build it manuaally :

```shell
cd apps/web
npm run prefetch:networks
npm run build
```

3. Export the built files from the next app :

```shell
cd apps/web
npm run prepare-electron
```

4. Run the desktop project :

```shell
npx electron index.js
```

5. (Optional) Build and release the project :

```shell
TODESKTOP_ACCESS_TOKEN=<token> TODESKTOP_EMAIL=<email> todesktop build
```
Binary file added apps/desktop/assets/mc-app-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
83 changes: 83 additions & 0 deletions apps/desktop/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/* eslint-disable turbo/no-undeclared-env-vars */
// @ts-check
const { app, BrowserWindow, dialog } = require("electron");
const todesktop = require("@todesktop/runtime");
const log = require("electron-log/main");

log.initialize();
log.transports.ipc.level = "verbose";
Object.assign(console, log.functions);

log.errorHandler.startCatching({
showDialog: true,
onError({ error, processType }) {
if (processType === "renderer") {
return;
}

dialog
.showMessageBox({
title: "An error occurred",
message: error.message,
detail: error.stack,
type: "error",
buttons: ["Ignore", "Exit"],
})
.then((result) => {
if (result.response === 1) {
app.quit();
}
});
},
});

function getRandomPort() {
return Math.floor(Math.random() * (65535 - 49152 + 1)) + 49152;
}

let hasServerStarted = false;
let totalAttempsLeft = 10;
while (!hasServerStarted && totalAttempsLeft > 0) {
try {
process.env.PORT = getRandomPort().toString();
require("./apps/web/server.js");
hasServerStarted = true;
} catch (error) {
totalAttempsLeft--;
}
}

todesktop.init();

function createWindow() {
// Create the browser window.
const mainWindow = new BrowserWindow({
width: 1200,
height: 900,
title: "Explorer",
titleBarStyle: "hidden",
trafficLightPosition: {
x: 16,
y: 16,
},
webPreferences: {
nodeIntegration: true,
devTools: true,
},
});

// this is to override the title set by `./apps/web/server.js`
// so that the window will show `Explorer` instead of `next-server`
process.title = mainWindow.title;

// and load the index.html of the app.
mainWindow.loadURL(`http://localhost:${process.env.PORT}`);
mainWindow.on("closed", () => {
app.quit();
});
}

app.whenReady().then(createWindow);
app.on("window-all-closed", () => {
app.quit();
});
28 changes: 28 additions & 0 deletions apps/desktop/todesktop.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"id": "240314gel7u7qi9",
"icon": "./assets/mc-app-icon.png",
"appPath": "./",
"schemaVersion": 1,
"npmVersion": "10.2.4",
"nodeVersion": "20.11.1",
"includeSubNodeModules": true,
"asar": false,
"packageJson": {
"extends": "package.json",
"main": "index.js",
"productName": "Modular Cloud Explorer",
"homepage": "https://explorer.modular.cloud",
"description": "A block exporer for modular blockchains.",
"author": {
"name": "Liam Cardenas",
"email": "lzrs@modular.cloud"
},
"scripts": {
"prepare": null
},
"dependencies": {
"@todesktop/runtime": "^1.6.1"
}
},
"uploadSizeLimit": 400
}
4 changes: 4 additions & 0 deletions apps/web/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# INTERNAL_INTEGRATION_API_URL="***"
NEXT_PUBLIC_SVM_METRICS="https://fr64dzklc3.execute-api.us-west-2.amazonaws.com/prod"
NEXT_PUBLIC_ADOBE_EMBED_API_KEY="a165f09589fc4cd29a574b37d1212a96"
NEXT_PUBLIC_TARGET='electron'
2 changes: 1 addition & 1 deletion apps/web/app/(entity)/[network]/[...path]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default function EntityLayout({ children, params }: Props) {
className={cn(
"overflow-x-clip fixed left-0 bottom-0 lg:max-w-[calc(100%_-_27rem)] w-full",
// this is default position when there is a 404 error
"top-[calc(theme('spacing.header')_-_10px)]",
"top-[calc(var(--header-size)+var(--header-tabs-size)_-_10px))]",
)}
>
{children}
Expand Down
12 changes: 4 additions & 8 deletions apps/web/app/(entity)/[network]/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
// components
import { Header } from "~/ui/header";
import { HideBodyOverflow } from "~/ui/hide-body-overflow";

// utils
import { getSingleNetwork } from "~/lib/network";
import { cn } from "~/ui/shadcn/utils";

// types
import { HeadlessRoute } from "~/lib/headless-utils";
import { DEFAULT_BRAND_COLOR } from "~/lib/constants";
import type { HeadlessRoute } from "~/lib/headless-utils";

export default async function BlockLayout({
children,
Expand All @@ -24,7 +20,7 @@ export default async function BlockLayout({
<main
className="min-h-screen flex flex-col h-full"
style={{
"--color-primary": network?.config.primaryColor,
"--color-primary": network?.config.primaryColor ?? DEFAULT_BRAND_COLOR,
"--gradient-primary": network?.config.cssGradient,
}}
>
Expand All @@ -37,7 +33,7 @@ export default async function BlockLayout({
id="main-content"
tabIndex={0}
className={cn(
"mt-[65px] bg-white min-h-screen",
"mt-header bg-white min-h-screen",
// style children but not the header nav
"[&>*:not(nav)]:bg-white col-span-6",
)}
Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/(home)/[network]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { HeadlessRoute } from "~/lib/headless-utils";
import { SVMWidgetLayout } from "~/ui/network-widgets/layouts/svm";
import { CelestiaWidgetLayout } from "~/ui/network-widgets/layouts/celestia";
import { DymensionWidgetLayout } from "~/ui/network-widgets/layouts/dymension";
import { env } from "~/env.mjs";
import { env } from "~/env.js";
import { OG_SIZE } from "~/lib/constants";

interface Props {
Expand Down
Loading
Loading