Skip to content

Commit 0aedff6

Browse files
committed
功能实现,但是存在缺陷(当订阅数多的时候会卡顿)
1 parent 6c9fef9 commit 0aedff6

25 files changed

+402
-279
lines changed

README.md

-16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
2-
3-
41
## 缓存目录
52

63
Linux: $XDG_CACHE_HOME or ~/.cache/electron/
@@ -29,19 +26,6 @@ npm install electron-rebuild --save .\node_modules\.bin\electron-rebuild.cmd
2926

3027

3128

32-
## TODO
33-
34-
1. 文章内容显示还会出现滚动条(横向),很难排查具体是什么元素撑开的(文章的样式还待优化)
35-
36-
2. 新增订阅
37-
38-
3. 收藏订阅、文章
39-
40-
4. 取消订阅
41-
42-
5. 文章数据的存储策略
43-
44-
6. 以绝对路径替换 img 标签,在后期移动整个目录会导致图片无法使用
4529

4630
## 错误记录
4731

config/articles.db

0 Bytes
Binary file not shown.

config/dev-app-update.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
provider: generic
2-
url: http://127.0.0.1:10086/public
2+
url: https://coder163.com/rss-reader
33
updaterCacheDirName: cache

electron-builder.json5

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
"publish": [
77
{
88
"provider": "generic",
9-
"url": "http://127.0.0.1:10086/public",
10-
//更新服务器地址,可为空
9+
"url": "https://coder163.com/rss-reader",
10+
1111
}
1212
],
1313
// "publish": {
@@ -19,7 +19,7 @@
1919
"appId": "com.coder163",
2020
"productName": "猿阅",//项目名,也是生成的安装文件名,即aDemo.exe
2121
"copyright": "Copyright © 2022",//版权信息
22-
"asar": true,
22+
"asar": false,
2323
"directories": {
2424
"output": "release/${version}"
2525
},
@@ -62,5 +62,6 @@
6262
"perMachine": false,
6363
"allowToChangeInstallationDirectory": true,
6464
"deleteAppDataOnUninstall": false,
65+
6566
}
6667
}

electron/main/index.ts

+32-29
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import {app, BrowserWindow, globalShortcut, ipcMain, protocol, shell} from 'electron'
2-
import {release} from 'os'
3-
import {join} from 'path'
1+
import { app, BrowserWindow, globalShortcut, ipcMain, protocol, shell } from 'electron'
2+
import { release } from 'os'
3+
import { join } from 'path'
44
import Update from "../update";
55

66

