Skip to content

Commit

Permalink
style: use prettier to format code, and add plugin named commitlint
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaozhu188 committed Mar 12, 2021
1 parent 392de51 commit f08a8e4
Show file tree
Hide file tree
Showing 210 changed files with 21,343 additions and 24,646 deletions.
5 changes: 5 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
build
coverage
dist
docs

13 changes: 13 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"trailingComma": "es5",
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": false,
"jsxSingleQuote": true,
"jsxBracketSameLine": false,
"arrowParens": "always",
"endOfLine": "lf",
"bracketSpacing": true,
"htmlWhitespaceSensitivity": "strict"
}
357 changes: 357 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: ['./node_modules/vue-cli-plugin-commitlint/lib/lint']
}
17,349 changes: 0 additions & 17,349 deletions package-lock.json

This file was deleted.

39 changes: 30 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
{
"name": "electron-vue-cloud-music",
"version": "1.1.16",
"description": "electron-网易云音乐",
"private": true,
"description": "electron-网易云音乐",
"scripts": {
"build": "vue-cli-service electron:build",
"release": "vue-cli-service electron:build",
"start": "vue-cli-service electron:serve",
"cz": "npm run log && git add . && git cz",
"doc": "docsify serve docs",
"log": "conventional-changelog --config ./node_modules/vue-cli-plugin-commitlint/lib/log -i CHANGELOG.md -s -r 0",
"major": "npm version major && git push origin master && git push origin --tags",
"minor": "npm version minor && git push origin master && git push origin --tags",
"patch": "npm version patch && git push origin master && git push origin --tags",
"postinstall": "electron-builder install-app-deps",
"postuninstall": "electron-builder install-app-deps",
"patch": "npm version patch && git push origin master && git push origin --tags",
"minor": "npm version minor && git push origin master && git push origin --tags",
"major": "npm version major && git push origin master && git push origin --tags",
"doc": "docsify serve docs"
"prettier": "npx prettier --write ./src ./docs",
"release": "vue-cli-service electron:build",
"start": "vue-cli-service electron:serve"
},
"main": "background.js",
"appId": "com.xiaozhu.cloudmusic",
"dependencies": {
"ant-design-vue": "^1.4.10",
"core-js": "^3.4.3",
Expand All @@ -26,6 +28,7 @@
"music-metadata": "^6.0.1",
"nedb": "^1.8.0",
"request-progress": "^3.0.0",
"right-pad": "^1.0.1",
"semver": "^6.3.0",
"showdown": "^1.9.1",
"store": "^2.0.12",
Expand All @@ -46,14 +49,32 @@
"@vue/eslint-config-standard": "^4.0.0",
"babel-eslint": "^10.0.3",
"babel-plugin-import": "^1.13.0",
"commitizen": "^4.0.3",
"commitlint": "^8.2.0",
"conventional-changelog-cli": "^2.0.28",
"electron": "^6.0.0",
"eslint": "^5.16.0",
"eslint-plugin-vue": "^5.0.0",
"husky": "^5.1.3",
"less": "^3.0.4",
"less-loader": "^5.0.0",
"prettier": "^2.2.1",
"vue-cli-plugin-commitlint": "~1.0.12",
"vue-cli-plugin-electron-builder": "^1.4.4",
"vue-html-loader": "^1.2.4",
"vue-template-compiler": "^2.6.10"
},
"__npminstall_done": false
"__npminstall_done": false,
"appId": "com.xiaozhu.cloudmusic",
"config": {
"commitizen": {
"path": "./node_modules/vue-cli-plugin-commitlint/lib/cz"
}
},
"husky": {
"hooks": {
"pre-commit": "npm run prettier",
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
}
}
61 changes: 39 additions & 22 deletions src/main/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { createProtocol } from 'vue-cli-plugin-electron-builder/lib'
import { ACHEME, LOAD_URL } from './config'

const isDevelopment = process.env.NODE_ENV !== 'production'
if ( process.env.NODE_ENV === 'production' ) {
if (process.env.NODE_ENV === 'production') {
global.__img = path.join(__dirname, './img')
global.__images = path.join(__dirname, './images')
}
Expand All @@ -19,11 +19,26 @@ let mainWindow = null
protocol.registerSchemesAsPrivileged([
{ scheme: ACHEME, privileges: { secure: true, standard: true } }
])
const previewIcon = process.env.NODE_ENV === 'development' ? 'public/images/tray.ico' : `${global.__images}/tray.ico`
const prevIcon = process.env.NODE_ENV === 'development' ? 'public/images/prev.png' : `${global.__images}/prev.png`
const nextIcon = process.env.NODE_ENV === 'development' ? 'public/images/next.png' : `${global.__images}/next.png`
const playIcon = process.env.NODE_ENV === 'development' ? 'public/images/play.png' : `${global.__images}/play.png`
const pauseIcon = process.env.NODE_ENV === 'development' ? 'public/images/pause.png' : `${global.__images}/pause.png`
const previewIcon =
process.env.NODE_ENV === 'development'
? 'public/images/tray.ico'
: `${global.__images}/tray.ico`
const prevIcon =
process.env.NODE_ENV === 'development'
? 'public/images/prev.png'
: `${global.__images}/prev.png`
const nextIcon =
process.env.NODE_ENV === 'development'
? 'public/images/next.png'
: `${global.__images}/next.png`
const playIcon =
process.env.NODE_ENV === 'development'
? 'public/images/play.png'
: `${global.__images}/play.png`
const pauseIcon =
process.env.NODE_ENV === 'development'
? 'public/images/pause.png'
: `${global.__images}/pause.png`
// 设置底部任务栏按钮和缩略图
const setThumbarButtons = function (mainWindow, playing) {
mainWindow.setThumbarButtons([
Expand Down Expand Up @@ -72,13 +87,13 @@ function createWindow () {
}
})
// 设置appId才能使用Notification
if ( process.platform === 'win32' ) {
if (process.platform === 'win32') {
app.setAppUserModelId(pkg.appId)
}
// 去除原生顶部菜单栏
mainWindow.setMenu(null)

if ( process.env.WEBPACK_DEV_SERVER_URL ) {
if (process.env.WEBPACK_DEV_SERVER_URL) {
mainWindow.loadURL(process.env.WEBPACK_DEV_SERVER_URL)
} else {
createProtocol(ACHEME)
Expand All @@ -97,19 +112,21 @@ function createWindow () {
mainWindow.once('ready-to-show', () => {
mainWindow.show()
// 设置任务栏操作和缩略图
if ( process.platform === 'win32' ) {
if (process.platform === 'win32') {
setThumbarButtons(mainWindow, false)
mainWindow.setThumbnailClip({ x: 0, y: 0, width: 180, height: 50 })
}
global.lyricWindow = createLyricWindow(BrowserWindow)
global.miniWindow = createMiniWindow(BrowserWindow)
})

if ( isDevelopment ) {
if (isDevelopment) {
// 安装vue-devtools
let extensions = BrowserWindow.getDevToolsExtensions()
if ( !extensions[ 'Vue.js devtools' ] ) {
BrowserWindow.addDevToolsExtension(path.resolve(__dirname, './../../src/main/vue-devtools'))
if (!extensions['Vue.js devtools']) {
BrowserWindow.addDevToolsExtension(
path.resolve(__dirname, './../../src/main/vue-devtools')
)
}
// 打开调试窗口
// mainWindow.webContents.openDevTools()
Expand All @@ -120,21 +137,21 @@ function createWindow () {
// 初始化进程之间事件监听
initIpcEvent()
// 如果是windows系统模拟托盘菜单
if ( process.platform === 'win32' ) {
if (process.platform === 'win32') {
global.tray = createTray(Tray)
let trayBounds = global.tray.getBounds()
global.trayWindow = createTrayWindow(BrowserWindow, trayBounds)
}
}

app.on('window-all-closed', () => {
if ( process.platform !== 'darwin' ) {
if (process.platform !== 'darwin') {
app.quit()
}
})

app.on('activate', () => {
if ( global.mainWindow === null || mainWindow === null ) {
if (global.mainWindow === null || mainWindow === null) {
createWindow()
}
})
Expand All @@ -145,24 +162,24 @@ app.on('ready', () => {
createWindow()
// protocalHandler()
ipcMain.on('thumbar-buttons', (e, data) => {
if ( global.mainWindow === null || mainWindow === null ) return
if ( process.platform === 'win32' ) {
if (global.mainWindow === null || mainWindow === null) return
if (process.platform === 'win32') {
let { playing } = data
setThumbarButtons(mainWindow, playing)
}
})
})

app.on('quit', () => {
if ( global.downloadFile ) {
if (global.downloadFile) {
shell.openItem(global.downloadFile)
}
})

if ( isDevelopment ) {
if ( process.platform === 'win32' ) {
process.on('message', data => {
if ( data === 'graceful-exit' ) {
if (isDevelopment) {
if (process.platform === 'win32') {
process.on('message', (data) => {
if (data === 'graceful-exit') {
app.quit()
}
})
Expand Down
28 changes: 15 additions & 13 deletions src/main/modules/ipcEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,22 @@ export default function () {
state: downloads[args.id].getState()
})
}
}).then(downloadItem => {
// console.log(downloadItem)
global.mainWindow.webContents.send('download-success', {
id: args.id,
song: args.song,
downloadFolder,
downloadUrl
})
.then((downloadItem) => {
// console.log(downloadItem)
global.mainWindow.webContents.send('download-success', {
id: args.id,
song: args.song,
downloadFolder,
downloadUrl
})
})
}).catch(e => {
global.mainWindow.webContents.send('download-error', {
id: args.id,
error: e
.catch((e) => {
global.mainWindow.webContents.send('download-error', {
id: args.id,
error: e
})
})
})
})

ipcMain.on('download-cancel', (e, data) => {
Expand All @@ -136,7 +138,7 @@ export default function () {
}
})

ipcMain.on('open-directory-dialog', event => {
ipcMain.on('open-directory-dialog', (event) => {
dialog.showOpenDialog(
{
defaultPath: defaultDownloadFolder,
Expand Down
Loading

0 comments on commit f08a8e4

Please sign in to comment.