Skip to content

Commit

Permalink
feat: electron app (#1586)
Browse files Browse the repository at this point in the history
  • Loading branch information
pengx17 authored Mar 16, 2023
1 parent 6ae06d5 commit 88f662e
Show file tree
Hide file tree
Showing 42 changed files with 6,590 additions and 277 deletions.
214 changes: 142 additions & 72 deletions .github/workflows/client-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,19 @@ on:
workflow_dispatch:
inputs:
version:
description: App Vesion
required: false
description: App Version
required: true
default: 0.1.0
is-draft:
description: 'Draft Release?'
type: boolean
required: true
default: true
is-pre-release:
description: 'Pre Release? (labeled as "PreRelease")'
type: boolean
required: true
default: true

permissions:
actions: write
Expand All @@ -20,90 +30,150 @@ concurrency:
cancel-in-progress: true

jobs:
create-release:
runs-on: ubuntu-latest
outputs:
release_id: ${{ steps.create-release.outputs.result }}

before-make:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- name: setup node
uses: actions/setup-node@v1
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
- uses: actions/setup-node@v3
with:
node-version: 16
- name: create release
id: create-release
uses: actions/github-script@v6
node-version: 18
cache: 'pnpm'
- name: Install dependencies
run: yarn install
working-directory: apps/electron

- name: before-make
working-directory: apps/electron
run: yarn before-make
env:
NEXT_PUBLIC_FIREBASE_API_KEY: ${{ secrets.NEXT_PUBLIC_FIREBASE_API_KEY }}
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN: ${{ secrets.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN }}
NEXT_PUBLIC_FIREBASE_PROJECT_ID: ${{ secrets.NEXT_PUBLIC_FIREBASE_PROJECT_ID }}
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET: ${{ secrets.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET }}
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID: ${{ secrets.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID }}
NEXT_PUBLIC_FIREBASE_APP_ID: ${{ secrets.NEXT_PUBLIC_FIREBASE_APP_ID }}
NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID: ${{ secrets.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID }}

- name: Upload Artifact (web-static)
uses: actions/upload-artifact@v3
with:
name: before-make-web-static
path: apps/electron/resources/web-static

- name: Upload Artifact (electron dist)
uses: actions/upload-artifact@v3
with:
script: |
const { data } = await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: `affine-client-v${{ github.event.inputs.version }}`,
name: `Affine Client v${{ github.event.inputs.version }}`,
body: 'Take a look at the assets to download and install this app.',
draft: true,
prerelease: false
})
return data.id
build-tauri:
needs: create-release
strategy:
fail-fast: false
matrix:
platform: [macos-latest, ubuntu-latest, windows-latest]

runs-on: ${{ matrix.platform }}
name: before-make-electron-dist
path: apps/electron/dist

build-macos-x64:
needs: before-make
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'pnpm'
- run: pnpm i
node-version: 18

- name: Install dependencies
run: yarn install # that's right, yarn
working-directory: apps/electron

- uses: actions/download-artifact@v3
with:
name: before-make-web-static
path: apps/electron/resources/web-static

- uses: actions/download-artifact@v3
with:
name: before-make-electron-dist
path: apps/electron/dist

- name: install dependencies (ubuntu only)
if: matrix.platform == 'ubuntu-latest'
- name: make build
run: yarn make-macos-arm64
working-directory: apps/electron

- name: Save x64 artifacts
run: |
sudo apt-get update
sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev librsvg2-dev patchelf
- name: install Rust stable
uses: dtolnay/rust-toolchain@stable

- name: Get rust cache
uses: Swatinem/rust-cache@v2
id: rust-cache
mkdir -p builds
mv apps/electron/out/make/AFFiNE.dmg ./builds/affine-darwin-x64-${{ github.event.inputs.version }}.dmg
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
workspaces: |
apps/desktop/src-tauri
name: affine-darwin-x64-builds
path: builds

