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

完成迷你模式

2.x
宇天 2019-01-26 23:26:49 +08:00
parent 4bcc894ec3
commit 22eea930c7
5 changed files with 107 additions and 38 deletions

View File

@ -120,14 +120,14 @@
<div class="contrl-bar"> <div class="contrl-bar">
<div class="play-box"> <div class="play-box" :click="handleCtrl">
<span class="item prev s-icon-prev" :click="nextSong(-1)"></span> <span class="item prev s-icon-prev" data-key="prev"></span>
<span <span
class="item play" class="item play"
:class="{'s-icon-play': !isPlaying, 's-icon-pause': isPlaying}" data-key="prev"
:click="play(null)"> :class="{'s-icon-play': !isPlaying, 's-icon-pause': isPlaying}">
</span> </span>
<span class="item next s-icon-next" :click="nextSong(1)"></span> <span class="item next s-icon-next" data-key="prev"></span>
</div> </div>
<div class="stat-box"> <div class="stat-box">

View File

@ -50,15 +50,8 @@ let appInit = ipcRenderer.sendSync('get-init')
Anot.ss('app-init', appInit) Anot.ss('app-init', appInit)
const LRC_WIN = createDesktopLrcWindow(MAIN_SCREEN) const LRC_WIN = createDesktopLrcWindow(MAIN_SCREEN)
// const MINI_WIN = createMiniWindow(MAIN_SCREEN, WIN) const MINI_WIN = createMiniWindow(MAIN_SCREEN, WIN)
// WIN.hide()
// MINI_WIN.show()
// MINI_WIN.opener = WIN
// MINI_WIN.openDevTools()
// window.MINI_WIN = MINI_WIN
Anot({ Anot({
$id: 'app', $id: 'app',
state: { state: {
@ -186,6 +179,32 @@ Anot({
remote.app.on('browser-window-blur', _ => { remote.app.on('browser-window-blur', _ => {
this.winFocus = false this.winFocus = false
}) })
/**
* 响应mini窗口的事件
*/
WIN.on('mini-ctrl', ev => {
switch (ev) {
case 'prev':
this.nextSong(-1)
break
case 'play':
this.play()
break
case 'next':
this.nextSong(1)
break
case 'desktoplrc':
this.toggleDesktopLrc()
break
default:
if (ev.name === 'play-mode') {
this.playMode = ev.value
SONIST.mode = PLAY_MODE[ev.value]
Anot.ls('play-mode', ev.value)
}
}
})
}, },
methods: { methods: {
quit(force) { quit(force) {
@ -203,8 +222,14 @@ Anot({
WIN.minimize() WIN.minimize()
}, },
change2mini() { change2mini() {
this.optBoxShow = false
WIN.hide() WIN.hide()
MINI_WIN.show() MINI_WIN.show()
let song = this.curr.$model
if (!this.isPlaying) {
delete song.id
}
MINI_WIN.emit('mini-init', song)
}, },
activeModule(mod) { activeModule(mod) {
@ -286,6 +311,27 @@ Anot({
} }
}, },
/**
* 播放按钮的事件
*/
handleCtrl(ev) {
let key = ev.target.dataset.key
switch (key) {
case 'prev':
this.nextSong(-1)
break
case 'play':
this.play()
break
case 'next':
this.nextSong(1)
break
default:
break
}
},
nextSong(step) { nextSong(step) {
let _p = null let _p = null
if (step > 0) { if (step > 0) {
@ -304,13 +350,10 @@ Anot({
}) })
}, },
pause() {
this.isPlaying = false
},
updateCurr(obj) { updateCurr(obj) {
let old = this.curr.$model let old = this.curr.$model
this.curr = Object.assign(old, obj) this.curr = Object.assign(old, obj)
MINI_WIN.emit('mini-init', this.curr.$model)
}, },
play(song) { play(song) {

View File

@ -8,36 +8,58 @@
import '/lib/anot.next.js' import '/lib/anot.next.js'
const { remote } = require('electron') const { remote, ipcRenderer } = require('electron')
const WIN = remote.getCurrentWindow() const WIN = remote.getCurrentWindow()
const MAIN_WIN = WIN.getParentWindow()
window.WIN = WIN ipcRenderer.on('post-main', (ev, val) => {
window.__MAIN__ = val
})
Anot({ Anot({
$id: 'mini', $id: 'mini',
state: { state: {
isPlaying: false, isPlaying: false,
curr: { curr: {
id: '', id: '',
title: '假装不合适', title: '',
artist: '', artist: '',
album: '', album: '',
time: 0, time: 0,
duration: 0, duration: 0,
cover: '/images/album.png' cover: ''
}, },
pinned: true, pinned: true,
playMode: Anot.ls('play-mode') >>> 0 playMode: Anot.ls('play-mode') >>> 0
}, },
mounted() { mounted() {
WIN.on('ktv-lrc', lrc => { WIN.on('mini-init', song => {
this.lrc = lrc this.curr = song
if (song.id) {
this.isPlaying = true
}
this.playMode = Anot.ls('play-mode') >>> 0
}) })
}, },
methods: { methods: {
play() {}, handleCtrl(ev) {
nextSong() {}, let key = ev.target.dataset.key
switch (key) {
case 'prev':
remote.app.__MAIN__.emit('mini-ctrl', 'prev')
break
case 'play':
this.isPlaying = !this.isPlaying
remote.app.__MAIN__.emit('mini-ctrl', 'play')
break
case 'next':
remote.app.__MAIN__.emit('mini-ctrl', 'next')
break
default:
break
}
},
handleTool(ev) { handleTool(ev) {
let key = ev.target.dataset.key let key = ev.target.dataset.key
@ -48,7 +70,7 @@ Anot({
break break
case 'quit': case 'quit':
WIN.hide() WIN.hide()
MAIN_WIN.show() remote.app.__MAIN__.show()
break break
default: default:
break break
@ -58,7 +80,7 @@ Anot({
let key = ev.target.dataset.key let key = ev.target.dataset.key
switch (key) { switch (key) {
case 'lrc': case 'lrc':
MAIN_WIN.emit('toggle-desktoplrc') remote.app.__MAIN__.emit('mini-ctrl', 'desktoplrc')
break break
case 'mode': case 'mode':
let mod = this.playMode let mod = this.playMode
@ -67,7 +89,10 @@ Anot({
mod = 0 mod = 0
} }
this.playMode = mod this.playMode = mod
MAIN_WIN.emit('play-mode', mod) remote.app.__MAIN__.emit('mini-ctrl', {
name: 'play-mode',
value: mod
})
} }
} }
} }

View File

@ -63,6 +63,7 @@ app.once('ready', () => {
let win = createMainWindow(path.resolve(ROOT, './images/app.png')) let win = createMainWindow(path.resolve(ROOT, './images/app.png'))
createTray(win) createTray(win)
createMenu(win) createMenu(win)
app.__MAIN__ = win
// mac专属事件,点击dock栏图标,可激活窗口 // mac专属事件,点击dock栏图标,可激活窗口
app.on('activate', _ => { app.on('activate', _ => {
if (win) { if (win) {

View File

@ -11,23 +11,23 @@
</head> </head>
<body class="do-fn-noselect" anot="mini"> <body class="do-fn-noselect" anot="mini">
<div class="app"> <div class="app">
<span class="cover"> <span class="cover do-fn-drag">
<img :attr-src="curr.cover" /> <img :attr-src="curr.cover || '/images/album.png'" />
</span> </span>
<div class="ctrl"> <div class="ctrl">
<h3 class="title" :text="curr.title"></h3> <h3 class="title do-fn-ell do-fn-drag" :text="curr.title ? '正在播放: ' + curr.title : '已经停止播放...'"></h3>
<div class="btns"> <div class="btns" :click="handleCtrl">
<span class="s-icon-prev" :click="nextSong(-1)"></span> <span class="s-icon-prev" data-key="prev"></span>
<span <span
class="play" class="play"
:class="{'s-icon-play': !isPlaying, 's-icon-pause': isPlaying}" data-key="play"
:click="play(null)"> :class="{'s-icon-play': !isPlaying, 's-icon-pause': isPlaying}" >
</span> </span>
<span class="s-icon-next" :click="nextSong(1)"></span> <span class="s-icon-next" data-key="next"></span>
</div> </div>
</div> </div>
<div class="tools" :click="handleTool"> <div class="tools do-fn-nodrag" :click="handleTool">
<span data-key="pin" class="do-icon-pin" :class="{active: pinned}"></span> <span data-key="pin" class="do-icon-pin" :class="{active: pinned}"></span>
<span data-key="quit" class="do-icon-maximized"></span> <span data-key="quit" class="do-icon-maximized"></span>
</div> </div>