Skip to content

Commit

Permalink
Merge pull request #1 from pokon548/rebase-electron-builder
Browse files Browse the repository at this point in the history
Rebase whole apps to use electron-builder
  • Loading branch information
pokon548 authored Oct 2, 2023
2 parents af1725c + aa1219e commit 84f57bb
Show file tree
Hide file tree
Showing 35 changed files with 397 additions and 1,981 deletions.
9 changes: 0 additions & 9 deletions .editorconfig

This file was deleted.

4 changes: 0 additions & 4 deletions .eslintignore

This file was deleted.

43 changes: 9 additions & 34 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,43 +1,18 @@
module.exports = {
root: true,
env: {
browser: true,
commonjs: true,
es6: true,
node: true
},
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaFeatures: {
jsx: true
},
sourceType: 'module',
ecmaVersion: 2021
},
plugins: ['@typescript-eslint'],
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:react/recommended',
'plugin:react/jsx-runtime',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:prettier/recommended'
'plugin:react-hooks/recommended',
],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parser: '@typescript-eslint/parser',
plugins: ['react-refresh'],
rules: {
'@typescript-eslint/ban-ts-comment': ['error', { 'ts-ignore': 'allow-with-description' }],
'@typescript-eslint/explicit-function-return-type': 'error',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-empty-function': ['error', { allow: ['arrowFunctions'] }],
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-var-requires': 'off'
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
overrides: [
{
files: ['*.js'],
rules: {
'@typescript-eslint/explicit-function-return-type': 'off'
}
}
]
}
26 changes: 23 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
out
*.log*
dist-ssr
dist-electron
release
*.local

.vscode
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
6 changes: 0 additions & 6 deletions .prettierignore

This file was deleted.

4 changes: 0 additions & 4 deletions .prettierrc.yaml

This file was deleted.

File renamed without changes.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,17 @@
在克隆完本项目的源代码后,执行以下命令安装依赖:

```bash
$ yarn
$ pnpm
```

### 运行开发版本

```bash
$ yarn dev
$ pnpm dev
```

### 构建

```bash
# For Linux
$ yarn build:linux
```
$ pnpm build
```
12 changes: 0 additions & 12 deletions build/entitlements.mac.plist

This file was deleted.

Binary file removed build/icon.icns
Binary file not shown.
Binary file removed build/icon.ico
Binary file not shown.
36 changes: 0 additions & 36 deletions build/notarize.js

This file was deleted.

44 changes: 0 additions & 44 deletions electron-builder.yml

This file was deleted.

20 changes: 0 additions & 20 deletions electron.vite.config.ts

This file was deleted.

27 changes: 27 additions & 0 deletions electron/electron-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/// <reference types="vite-plugin-electron/electron-env" />

declare namespace NodeJS {
interface ProcessEnv {
/**
* The built directory structure
*
* ```tree
* ├─┬─┬ dist
* │ │ └── index.html
* │ │
* │ ├─┬ dist-electron
* │ │ ├── main.js
* │ │ └── preload.js
* │
* ```
*/
DIST: string
/** /dist/ or /public/ */
VITE_PUBLIC: string
}
}

// Used in Renderer process, expose in `preload.ts`
interface Window {
ipcRenderer: import('electron').IpcRenderer
}
80 changes: 80 additions & 0 deletions electron/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { app, BrowserWindow, ipcMain, Notification } from 'electron'
import path from 'node:path'

import { download } from 'electron-dl'

// The built directory structure
//
// ├─┬─┬ dist
// │ │ └── index.html
// │ │
// │ ├─┬ dist-electron
// │ │ ├── main.js
// │ │ └── preload.js
// │
process.env.DIST = path.join(__dirname, '../dist')
process.env.VITE_PUBLIC = app.isPackaged ? process.env.DIST : path.join(process.env.DIST, '../public')

function createWindow() {
const win = new BrowserWindow({
width: 1280,
height: 1080,
show: true,
icon: path.join(process.env.VITE_PUBLIC, 'electron-vite.svg'),
autoHideMenuBar: true,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
},
})

// Test active push message to Renderer-process.
win.webContents.on('did-finish-load', () => {
win?.webContents.send('main-process-message', (new Date).toLocaleString())
})

win.loadURL('https://client.orangevip.com', {
userAgent: 'CLClient 1.0'
})

ipcMain.on('url', async (_event, url) => {
console.log(
await download(win, url, {
onStarted(item) {
new Notification({
title: '正在下载课程资料',
body: item.getFilename()
}).show()
},
onProgress(progress) {
win.setProgressBar(progress.percent)
},
onCompleted(file) {
new Notification({
title: '下载完成',
body: '文件路径:' + file.path.toString()
}).show()
win.setProgressBar(1.0)
}
})
)
})
}

// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})

app.on('activate', () => {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})

app.whenReady().then(createWindow)
25 changes: 25 additions & 0 deletions electron/preload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { contextBridge, ipcRenderer } from 'electron'

interface JSBridgeArgs {
key: string
value: string
}

// 实现前端的 JSBridge
const CLClient = {
/**
* @description 实现橙啦网页端的 JSBridge
* @param {string} args 网页段传入的 JSON 参数
*/
invokeMethod(args: string): void {
const jsBridgeArgs: JSBridgeArgs = JSON.parse(args)
switch (jsBridgeArgs.key) {
case 'url':
ipcRenderer.send('url', jsBridgeArgs.value)
}
}
}

// --------- Expose some API to the Renderer process ---------
contextBridge.exposeInMainWorld('ipcRenderer', ipcRenderer)
contextBridge.exposeInMainWorld('CLClient', CLClient)
Loading

0 comments on commit 84f57bb

Please sign in to comment.