first commit
This commit is contained in:
1
docs/zh-cn/.pydio
Normal file
1
docs/zh-cn/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
d51c4cfd-204c-4d1f-b63f-975d8241cdaa
|
||||
30
docs/zh-cn/problem.md
Executable file
30
docs/zh-cn/problem.md
Executable file
@@ -0,0 +1,30 @@
|
||||
### 软件在window下会存在重复运行的问题
|
||||
即双击打开软件,在windows下会创建一个新的运行程序。
|
||||
|
||||
#### 解决方法
|
||||
```js
|
||||
// 创建程序锁,保证只能打开单个实例
|
||||
if (isWin()) {
|
||||
const gotTheLock = app.requestSingleInstanceLock()
|
||||
if (!gotTheLock) {
|
||||
app.quit()
|
||||
} else {
|
||||
app.on('second-instance', (event, commandLine, workingDirectory) => {
|
||||
if (mainWindow) {
|
||||
if (!mainWindow.isVisible()) {
|
||||
mainWindowShow()
|
||||
}
|
||||
mainWindow.focus()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### win.setPosition方法报错
|
||||
##### 原因:setPosition方法中的参数不支持浮点数,只支持整数
|
||||
|
||||
### 远程升级相关问题
|
||||
#### 1.远程升级只能在build后生效
|
||||
#### 2.mac端远程升级需要development ID 到官网申请
|
||||
#### 3.安装最新的electron-update后,运行提示缺少`whenReady()`方法,那是因为`electron-vue`的`electron`版本为2.7的而`whenReady()`为electron3.0.0更新的。解决办法就是升级electron
|
||||
8
docs/zh-cn/reptile.md
Executable file
8
docs/zh-cn/reptile.md
Executable file
@@ -0,0 +1,8 @@
|
||||
### 分析网页接口
|
||||
> 在此处拿https://www.pexels.com 的图库进行分析
|
||||
|
||||
pexels为一个面版权的图库网站,
|
||||
|
||||
### 模拟请求
|
||||
|
||||
### 处理DOM
|
||||
94
docs/zh-cn/save-image.md
Executable file
94
docs/zh-cn/save-image.md
Executable file
@@ -0,0 +1,94 @@
|
||||
#### 文件代码在 src/file.js
|
||||
|
||||
起初采用axios进行图片的下载,但是axios在服务端不支持进度条,最后又换成了request请求。
|
||||
|
||||
```js
|
||||
export const downloadPic = async function (src, mainWindow) {
|
||||
// 返回一个Promise方便处理
|
||||
return new Promise((resolve, reject) => {
|
||||
// 先检测目录,没有相关目录的话会自动创建新的目录
|
||||
mkdirSync(hostdir)
|
||||
// 自动重命名
|
||||
let dstpath = `${hostdir}/${(new Date()).getTime()}_${(new Date()).getMilliseconds()}`
|
||||
// webp格式的图片标志,500px下载的图片为webp格式的
|
||||
let isWebp = false
|
||||
// 判断图片格式
|
||||
if (src.match('webp=true')) {
|
||||
dstpath += '.webp'
|
||||
isWebp = true
|
||||
} else {
|
||||
dstpath += '.jpg'
|
||||
isWebp = false
|
||||
}
|
||||
|
||||
// 已经接受的文件的大小
|
||||
let receivedBytes = 0
|
||||
// 文件总的字大小
|
||||
let totalBytes = 0
|
||||
|
||||
// 创建一个文件流
|
||||
const writeStream = fs.createWriteStream(dstpath, {
|
||||
autoClose: true
|
||||
})
|
||||
// 创建一个请求
|
||||
myRequest = request({
|
||||
url: src,
|
||||
headers: browserHeader,
|
||||
})
|
||||
myRequest.pipe(writeStream)
|
||||
myRequest.on('response', (data) => {
|
||||
// 更新总文件字节大小
|
||||
totalBytes = parseInt(data.headers['content-length'], 10)
|
||||
})
|
||||
myRequest.on('data', (chunk) => {
|
||||
// 更新下载的文件块字节大小
|
||||
receivedBytes += chunk.length
|
||||
// 更新进度条
|
||||
mainWindow.webContents.send('datainfo', {
|
||||
type: 'updaterProgress',
|
||||
data: parseFloat(((receivedBytes / totalBytes) * 100))
|
||||
})
|
||||
})
|
||||
|
||||
myRequest.on('finish', () => {
|
||||
myRequest = null
|
||||
})
|
||||
myRequest.on('error', () => {
|
||||
reject()
|
||||
})
|
||||
writeStream.on('finish', () => {
|
||||
writeStream.end()
|
||||
myRequest = null
|
||||
if (receivedBytes === totalBytes){
|
||||
if (isWebp) {
|
||||
// 将webp图片转成jpg图片
|
||||
webp.dwebp(dstpath, dstpath.replace('webp', 'jpg'), '-o', (status) => {
|
||||
// status 101->fails || 100->successful
|
||||
if (status === '100'){
|
||||
fs.unlink(dstpath, (err) => {
|
||||
if (err) throw err
|
||||
// console.log('文件已删除')
|
||||
})
|
||||
resolve(dstpath.replace('webp', 'jpg'))
|
||||
} else {
|
||||
reject()
|
||||
}
|
||||
})
|
||||
} else {
|
||||
resolve(dstpath)
|
||||
}
|
||||
} else {
|
||||
fs.unlink(dstpath, (err) => {
|
||||
if (err) throw err
|
||||
})
|
||||
// 更新进度条
|
||||
mainWindow.webContents.send('datainfo', {
|
||||
type: 'updaterProgress',
|
||||
data: 0
|
||||
})
|
||||
reject()
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
```
|
||||
1
docs/zh-cn/set-wallpaper.md
Executable file
1
docs/zh-cn/set-wallpaper.md
Executable file
@@ -0,0 +1 @@
|
||||
不支持
|
||||
1
docs/zh-cn/start.md
Executable file
1
docs/zh-cn/start.md
Executable file
@@ -0,0 +1 @@
|
||||
xiangmudajian
|
||||
79
docs/zh-cn/tarbar.md
Executable file
79
docs/zh-cn/tarbar.md
Executable file
@@ -0,0 +1,79 @@
|
||||
#### 定位
|
||||
```js
|
||||
appTray.on('click', (event, bounds, position) => {
|
||||
// mainWindow === null ? createWindow() : mainWindow.close()
|
||||
// return
|
||||
// 点击时显示窗口,并修改窗口的显示位置
|
||||
function setMainWinPosition(win, trayBounds) {
|
||||
try {
|
||||
const { screen } = electron
|
||||
const winWidth = mainWindow.getSize()[0]
|
||||
const winHeight = mainWindow.getSize()[1]
|
||||
const cursorPosition = screen.getCursorScreenPoint()
|
||||
const currentScreen = screen.getDisplayNearestPoint(cursorPosition)
|
||||
const screens = screen.getAllDisplays()
|
||||
|
||||
let screenWidth = 0
|
||||
|
||||
// 这目前判断多屏都是横着拼的多屏,
|
||||
for (let i = 0; i < screens.length; i++) {
|
||||
screenWidth += screens[i].workAreaSize.width
|
||||
}
|
||||
|
||||
cursorPosition.x = trayBounds.x + trayBounds.width / 2
|
||||
|
||||
const parallelType = cursorPosition.x < screenWidth / 2 ? 'left' : 'right'
|
||||
const verticaType = cursorPosition.y < currentScreen.workAreaSize.height / 2 ? 'top' : 'bottom'
|
||||
|
||||
let trayPositionType = '' // 任务栏的位置
|
||||
let trayPositionSize = 0
|
||||
|
||||
if (currentScreen.workAreaSize.height < currentScreen.size.height) {
|
||||
trayPositionType = verticaType === 'top' ? 'top' : 'bottom'
|
||||
trayPositionSize = currentScreen.size.height - currentScreen.workAreaSize.height
|
||||
} else if (currentScreen.workAreaSize.width < currentScreen.size.width) {
|
||||
trayPositionType = parallelType === 'left' ? 'left' : 'right'
|
||||
trayPositionSize = currentScreen.size.width - currentScreen.workAreaSize.width
|
||||
}
|
||||
|
||||
let winPositionX = 1
|
||||
let winPositionY = 1
|
||||
|
||||
if (trayPositionType === 'top') {
|
||||
winPositionX = Math.max(Math.min(screenWidth - winWidth, cursorPosition.x - (winWidth / 2)), 1)
|
||||
winPositionY = trayBounds.height + 2
|
||||
} else if (trayPositionType === 'bottom') {
|
||||
winPositionX = Math.max(Math.min(screenWidth - winWidth, cursorPosition.x - (winWidth / 2)), 1)
|
||||
winPositionY = currentScreen.size.height - trayPositionSize - winHeight
|
||||
} else if (trayPositionType === 'left') {
|
||||
winPositionX = trayPositionSize
|
||||
winPositionY = Math.max(Math.min(currentScreen.size.height - winHeight, cursorPosition.y - (winHeight / 2)), 1)
|
||||
} else if (trayPositionType === 'right') {
|
||||
winPositionX = screenWidth - trayPositionSize - winWidth
|
||||
winPositionY = Math.max(Math.min(currentScreen.size.height - winHeight, cursorPosition.y - (winHeight / 2)), 1)
|
||||
}
|
||||
win.setPosition(parseInt(winPositionX, 10), winPositionY)
|
||||
} catch (error) {
|
||||
log.error(error)
|
||||
}
|
||||
}
|
||||
try {
|
||||
if (mainWindow.isVisible()) {
|
||||
mainWindow.webContents.send('datainfo', {
|
||||
type: 'windowShow',
|
||||
data: false
|
||||
})
|
||||
mainWindowHide()
|
||||
} else {
|
||||
mainWindow.webContents.send('datainfo', {
|
||||
type: 'windowShow',
|
||||
data: true
|
||||
})
|
||||
mainWindowShow()
|
||||
setMainWinPosition(mainWindow, bounds)
|
||||
}
|
||||
} catch (error) {
|
||||
log.error(error)
|
||||
}
|
||||
})
|
||||
```
|
||||
3
docs/zh-cn/updata.md
Executable file
3
docs/zh-cn/updata.md
Executable file
@@ -0,0 +1,3 @@
|
||||
### 远程升级
|
||||
|
||||
采用`electron-updater`模块
|
||||
Reference in New Issue
Block a user