lint: prettier lint

master
kunkka 4 years ago
parent 86b4b9d523
commit a9e153cfd6

@ -25,8 +25,8 @@
import Navbar from "./components/Navbar.vue"; import Navbar from "./components/Navbar.vue";
import Player from "./components/Player.vue"; import Player from "./components/Player.vue";
import GlobalEvents from "vue-global-events"; import GlobalEvents from "vue-global-events";
const electron = window.require('electron') const electron = window.require("electron");
const ipcRenderer = electron.ipcRenderer const ipcRenderer = electron.ipcRenderer;
export default { export default {
name: "App", name: "App",
@ -35,44 +35,44 @@ export default {
Player, Player,
GlobalEvents, GlobalEvents,
}, },
created(){ created() {
// listens to the main process 'changeRouteTo' event and changes the route from // listens to the main process 'changeRouteTo' event and changes the route from
// inside this Vue instance, according to what path the main process requires. // inside this Vue instance, according to what path the main process requires.
// responds to Menu click() events at the main process and changes the route accordingly. // responds to Menu click() events at the main process and changes the route accordingly.
ipcRenderer.on('changeRouteTo', (event, path) => { ipcRenderer.on("changeRouteTo", (event, path) => {
console.log(event) console.log(event);
this.$router.push(path) this.$router.push(path);
}) });
ipcRenderer.on('play', () => { ipcRenderer.on("play", () => {
this.$refs.player.play() this.$refs.player.play();
}) });
ipcRenderer.on('next', () => { ipcRenderer.on("next", () => {
this.$refs.player.next() this.$refs.player.next();
}) });
ipcRenderer.on('previous', () => { ipcRenderer.on("previous", () => {
this.$refs.player.previous() this.$refs.player.previous();
}) });
ipcRenderer.on('increaseVolume', () => { ipcRenderer.on("increaseVolume", () => {
if (this.$refs.player.volume + 0.1 >= 1) { if (this.$refs.player.volume + 0.1 >= 1) {
return this.$refs.player.volume = 1 return (this.$refs.player.volume = 1);
} }
this.$refs.player.volume += 0.1 this.$refs.player.volume += 0.1;
}) });
ipcRenderer.on('decreaseVolume', () => { ipcRenderer.on("decreaseVolume", () => {
if (this.$refs.player.volume - 0.1 <= 0) { if (this.$refs.player.volume - 0.1 <= 0) {
return this.$refs.player.volume = 0 return (this.$refs.player.volume = 0);
} }
this.$refs.player.volume -= 0.1 this.$refs.player.volume -= 0.1;
}) });
ipcRenderer.on('like', () => { ipcRenderer.on("like", () => {
this.$refs.player.likeCurrentSong() this.$refs.player.likeCurrentSong();
}) });
ipcRenderer.on('repeat', () => { ipcRenderer.on("repeat", () => {
this.$refs.player.repeat() this.$refs.player.repeat();
}) });
ipcRenderer.on('shuffle', () => { ipcRenderer.on("shuffle", () => {
this.$refs.player.shuffle() this.$refs.player.shuffle();
}) });
}, },
methods: { methods: {
play(e) { play(e) {

@ -1,6 +1,6 @@
"use strict"; "use strict";
import path from 'path' import path from "path";
// import { autoUpdater } from "electron-updater" // import { autoUpdater } from "electron-updater"
import { import {
app, app,
@ -23,27 +23,27 @@ let win;
protocol.registerSchemesAsPrivileged([ protocol.registerSchemesAsPrivileged([
{ scheme: "app", privileges: { secure: true, standard: true } }, { scheme: "app", privileges: { secure: true, standard: true } },
]); ]);
const iconString = path.join(__static, "img/icons/apple-touch-icon.png") const iconString = path.join(__static, "img/icons/apple-touch-icon.png");
let bounceId = app.dock.bounce() let bounceId = app.dock.bounce();
app.dock.setIcon(iconString) app.dock.setIcon(iconString);
function createWindow() { function createWindow() {
const touchbar = require('./electron/touchbar.js') const touchbar = require("./electron/touchbar.js");
const tray = require('./electron/tray.js') const tray = require("./electron/tray.js");
const createMenu = require('./electron/menu.js') const createMenu = require("./electron/menu.js");
tray.on('click', function () { tray.on("click", function () {
if (win.isVisible()) { if (win.isVisible()) {
win.hide() win.hide();
} else { } else {
win.show() win.show();
} }
}) });
win = new BrowserWindow({ win = new BrowserWindow({
width: 1440, width: 1440,
height: 768, height: 768,
icon: iconString, icon: iconString,
titleBarStyle: 'default', titleBarStyle: "default",
webPreferences: { webPreferences: {
webSecurity: false, webSecurity: false,
nodeIntegration: true, nodeIntegration: true,
@ -52,13 +52,13 @@ function createWindow() {
}); });
try { try {
createMenu(win) createMenu(win);
win.setTouchBar(touchbar) win.setTouchBar(touchbar);
win.setAutoHideCursor(true) win.setAutoHideCursor(true);
app.dock.cancelBounce(bounceId) app.dock.cancelBounce(bounceId);
// autoUpdater.checkForUpdatesAndNotify() // autoUpdater.checkForUpdatesAndNotify()
} catch (error) { } catch (error) {
console.log(error) console.log(error);
} }
if (process.env.WEBPACK_DEV_SERVER_URL) { if (process.env.WEBPACK_DEV_SERVER_URL) {
@ -98,7 +98,7 @@ app.on("activate", () => {
// Some APIs can only be used after this event occurs. // Some APIs can only be used after this event occurs.
app.on("ready", async () => { app.on("ready", async () => {
// 启动 api 服务器 // 启动 api 服务器
require('./electron/services.js') require("./electron/services.js");
if (isDevelopment && !process.env.IS_TEST) { if (isDevelopment && !process.env.IS_TEST) {
// Install Vue Devtools // Install Vue Devtools
try { try {

@ -1,178 +1,177 @@
const { app, Menu } = require('electron') const { app, Menu } = require("electron");
// import { autoUpdater } from "electron-updater" // import { autoUpdater } from "electron-updater"
// const version = app.getVersion(); // const version = app.getVersion();
const isMac = process.platform === 'darwin' const isMac = process.platform === "darwin";
function createMenu(win) { function createMenu(win) {
let menu = null let menu = null;
const template = [ const template = [
...(isMac ? [{ ...(isMac
label: app.name, ? [
submenu: [ {
{ role: 'about' }, label: app.name,
{ type: 'separator' }, submenu: [
{ role: 'services' }, { role: "about" },
{ type: 'separator' }, { type: "separator" },
{ type: 'separator' }, { role: "services" },
{ { type: "separator" },
label: 'Preferences...', { type: "separator" },
accelerator: (() => isMac ? 'CmdOrCtrl+,' : 'Ctrl+,')(), {
click: () => { label: "Preferences...",
win.webContents.send("changeRouteTo", "/settings") accelerator: (() => (isMac ? "CmdOrCtrl+," : "Ctrl+,"))(),
click: () => {
win.webContents.send("changeRouteTo", "/settings");
},
role: "preferences",
},
{ type: "separator" },
{ role: "hide" },
{ role: "hideothers" },
{ role: "unhide" },
{ type: "separator" },
{ role: "quit" },
],
}, },
role: 'preferences' ]
}, : []),
{ type: 'separator' },
{ role: 'hide' },
{ role: 'hideothers' },
{ role: 'unhide' },
{ type: 'separator' },
{ role: 'quit' }
]
}] : []),
{ {
label: 'Edit', label: "Edit",
submenu: [ submenu: [
{ role: 'undo' }, { role: "undo" },
{ role: 'redo' }, { role: "redo" },
{ type: 'separator' }, { type: "separator" },
{ role: 'cut' }, { role: "cut" },
{ role: 'copy' }, { role: "copy" },
{ role: 'paste' }, { role: "paste" },
...(isMac ? [ ...(isMac
{ role: 'delete' }, ? [
{ role: 'selectAll' }, { role: "delete" },
{ type: 'separator' }, { role: "selectAll" },
{ { type: "separator" },
label: 'Speech', {
submenu: [ label: "Speech",
{ role: 'startspeaking' }, submenu: [{ role: "startspeaking" }, { role: "stopspeaking" }],
{ role: 'stopspeaking' } },
] ]
} : [{ role: "delete" }, { type: "separator" }, { role: "selectAll" }]),
] : [ ],
{ role: 'delete' },
{ type: 'separator' },
{ role: 'selectAll' }
])
]
}, },
{ {
label: 'Controls', label: "Controls",
submenu: [ submenu: [
{ {
label: 'Play', label: "Play",
accelerator: 'Space', accelerator: "Space",
click: () => { click: () => {
win.webContents.send("play") win.webContents.send("play");
}, },
}, },
{ {
label: 'Next', label: "Next",
accelerator: 'CmdOrCtrl+Right', accelerator: "CmdOrCtrl+Right",
click: () => { click: () => {
win.webContents.send("next") win.webContents.send("next");
}, },
}, },
{ {
label: 'Previous', label: "Previous",
accelerator: 'CmdOrCtrl+Left', accelerator: "CmdOrCtrl+Left",
click: () => { click: () => {
win.webContents.send("previous") win.webContents.send("previous");
}, },
}, },
{ {
label: 'Increase Volume', label: "Increase Volume",
accelerator: 'CmdOrCtrl+Up', accelerator: "CmdOrCtrl+Up",
click: () => { click: () => {
win.webContents.send("increaseVolume") win.webContents.send("increaseVolume");
}, },
}, },
{ {
label: 'Decrease Volume', label: "Decrease Volume",
accelerator: 'CmdOrCtrl+Down', accelerator: "CmdOrCtrl+Down",
click: () => { click: () => {
win.webContents.send("decreaseVolume") win.webContents.send("decreaseVolume");
}, },
}, },
{ {
label: 'Like', label: "Like",
accelerator: 'CmdOrCtrl+L', accelerator: "CmdOrCtrl+L",
click: () => { click: () => {
win.webContents.send("like") win.webContents.send("like");
}, },
}, },
{ {
label: 'Repeat', label: "Repeat",
accelerator: 'Alt+R', accelerator: "Alt+R",
click: () => { click: () => {
win.webContents.send("repeat") win.webContents.send("repeat");
}, },
}, },
{ {
label: 'Shuffle', label: "Shuffle",
accelerator: 'Alt+S', accelerator: "Alt+S",
click: () => { click: () => {
win.webContents.send("shuffle") win.webContents.send("shuffle");
}, },
} },
] ],
}, },
{ {
label: 'Window', label: "Window",
submenu: [ submenu: [
{ role: 'minimize' }, { role: "minimize" },
{ role: 'zoom' }, { role: "zoom" },
{ role: 'reload' }, { role: "reload" },
{ role: 'forcereload' }, { role: "forcereload" },
{ role: 'toggledevtools' }, { role: "toggledevtools" },
{ type: 'separator' }, { type: "separator" },
{ role: 'togglefullscreen' }, { role: "togglefullscreen" },
...(isMac ? [ ...(isMac
{ type: 'separator' }, ? [
{ role: 'front' }, { type: "separator" },
{ type: 'separator' }, { role: "front" },
{ { type: "separator" },
role: 'window', {
id: 'window', role: "window",
label: 'Yes Play Music', id: "window",
type: 'checkbox', label: "Yes Play Music",
checked: true, type: "checkbox",
click: () => { checked: true,
const current = menu.getMenuItemById('window') click: () => {
if (current.checked === false) { const current = menu.getMenuItemById("window");
win.hide() if (current.checked === false) {
} else { win.hide();
win.show() } else {
} win.show();
}, }
} },
] : [ },
{ role: 'close' } ]
]) : [{ role: "close" }]),
] ],
}, },
{ {
label: 'Help', label: "Help",
submenu: [ submenu: [
{ {
label: 'Github', label: "Github",
click: async () => { click: async () => {
const { shell } = require('electron') const { shell } = require("electron");
await shell.openExternal('https://github.com/qier222/YesPlayMusic') await shell.openExternal("https://github.com/qier222/YesPlayMusic");
} },
}, },
{ {
label: 'Electron', label: "Electron",
click: async () => { click: async () => {
const { shell } = require('electron') const { shell } = require("electron");
await shell.openExternal('https://electronjs.org') await shell.openExternal("https://electronjs.org");
} },
}, },
] ],
} },
] ];
// for window // for window
// if (process.platform === "win32") { // if (process.platform === "win32") {
// template.push({ // template.push({
@ -194,10 +193,8 @@ function createMenu(win) {
// ], // ],
// }); // });
// } // }
menu = Menu.buildFromTemplate(template) menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu) Menu.setApplicationMenu(menu);
} }
module.exports = createMenu module.exports = createMenu;

@ -1,57 +1,57 @@
const express = require("express"); const express = require("express");
const bodyParser = require('body-parser') const bodyParser = require("body-parser");
const cache = require('../../napi/util/apicache').middleware const cache = require("../../napi/util/apicache").middleware;
const fileUpload = require('express-fileupload') const fileUpload = require("express-fileupload");
import routes from "../../napi/routes"; import routes from "../../napi/routes";
// Integrate API // Integrate API
const app = express() const app = express();
// CORS & Preflight request // CORS & Preflight request
app.use((req, res, next) => { app.use((req, res, next) => {
if (req.path !== '/' && !req.path.includes('.')) { if (req.path !== "/" && !req.path.includes(".")) {
res.set({ res.set({
'Access-Control-Allow-Credentials': true, "Access-Control-Allow-Credentials": true,
'Access-Control-Allow-Origin': req.headers.origin || '*', "Access-Control-Allow-Origin": req.headers.origin || "*",
'Access-Control-Allow-Headers': 'X-Requested-With,Content-Type', "Access-Control-Allow-Headers": "X-Requested-With,Content-Type",
'Access-Control-Allow-Methods': 'PUT,POST,GET,DELETE,OPTIONS', "Access-Control-Allow-Methods": "PUT,POST,GET,DELETE,OPTIONS",
'Content-Type': 'application/json; charset=utf-8', "Content-Type": "application/json; charset=utf-8",
}) });
} }
req.method === 'OPTIONS' ? res.status(204).end() : next() req.method === "OPTIONS" ? res.status(204).end() : next();
}) });
// cookie parser // cookie parser
app.use((req, res, next) => { app.use((req, res, next) => {
req.cookies = {} req.cookies = {};
;(req.headers.cookie || '').split(/\s*;\s*/).forEach((pair) => { (req.headers.cookie || "").split(/\s*;\s*/).forEach((pair) => {
let crack = pair.indexOf('=') let crack = pair.indexOf("=");
if (crack < 1 || crack == pair.length - 1) return if (crack < 1 || crack == pair.length - 1) return;
req.cookies[ req.cookies[
decodeURIComponent(pair.slice(0, crack)).trim() decodeURIComponent(pair.slice(0, crack)).trim()
] = decodeURIComponent(pair.slice(crack + 1)).trim() ] = decodeURIComponent(pair.slice(crack + 1)).trim();
}) });
next() next();
}) });
// body parser // body parser
app.use(bodyParser.json()) app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false })) app.use(bodyParser.urlencoded({ extended: false }));
app.use(fileUpload()) app.use(fileUpload());
// cache // cache
app.use(cache('2 minutes', (req, res) => res.statusCode === 200)) app.use(cache("2 minutes", (req, res) => res.statusCode === 200));
// router // router
Object.keys(routes).forEach(route => { Object.keys(routes).forEach((route) => {
app.use(route, routes[route]) app.use(route, routes[route]);
}) });
const port = process.env.PORT || 10754 const port = process.env.PORT || 10754;
const host = process.env.HOST || '127.0.0.1' const host = process.env.HOST || "127.0.0.1";
app.server = app.listen(port, host, () => { app.server = app.listen(port, host, () => {
console.log(`server running @ http://${host ? host : 'localhost'}:${port}`) console.log(`server running @ http://${host ? host : "localhost"}:${port}`);
}) });

@ -1,96 +1,92 @@
const { const { app, BrowserWindow, TouchBar } = require("electron");
app,
BrowserWindow,
TouchBar
} = require('electron')
const { TouchBarLabel, TouchBarButton, TouchBarSpacer } = TouchBar const { TouchBarLabel, TouchBarButton, TouchBarSpacer } = TouchBar;
let spinning = false let spinning = false;
// Reel labels // Reel labels
const reel1 = new TouchBarLabel() const reel1 = new TouchBarLabel();
const reel2 = new TouchBarLabel() const reel2 = new TouchBarLabel();
const reel3 = new TouchBarLabel() const reel3 = new TouchBarLabel();
// Spin result label // Spin result label
const result = new TouchBarLabel() const result = new TouchBarLabel();
// Spin button // Spin button
const spin = new TouchBarButton({ const spin = new TouchBarButton({
label: '🎰 Spin', label: "🎰 Spin",
backgroundColor: '#7851A9', backgroundColor: "#7851A9",
click: () => { click: () => {
// Ignore clicks if already spinning // Ignore clicks if already spinning
if (spinning) { if (spinning) {
return return;
} }
spinning = true spinning = true;
result.label = '' result.label = "";
let timeout = 10 let timeout = 10;
const spinLength = 4 * 1000 // 4 seconds const spinLength = 4 * 1000; // 4 seconds
const startTime = Date.now() const startTime = Date.now();
const spinReels = () => { const spinReels = () => {
updateReels() updateReels();
if ((Date.now() - startTime) >= spinLength) { if (Date.now() - startTime >= spinLength) {
finishSpin() finishSpin();
} else { } else {
// Slow down a bit on each spin // Slow down a bit on each spin
timeout *= 1.1 timeout *= 1.1;
setTimeout(spinReels, timeout) setTimeout(spinReels, timeout);
} }
} };
spinReels() spinReels();
} },
}) });
const getRandomValue = () => { const getRandomValue = () => {
const values = ['🍒', '💎', '7⃣', '🍊', '🔔', '⭐', '🍇', '🍀'] const values = ["🍒", "💎", "7⃣", "🍊", "🔔", "⭐", "🍇", "🍀"];
return values[Math.floor(Math.random() * values.length)] return values[Math.floor(Math.random() * values.length)];
} };
const updateReels = () => { const updateReels = () => {
reel1.label = getRandomValue() reel1.label = getRandomValue();
reel2.label = getRandomValue() reel2.label = getRandomValue();
reel3.label = getRandomValue() reel3.label = getRandomValue();
} };
const finishSpin = () => { const finishSpin = () => {
const uniqueValues = new Set([reel1.label, reel2.label, reel3.label]).size const uniqueValues = new Set([reel1.label, reel2.label, reel3.label]).size;
if (uniqueValues === 1) { if (uniqueValues === 1) {
// All 3 values are the same // All 3 values are the same
result.label = '💰 Jackpot!' result.label = "💰 Jackpot!";
result.textColor = '#FDFF00' result.textColor = "#FDFF00";
} else if (uniqueValues === 2) { } else if (uniqueValues === 2) {
// 2 values are the same // 2 values are the same
result.label = '😍 Winner!' result.label = "😍 Winner!";
result.textColor = '#FDFF00' result.textColor = "#FDFF00";
} else { } else {
// No values are the same // No values are the same
result.label = '🙁 Spin Again' result.label = "🙁 Spin Again";
result.textColor = null result.textColor = null;
} }
spinning = false spinning = false;
} };
const touchBar = new TouchBar({ const touchBar = new TouchBar({
items: [ items: [
spin, spin,
new TouchBarSpacer({ size: 'large' }), new TouchBarSpacer({ size: "large" }),
reel1, reel1,
new TouchBarSpacer({ size: 'small' }), new TouchBarSpacer({ size: "small" }),
reel2, reel2,
new TouchBarSpacer({ size: 'small' }), new TouchBarSpacer({ size: "small" }),
reel3, reel3,
new TouchBarSpacer({ size: 'large' }), new TouchBarSpacer({ size: "large" }),
result result,
] ],
}) });
// let window // let window
@ -104,4 +100,4 @@ const touchBar = new TouchBar({
// window.setTouchBar(touchBar) // window.setTouchBar(touchBar)
// }) // })
module.exports = touchBar module.exports = touchBar;

@ -1,12 +1,12 @@
const path = require('path') const path = require("path");
const { Menu, Tray } = require('electron') const { Menu, Tray } = require("electron");
let tray = null let tray = null;
const macIcon = path.join(__static, "img/icons/menu.png") const macIcon = path.join(__static, "img/icons/menu.png");
const winIcon = path.join(__static, "img/icons/icon.ico") const winIcon = path.join(__static, "img/icons/icon.ico");
tray = new Tray(macIcon) tray = new Tray(macIcon);
// Temporary no need for menu. // Temporary no need for menu.
// const contextMenu = Menu.buildFromTemplate([ // const contextMenu = Menu.buildFromTemplate([
@ -21,4 +21,4 @@ tray = new Tray(macIcon)
// Call this again for Linux because we modified the context menu // Call this again for Linux because we modified the context menu
// tray.setContextMenu(contextMenu) // tray.setContextMenu(contextMenu)
module.exports = tray module.exports = tray;

@ -36,7 +36,7 @@ export default {
artist: "Artist", artist: "Artist",
videos: "Music Videos", videos: "Music Videos",
following: "Following", following: "Following",
follow: "Follow" follow: "Follow",
}, },
album: { album: {
released: "Released", released: "Released",

@ -33,7 +33,7 @@ export default {
artist: "歌手", artist: "歌手",
videos: "个MV", videos: "个MV",
following: "已关注", following: "已关注",
follow: "关注" follow: "关注",
}, },
album: { album: {
released: "发行于", released: "发行于",

@ -2,7 +2,10 @@
import { register } from "register-service-worker"; import { register } from "register-service-worker";
if (process.env.NODE_ENV === "production" && process.env.IS_ELECTRON === 'undefined') { if (
process.env.NODE_ENV === "production" &&
process.env.IS_ELECTRON === "undefined"
) {
register(`${process.env.BASE_URL}service-worker.js`, { register(`${process.env.BASE_URL}service-worker.js`, {
ready() { ready() {
console.log( console.log(

@ -1,11 +1,11 @@
import axios from "axios"; import axios from "axios";
let baseURL = '' let baseURL = "";
// Web 和 Electron 跑在不同端口避免同时启动时冲突 // Web 和 Electron 跑在不同端口避免同时启动时冲突
if (process.env.IS_ELECTRON) { if (process.env.IS_ELECTRON) {
baseURL = process.env.VUE_APP_ELECTRON_API_URL baseURL = process.env.VUE_APP_ELECTRON_API_URL;
} else { } else {
baseURL = process.env.VUE_APP_NETEASE_API_URL baseURL = process.env.VUE_APP_NETEASE_API_URL;
} }
const service = axios.create({ const service = axios.create({

Loading…
Cancel
Save