This repository has been archived on 2023-08-30. You can view files and clone it, but cannot push or open issues/pull-requests.
appcat
/
sonist
Archived
1
0
Fork 0
sonist/src/main.js

104 lines
2.5 KiB
JavaScript

/**
* 主入口
* @author yutent<yutent.io@gmail.com>
* @date 2020/11/18 09:27:09
*/
const { app, session, protocol, globalShortcut, ipcMain } = require('electron')
const path = require('path')
const fs = require('iofs')
require('./tools/init.js')
const { createMainWindow } = require('./tools/windows.js')
const MIME_TYPES = {
'.js': 'text/javascript',
'.html': 'text/html',
'.htm': 'text/plain',
'.css': 'text/css',
'.jpg': 'image/jpg',
'.png': 'image/png',
'.gif': 'image/gif',
'.svg': 'image/svg+xml',
'.ico': 'image/ico',
'.mp3': 'audio/mpeg',
'.m4a': 'audio/m4a',
'.aac': 'audio/x-aac',
'.ogg': 'audio/ogg',
'.wav': 'audio/x-wav',
'.flac': 'audio/flac',
all: 'audio/*'
}
/* ----------------------------------------------------- */
app.commandLine.appendSwitch('--lang', 'zh-CN')
app.commandLine.appendSwitch('--autoplay-policy', 'no-user-gesture-required')
protocol.registerSchemesAsPrivileged([
{ scheme: 'app', privileges: { secure: true, standard: true } },
{ scheme: 'sonist', privileges: { secure: true, standard: true } }
])
/* ----------------------------------------------------- */
// 初始化应用
app.once('ready', () => {
// 注册协议
protocol.registerStreamProtocol('app', function(req, cb) {
var file = decodeURIComponent(req.url.replace(/^app:\/\/local\//, ''))
var ext = path.extname(req.url)
file = path.resolve(__dirname, file)
cb({
data: fs.origin.createReadStream(file),
mimeType: MIME_TYPES[ext],
headers: {
'Cache-Control': 'max-age=144000000'
}
})
})
protocol.registerStreamProtocol('sonist', function(req, cb) {
var file = decodeURIComponent(req.url.replace(/^sonist:[\/]+/, '/'))
var ext = path.extname(req.url)
cb({
data: fs.origin.createReadStream(file),
mimeType: MIME_TYPES[ext] || MIME_TYPES.all,
headers: {
'Cache-Control': 'max-age=144000000'
}
})
})
// 修改app的UA
session.defaultSession.setUserAgent(
'KugouMusic/2.9.5 (Mac OS X Version 10.15.7 (Build 19H2))'
)
let win = createMainWindow(path.resolve(__dirname, './images/app.png'))
// mac专属事件,点击dock栏图标,可激活窗口
app.on('activate', _ => {
if (win) {
win.restore()
}
})
ipcMain.on('app', (ev, conn) => {
switch (conn.type) {
case 'update-lrc':
win.__lrc__.setTitle(conn.data.lrc)
ev.returnValue = true
break
default:
break
}
})
})
// 退出前清空所有快捷键
app.on('will-quit', () => {
globalShortcut.unregisterAll()
})
一个音乐播放器, 主打本地音乐播放。支持 自动歌词/自动封面/均衡器等常见功能。
JavaScript 60.1%
SCSS 19.2%
HTML 16.9%
CSS 3.8%