-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from pokon548/rebase-electron-builder
Rebase whole apps to use electron-builder
- Loading branch information
Showing
35 changed files
with
397 additions
and
1,981 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.