@@ -28,17 +28,19 @@ export const ROOT_PATH = {
2828
let win: BrowserWindow | null = null
2929
// Here, you can also use other preload
3030
const preload = join(__dirname, '../preload/index.js')
31+
log.info(preload)
3132
// 🚧 Use ['ENV_NAME'] avoid vite:define plugin
3233
const url = `http://${process.env['VITE_DEV_SERVER_HOST']}:${process.env['VITE_DEV_SERVER_PORT']}`
3334
const indexHtml = join(ROOT_PATH.dist, 'index.html')
34-
35+
// 禁用当前应用程序的硬件加速
36+
app.disableHardwareAcceleration()
3537
async function createWindow() {
3638
win = new BrowserWindow({
3739
height: 800,
3840
width: 1200,
39-
frame: false,//添加这一行采用无边框窗口
41+
// frame: false,//添加这一行采用无边框窗口
4042
icon: join(ROOT_PATH.public, 'favicon.ico'),
41-
transparent:false,//透明 为true会影响页面缩放
43+
transparent: false,//透明 为true会影响页面缩放
4244
resizable: true,//可否缩放 为false会影响页面缩放
4345
movable: true,//可否移动 为false会影响页面缩放
4446
webPreferences: {
@@ -56,10 +58,10 @@ async function createWindow() {
5658
win?.webContents.send('key-event-l')
5759
})
5860
win.on('maximize', () => {
59-
win.webContents.send('WINDOW_MAXIMIZE',true)
61+
win.webContents.send('WINDOW_MAXIMIZE', true)
6062
})
6163
win.on('unmaximize', () => {
62-
win.webContents.send('WINDOW_MAXIMIZE',false)
64+
win.webContents.send('WINDOW_MAXIMIZE', false)
6365
})
6466

6567
// win.setMenu(null)
@@ -79,9 +81,9 @@ async function createWindow() {
7981
})
8082

8183
// Make all links open with the browser, not with the application
82-
win.webContents.setWindowOpenHandler(({url}) => {
84+
win.webContents.setWindowOpenHandler(({ url }) => {
8385
if (url.startsWith('https:')) shell.openExternal(url)
84-
return {action: 'deny'}
86+
return { action: 'deny' }
8587
})
8688
//引用本地图片问题https://blog.csdn.net/Takayamaaren/article/details/107289994
8789
protocol.interceptFileProtocol('file', (req, callback) => {
@@ -132,17 +134,18 @@ ipcMain.handle('open-win', (event, arg) => {
132134
})
133135

134136
if (app.isPackaged) {
135-
childWindow.loadFile(indexHtml, {hash: arg})
137+
childWindow.loadFile(indexHtml, { hash: arg })
136138
} else {
137139
childWindow.loadURL(`${url}/#${arg}`)
138140
// childWindow.webContents.openDevTools({ mode: "undocked", activate: true })
139141
}
140142
})
141143

142144

143-
ipcMain.on("read-content", (event, url) => {
145+
ipcMain.on("read-content", (event, item) => {
146+
console.log(item)
144147
//通知content.vue渲染
145-
win?.webContents.send('read-content-done', url)
148+
win?.webContents.send('read-content-done', item)
146149
})
147150
ipcMain.on("update-item-list", (event, ...args) => {
148151

@@ -155,7 +158,7 @@ ipcMain.on('refresh-sub-list', (event, url) => {
155158
win?.webContents.send('refresh-sub-list-done')
156159
})
157160
// @ts-ignore
158-
import {ChannelMessage} from "../../src/domain/enum"
161+
import { ChannelMessage } from "../../src/domain/enum"
159162

160163
ipcMain.on(ChannelMessage.WINDOW_OPERATION, (event, operation) => {
161164
switch (operation) {
@@ -178,31 +181,31 @@ ipcMain.on(ChannelMessage.WINDOW_OPERATION, (event, operation) => {
178181
/**
179182
* 菜单-更新检查
180183
*/
181-
ipcMain.on(ChannelMessage.CHECK_UPDATES,()=>{
182-
const path = require("path")
183-
//测试环境下使用自动更新
184-
Object.defineProperty(app,"isPackaged",{
185-
get(){
186-
return true
187-
}
188-
})
189-
if (app.isPackaged) {
190-
autoUpdater.updateConfigPath = path.join(__dirname, '../../../config/dev-app-update.yml');
191-
}
184+
ipcMain.on(ChannelMessage.CHECK_UPDATES, () => {
185+
// const path = require("path")
186+
// //测试环境下使用自动更新
187+
// Object.defineProperty(app,"isPackaged",{
188+
// get(){
189+
// return true
190+
// }
191+
// })
192+
// if (app.isPackaged) {
193+
// autoUpdater.updateConfigPath = path.join(__dirname, '../../../config/dev-app-update.yml');
194+
// }
192195

193196
autoUpdater.checkForUpdatesAndNotify()
194197

195198
})
196199

197200
import log from './../../src/util/log'
198-
import {autoUpdater} from "electron-updater";
201+
import { autoUpdater } from "electron-updater";
199202
/**
200203
* 菜单-应用设置
201204
*/
202-
ipcMain.on(ChannelMessage.APP_SETTINGS_DIALOG,()=>{
205+
ipcMain.on(ChannelMessage.APP_SETTINGS_DIALOG, () => {
203206

204-
win.webContents.send(ChannelMessage.APP_SETTINGS_DIALOG_DONE)
207+
win.webContents.send(ChannelMessage.APP_SETTINGS_DIALOG_DONE)
205208
})
206-
ipcMain.on('open-dev-tool',()=>{
209+
ipcMain.on('open-dev-tool', () => {
207210
win.webContents.openDevTools()
208211
})

electron/preload/index.ts

+40-40
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
function domReady(condition: DocumentReadyState[] = ['complete', 'interactive']) {
2-
return new Promise(resolve => {
3-
if (condition.includes(document.readyState)) {
4-
resolve(true)
5-
} else {
6-
document.addEventListener('readystatechange', () => {
2+
return new Promise(resolve => {
73
if (condition.includes(document.readyState)) {
8-
resolve(true)
4+
resolve(true)
5+
} else {
6+
document.addEventListener('readystatechange', () => {
7+
if (condition.includes(document.readyState)) {
8+
resolve(true)
9+
}
10+
})
911
}
10-
})
11-
}
12-
})
12+
})
1313
}
1414

1515
const safeDOM = {
16-
append(parent: HTMLElement, child: HTMLElement) {
17-
if (!Array.from(parent.children).find(e => e === child)) {
18-
return parent.appendChild(child)
19-
}
20-
},
21-
remove(parent: HTMLElement, child: HTMLElement) {
22-
if (Array.from(parent.children).find(e => e === child)) {
23-
return parent.removeChild(child)
24-
}
25-
},
16+
append(parent: HTMLElement, child: HTMLElement) {
17+
if (!Array.from(parent.children).find(e => e === child)) {
18+
return parent.appendChild(child)
19+
}
20+
},
21+
remove(parent: HTMLElement, child: HTMLElement) {
22+
if (Array.from(parent.children).find(e => e === child)) {
23+
return parent.removeChild(child)
24+
}
25+
},
2626
}
2727

2828
/**
@@ -32,10 +32,10 @@ const safeDOM = {
3232
* https://matejkustec.github.io/SpinThatShit
3333
*/
3434
function useLoading() {
35-
const className = `loading`
36-
const styleContent = `
35+
const className = `loading`
36+
const styleContent = `
3737
body {
38-
38+
background: #ecf0f6;
3939
text-align: center;
4040
padding: 20%;
4141
}
@@ -83,39 +83,39 @@ function useLoading() {
8383
}
8484
}
8585
`
86-
const oStyle = document.createElement('style')
87-
const oDiv = document.createElement('div')
86+
const oStyle = document.createElement('style')
87+
const oDiv = document.createElement('div')
8888

89-
oStyle.id = 'app-loading-style'
90-
oStyle.innerHTML = styleContent
91-
oDiv.className = className
92-
oDiv.innerHTML = `
89+
oStyle.id = 'app-loading-style'
90+
oStyle.innerHTML = styleContent
91+
oDiv.className = className
92+
oDiv.innerHTML = `
9393
<h4>正在努力加载,请稍后</h4>
9494
<span></span> <span></span> <span></span>
9595
<span></span> <span></span> <span></span>
9696
<span></span> <span></span> <span></span>
9797
`
9898

99-
return {
100-
appendLoading() {
101-
safeDOM.append(document.head, oStyle)
102-
safeDOM.append(document.body, oDiv)
103-
},
104-
removeLoading() {
105-
safeDOM.remove(document.head, oStyle)
106-
safeDOM.remove(document.body, oDiv)
107-
},
108-
}
99+
return {
100+
appendLoading() {
101+
safeDOM.append(document.head, oStyle)
102+
safeDOM.append(document.body, oDiv)
103+
},
104+
removeLoading() {
105+
safeDOM.remove(document.head, oStyle)
106+
safeDOM.remove(document.body, oDiv)
107+
},
108+
}
109109
}
110110

111111
// ----------------------------------------------------------------------
112112

113-
const { appendLoading, removeLoading } = useLoading()
113+
const {appendLoading, removeLoading} = useLoading()
114114
domReady().then(appendLoading)
115115

116116
window.onmessage = ev => {
117117

118-
ev.data.payload === 'removeLoading' && removeLoading()
118+
ev.data.payload === 'removeLoading' && removeLoading()
119119
}
120120

121121
// setTimeout(removeLoading, 10)

electron/update/index.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ function Message(mainWindow: BrowserWindow, type: Number, data?: any) {
1616
}
1717
mainWindow.webContents.send('UpdateMsg', senddata)
1818
}
19-
19+
const path=require('path')
2020
// 更新应用的方法
2121
export default (mainWindow: BrowserWindow) => {
2222
// log.info('%cRed text. %cGreen text', 'color: red', 'color: green')
2323
// 在下载之前将autoUpdater的autoDownload属性设置成false,通过渲染进程触发主进程事件来实现这一设置(将自动更新设置成false)
2424
autoUpdater.autoDownload = false
2525
//设置版本更新地址,即将打包后的latest.yml文件和exe文件同时放在
2626
// autoUpdater.setFeedURL('http://localhost:10086/public')
27+
2728
// 当更新发生错误的时候触发。
2829
autoUpdater.on('error', (err: any) => {
2930
log.log(err)
@@ -46,7 +47,7 @@ export default (mainWindow: BrowserWindow) => {
4647
})
4748
// 下载监听
4849
autoUpdater.on('download-progress', (progressObj: any) => {
49-
log.log('download-progress', '下载监听', progressObj)
50+
log.log('download-progress', '下载监听')
5051
Message(mainWindow, 3, progressObj)
5152
})
5253
// 下载完成

favicon.ico

-33.6 KB
Binary file not shown.

index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<head>
55
<meta charset="UTF-8" />
6-
<link rel="icon" href="/favicon.ico" />
6+
<link rel="icon" href="/logox32.png" />
77
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
88
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';" />
99
<title>猿阅</title>

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"private": true,
88
"scripts": {
99
"dev": " vite",
10-
"build": " vite build && electron-builder"
10+
"build": " vite build && electron-builder",
11+
"release": "cross-env GH_TOKEN=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 electron-builder"
1112
},
1213
"engines": {
1314
"node": ">=14.17.0"
@@ -16,6 +17,7 @@
1617
"@quasar/vite-plugin": "^1.0.10",
1718
"@types/request": "^2.48.8",
1819
"@vitejs/plugin-vue": "^2.3.3",
20+
"axios": "^0.27.2",
1921
"electron": "^19.0.8",
2022
"electron-builder": "^23.1.0",
2123
"highlight.js": "^11.6.0",
@@ -38,7 +40,6 @@
3840
},
3941
"dependencies": {
4042
"@quasar/extras": "^1.14.3",
41-
"axios": "^0.27.2",
4243
"cheerio": "^1.0.0-rc.12",
4344
"download": "^8.0.0",
4445
"electron-log": "^4.4.8",
@@ -49,5 +50,4 @@
4950
"request": "^2.88.2",
5051
"sqlite3": "^5.0.9"
5152
}
52-
5353
}

0 commit comments

Comments
 (0)