feat: desktop app (#169)

* electron

* github actions

* fix publish.yml

* more concise

* update linux target

* gitignore add newline
This commit is contained in:
Jing Hua 2023-03-30 13:58:59 +08:00 committed by GitHub
parent 77963d3aaa
commit 4903399d56
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 1774 additions and 8 deletions

27
.github/workflows/publish.yml vendored Normal file
View file

@ -0,0 +1,27 @@
name: Build and publish desktop app
on:
workflow_dispatch:
concurrency:
group: 'publish'
cancel-in-progress: true
jobs:
build:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Use Node.js 18
uses: actions/setup-node@v3
with:
node-version: 18
- name: Install dependencies
run: yarn
- name: Build
run: yarn make

2
.gitignore vendored
View file

@ -22,3 +22,5 @@ dist-ssr
*.njsproj *.njsproj
*.sln *.sln
*.sw? *.sw?
release/

46
electron/index.cjs Normal file
View file

@ -0,0 +1,46 @@
const path = require('path');
const { app, BrowserWindow } = require('electron');
const isDev = require('electron-is-dev');
if (require('electron-squirrel-startup')) app.quit();
function createWindow() {
let iconPath = '';
if (isDev) {
iconPath = path.join(__dirname, '../public/favicon-516x516.png');
} else {
iconPath = path.join(__dirname, '../dist/favicon-516x516.png');
}
const win = new BrowserWindow({
show: false,
icon: iconPath,
});
win.maximize();
win.show();
win.loadURL(
isDev
? 'http://localhost:5173'
: `file://${path.join(__dirname, '../dist/index.html')}`
);
if (isDev) {
win.webContents.openDevTools({ mode: 'detach' });
}
}
app.whenReady().then(createWindow);
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});

View file

@ -1,15 +1,44 @@
{ {
"name": "better-chatgpt", "name": "better-chatgpt",
"private": true, "private": true,
"version": "1.0.0", "version": "1.0.1",
"type": "module", "type": "module",
"homepage": "./",
"main": "electron/index.cjs",
"author": "Jing Hua <betterchatgpt@mail.tjh.sg>",
"description": "Play and chat smarter with BetterChatGPT - an amazing open-source web app with a better UI for exploring OpenAI's ChatGPT API!",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"build": "tsc && vite build", "build": "tsc && vite build",
"preview": "vite preview" "preview": "vite preview",
"electron": "concurrently -k \"BROWSER=none yarn dev\" \"wait-on tcp:5173 && electron .\"",
"pack": "yarn build && electron-builder --dir",
"make": "yarn build && electron-builder"
},
"build": {
"appId": "better-chatgpt",
"productName": "Better ChatGPT",
"directories": {
"output": "release"
},
"dmg": {
"title": "${productName} ${version}",
"icon": "dist/favicon-516x516.png"
},
"linux": {
"target": "tar.gz",
"category": "Chat",
"icon": "dist/favicon-516x516.png"
},
"win": {
"target": "NSIS",
"icon": "dist/favicon-516x516.png"
}
}, },
"dependencies": { "dependencies": {
"@dqbd/tiktoken": "^1.0.2", "@dqbd/tiktoken": "^1.0.2",
"electron-is-dev": "^2.0.0",
"electron-squirrel-startup": "^1.0.0",
"html2canvas": "^1.4.1", "html2canvas": "^1.4.1",
"i18next": "^22.4.11", "i18next": "^22.4.11",
"i18next-browser-languagedetector": "^7.0.1", "i18next-browser-languagedetector": "^7.0.1",
@ -36,11 +65,15 @@
"@types/uuid": "^9.0.1", "@types/uuid": "^9.0.1",
"@vitejs/plugin-react-swc": "^3.0.0", "@vitejs/plugin-react-swc": "^3.0.0",
"autoprefixer": "^10.4.13", "autoprefixer": "^10.4.13",
"concurrently": "^8.0.1",
"electron": "^23.2.0",
"electron-builder": "^23.6.0",
"postcss": "^8.4.21", "postcss": "^8.4.21",
"tailwindcss": "^3.2.7", "tailwindcss": "^3.2.7",
"typescript": "^4.9.3", "typescript": "^4.9.3",
"vite": "^4.1.0", "vite": "^4.1.0",
"vite-plugin-top-level-await": "^1.3.0", "vite-plugin-top-level-await": "^1.3.0",
"vite-plugin-wasm": "^3.2.2" "vite-plugin-wasm": "^3.2.2",
"wait-on": "^7.0.1"
} }
} }

BIN
public/favicon-516x516.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB

View file

@ -28,6 +28,6 @@
"@src/*": ["./src/*"] "@src/*": ["./src/*"]
} }
}, },
"include": ["src"], "include": ["src", "electron/index.cjs"],
"references": [{ "path": "./tsconfig.node.json" }] "references": [{ "path": "./tsconfig.node.json" }]
} }

1666
yarn.lock

File diff suppressed because it is too large Load diff