- name: Upload to release on git tag Or output artifact path on nightly
uses: tauri-apps/tauri-action@v0
id: tauri-action
env:
CI_PULL_REQUEST: ${{ github.event_name == 'pull_request' }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build-macos-arm64:
needs: before-make
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
releaseId: ${{ needs.create-release.outputs.release_id }}
node-version: 18

publish-release:
runs-on: ubuntu-latest
needs: [create-release, build-tauri]
- name: Install dependencies
run: yarn install # that's right, yarn
working-directory: apps/electron

- uses: actions/download-artifact@v3
with:
name: before-make-web-static
path: apps/electron/resources/web-static

- uses: actions/download-artifact@v3
with:
name: before-make-electron-dist
path: apps/electron/dist

- name: make build
run: yarn make-macos-arm64
working-directory: apps/electron

- name: Save arm64 artifacts
run: |
mkdir -p builds
mv apps/electron/out/make/AFFiNE.dmg ./builds/affine-darwin-arm64-${{ github.event.inputs.version }}.dmg
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: affine-darwin-arm64-builds
path: builds

release:
needs: [build-macos-x64, build-macos-arm64]
runs-on: ubuntu-latest
steps:
- name: publish pre release
id: publish-pre-release
uses: actions/github-script@v6
- name: Download MacOS x64 Artifacts
uses: actions/download-artifact@v3
with:
name: affine-darwin-x64-builds
path: ./

- name: Download MacOS arm64 Artifacts
uses: actions/download-artifact@v3
with:
name: affine-darwin-arm64-builds
path: ./

- name: Create Release Draft
uses: softprops/action-gh-release@v1
env:
release_id: ${{ needs.create-release.outputs.release_id }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
script: |
github.rest.repos.updateRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: process.env.release_id,
draft: false,
prerelease: true
})
name: Desktop APP ${{ github.event.inputs.version }}
body: 'TODO: Add release notes here'
draft: ${{ github.event.inputs.is-draft }}
prerelease: ${{ github.event.inputs.is-pre-release }}
files: |
./VERSION
./*.zip
./*.dmg
./*.exe
./*.nupkg
./RELEASES
./*.AppImage
./*.apk
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,3 @@ module-resolve.cjs
# Cache
.eslintcache
next-env.d.ts

# generated assets
apps/desktop/public/affine-out
apps/desktop/public/preload
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pnpm-lock.yaml

3 changes: 3 additions & 0 deletions apps/desktop/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# generated assets
public/affine-out
public/preload
13 changes: 13 additions & 0 deletions apps/electron/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
*.autogen.*
dist

resources/web-static

# yarn (3)
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
873 changes: 873 additions & 0 deletions apps/electron/.yarn/releases/yarn-3.4.1.cjs

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions apps/electron/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
yarnPath: .yarn/releases/yarn-3.4.1.cjs
nodeLinker: node-modules
24 changes: 24 additions & 0 deletions apps/electron/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# AFFiNE Electron App

# ⚠️ NOTE ⚠️

Due to PNPM related issues, this project is currently using **yarn 3**.
See https://github.com/electron/forge/issues/2633

## Development

```
# in project root, start web app at :8080
pnpm dev
# in /apps/electron, start electron app
pnpm dev
```

## Credits

Most of the boilerplate code is generously borrowed from the following

- [vite-electron-builder](https://github.com/cawa-93/vite-electron-builder)
- [Turborepo basic example](https://github.com/vercel/turborepo/tree/main/examples/basic)
- [yerba](https://github.com/t3dotgg/yerba)
16 changes: 16 additions & 0 deletions apps/electron/forge.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
packagerConfig: {
name: 'AFFiNE',
icon: './resources/icons/icon.icns',
},
makers: [
{
name: '@electron-forge/maker-dmg',
config: {
format: 'ULFO',
icon: './resources/icons/icon.icns',
name: 'AFFiNE',
},
},
],
};
57 changes: 57 additions & 0 deletions apps/electron/layers/main/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import './security-restrictions';

import { app } from 'electron';

import { restoreOrCreateWindow } from './main-window';
import { registerProtocol } from './protocol';

/**
* Prevent multiple instances
*/
const isSingleInstance = app.requestSingleInstanceLock();
if (!isSingleInstance) {
app.quit();
process.exit(0);
}

app.on('second-instance', restoreOrCreateWindow);

/**
* Disable Hardware Acceleration for more power-save
*/
app.disableHardwareAcceleration();

/**
* Shout down background process if all windows was closed
*/
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});

/**
* @see https://www.electronjs.org/docs/v14-x-y/api/app#event-activate-macos Event: 'activate'
*/
app.on('activate', restoreOrCreateWindow);

/**
* Create app window when background process will be ready
*/
app
.whenReady()
.then(registerProtocol)
.then(restoreOrCreateWindow)
.catch(e => console.error('Failed create window:', e));

/**
* Check new app version in production mode only
*/
// FIXME: add me back later
// if (import.meta.env.PROD) {
// app
// .whenReady()
// .then(() => import('electron-updater'))
// .then(({ autoUpdater }) => autoUpdater.checkForUpdatesAndNotify())
// .catch(e => console.error('Failed check updates:', e));
// }
Loading

2 comments on commit 88f662e

@vercel
Copy link

@vercel vercel bot commented on 88f662e Mar 16, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

affine-preview – ./apps/web

affine-preview-git-master-toeverything.vercel.app
affine-preview-toeverything.vercel.app
affine-preview.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 88f662e Mar 16, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

affine-storybook – ./packages/component

affine-storybook.vercel.app
affine-storybook-git-master-toeverything.vercel.app
affine-storybook-toeverything.vercel.app

Please sign in to comment.