Skip to content

Commit

Permalink
feat: desktop app (#169)
Browse files Browse the repository at this point in the history
* electron

* github actions

* fix publish.yml

* more concise

* update linux target

* gitignore add newline
  • Loading branch information
ztjhz authored Mar 30, 2023
1 parent 77963d3 commit 4903399
Show file tree
Hide file tree
Showing 7 changed files with 1,774 additions and 8 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -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 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ dist-ssr
*.njsproj
*.sln
*.sw?

release/
46 changes: 46 additions & 0 deletions electron/index.cjs
Original file line number Diff line number Diff line change
@@ -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();
}
});
39 changes: 36 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,44 @@
{
"name": "better-chatgpt",
"private": true,
"version": "1.0.0",
"version": "1.0.1",
"type": "module",
"homepage": "./",
"main": "electron/index.cjs",
"author": "Jing Hua <[email protected]>",
"description": "Play and chat smarter with BetterChatGPT - an amazing open-source web app with a better UI for exploring OpenAI's ChatGPT API!",
"scripts": {
"dev": "vite",
"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": {
"@dqbd/tiktoken": "^1.0.2",
"electron-is-dev": "^2.0.0",
"electron-squirrel-startup": "^1.0.0",
"html2canvas": "^1.4.1",
"i18next": "^22.4.11",
"i18next-browser-languagedetector": "^7.0.1",
Expand All @@ -36,11 +65,15 @@
"@types/uuid": "^9.0.1",
"@vitejs/plugin-react-swc": "^3.0.0",
"autoprefixer": "^10.4.13",
"concurrently": "^8.0.1",
"electron": "^23.2.0",
"electron-builder": "^23.6.0",
"postcss": "^8.4.21",
"tailwindcss": "^3.2.7",
"typescript": "^4.9.3",
"vite": "^4.1.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"
}
}
Binary file added public/favicon-516x516.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
"@src/*": ["./src/*"]
}
},
"include": ["src"],
"include": ["src", "electron/index.cjs"],
"references": [{ "path": "./tsconfig.node.json" }]
}
Loading

0 comments on commit 4903399

Please sign in to comment.