Skip to content

Commit

Permalink
api重构;简版排行榜;解决歌词面板带来的性能问题;稳定性提升
Browse files Browse the repository at this point in the history
  • Loading branch information
sunzongzheng committed Dec 6, 2017
1 parent 8cbd8ba commit 2cfaa13
Show file tree
Hide file tree
Showing 46 changed files with 618 additions and 409 deletions.
47 changes: 29 additions & 18 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,48 @@
"env": {
"test": {
"presets": [
["env", {
"targets": { "node": 7 }
}],
"stage-0"
[
"env",
{
"targets": {
"node": 7
}
}
]
],
"plugins": ["istanbul"]
"plugins": [
"istanbul"
]
},
"main": {
"presets": [
["env", {
"targets": { "node": 7 }
}],
"stage-0"
[
"env",
{
"targets": {
"node": 7
}
}
]
]
},
"renderer": {
"presets": [
["env", {
"modules": false
}],
"stage-0"
[
"env"
]
]
},
"web": {
"presets": [
["env", {
"modules": false
}],
"stage-0"
[
"env"
]
]
}
},
"plugins": ["transform-runtime"]
"plugins": [
"transform-runtime",
"transform-object-rest-spread"
]
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
- 歌曲[Api](https://github.com/sunzongzheng/musicAPI)涵盖网易云、QQ音乐、虾米
- 界面仿QQ音乐
- Mac > Windows > Linux都会逐步适配,移动端在计划中
- [下载页](https://github.com/sunzongzheng/music/releases)
# 已完成
- QQ登录
- 云歌单
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "player",
"version": "1.0.20",
"version": "1.0.22",
"author": "sunzongzheng <[email protected]>",
"description": "An electron-vue project",
"license": "CC0-1.0",
Expand Down Expand Up @@ -65,17 +65,18 @@
"dependencies": {
"@xunlei/vue-context-menu": "^1.0.2",
"axios": "^0.16.1",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"element-ui": "2.0.0",
"fs": "0.0.1-security",
"install": "^0.10.1",
"jquery": "^3.2.1",
"lodash": "^4.17.4",
"moment": "^2.18.1",
"music-api": "git+https://github.com/sunzongzheng/musicAPI.git",
"music-api": "git+https://github.com/sunzongzheng/musicApi.git",
"npm": "^5.5.1",
"passport-qq": "0.0.3",
"request": "^2.82.0",
"shelljs": "^0.7.8",
"velocity-animate": "^1.5.0",
"vue": "2.3.3",
"vue-electron": "^1.0.6",
"vue-router": "2.5.3",
Expand Down
54 changes: 0 additions & 54 deletions src/main/api/index.js

This file was deleted.

7 changes: 0 additions & 7 deletions src/main/api/netease.js

This file was deleted.

7 changes: 0 additions & 7 deletions src/main/api/qq.js

This file was deleted.

7 changes: 0 additions & 7 deletions src/main/api/xiami.js

This file was deleted.

62 changes: 62 additions & 0 deletions src/main/global/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import api from 'music-api'

export default {
...api,
async searchSong(key) {
try {
let data = await api.searchSong(key)
if (data.status) {
data = data.data
// 为了保留 每个平台搜索结果 的排序权重 此处先找出最大长度
let maxLength = 0
for (let i in data) {
const len = data[i].songs.length
if (len > maxLength) {
maxLength = len
}
}
const result = []
for (let i = 0; i < maxLength; i++) {
for (let j in data) {
const cur = data[j].songs[i]
// 如果存在
if (typeof cur !== 'undefined') {
// 检查是否已存在同名 同歌手 同专辑 则跳过
if (result.filter(item => {
// 首先判断歌手是不是全等 此处歌手可能有多个
let art_same = true
item.artists.every((item, index) => {
if (!cur.artists[index] || item.name !== cur.artists[index].name) {
art_same = false
return false
}
return true
})
return item.name === cur.name && art_same && item.album.name === cur.album.name
}).length) {
continue
} else {
result.push({
...cur,
source: j
})
}
}
}
}
return {
status: true,
data: result
}
} else {
return data
}
} catch (e) {
return {
status: false,
msg: e.msg || '搜索失败,请重试',
log: e
}
}
}
}
10 changes: 10 additions & 0 deletions src/main/global/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import axios from 'axios'
import api from './api'

export default {
init(window) {
global.api = api
global.win = window
global.clientApi = axios
}
}
32 changes: 20 additions & 12 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import { app, Menu, Tray, BrowserWindow, nativeImage, ipcMain } from 'electron'
import ipcEvent from './ipcEvent'
import g from './global'
import { version } from '../../package.json'
import axios from 'axios'
/**
* Set `__static` path to static files in production
* https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-static-assets.html
Expand All @@ -16,11 +18,11 @@ const winURL = process.env.NODE_ENV === 'development'
? `http://localhost:9080`
: `file://${__dirname}/index.html`

function initialTray (mainWindow) {
function initialTray(mainWindow) {
var trayIconPath = __static + '/images/logo_32.png'
let appTray = new Tray(trayIconPath)

function toggleVisiable () {
function toggleVisiable() {
var isVisible = mainWindow.isVisible()
if (isVisible) {
mainWindow.hide()
Expand All @@ -32,18 +34,19 @@ function initialTray (mainWindow) {
const contextMenu = Menu.buildFromTemplate([
{
label: '退出',
click () {
click() {
app.quit()
}
}
])
appTray.setToolTip('Player')
appTray.setContextMenu(contextMenu)
appTray.on('click', function handleClicked () {
appTray.on('click', function handleClicked() {
toggleVisiable()
})
}

function initMacTray (mainWindow) {
function initMacTray(mainWindow) {
let next = new Tray(__static + '/images/next_16.png')
let play = new Tray(__static + '/images/play_16.png')
let text = new Tray(nativeImage.createEmpty())
Expand All @@ -67,7 +70,7 @@ function initMacTray (mainWindow) {
})
}

function createWindow () {
function createWindow() {
mainWindow = new BrowserWindow({
height: 650,
useContentSize: true,
Expand All @@ -78,14 +81,18 @@ function createWindow () {
frame: false
})
ipcEvent.on(mainWindow)
fetch('https://raw.githubusercontent.com/sunzongzheng/music/master/package.json')
.then(res => res.json())
.then(data => {
if (version !== data.version) {
// mainWindow.webContents.openDevTools({detach: true})
mainWindow.loadURL(winURL)
axios('https://raw.githubusercontent.com/sunzongzheng/music/master/package.json')
.then(({data}) => {
let cur_version = version.split('.')
data.version = data.version.split('.')
cur_version = parseInt(cur_version[0]) * 10000 + parseInt(cur_version[1]) * 100 + parseInt(cur_version[2])
data.version = parseInt(data.version[0]) * 10000 + parseInt(data.version[1]) * 100 + parseInt(data.version[2])
if (cur_version < data.version) {
mainWindow.webContents.send('version_new')
}
})
mainWindow.loadURL(winURL)
mainWindow.on('closed', () => {
mainWindow = null
})
Expand All @@ -94,6 +101,7 @@ function createWindow () {
} else {
initMacTray(mainWindow)
}
g.init(mainWindow)
}

app.on('ready', createWindow)
Expand Down Expand Up @@ -130,4 +138,4 @@ autoUpdater.on('update-downloaded', () => {
app.on('ready', () => {
if (process.env.NODE_ENV === 'production') autoUpdater.checkForUpdates()
})
*/
*/
28 changes: 0 additions & 28 deletions src/main/ipcEvent/api.js

This file was deleted.

Loading

0 comments on commit 2cfaa13

Please sign in to comment.