diff --git a/src/js/app.js b/src/js/app.js
index e395554..51ce6cc 100644
--- a/src/js/app.js
+++ b/src/js/app.js
@@ -50,15 +50,8 @@ let appInit = ipcRenderer.sendSync('get-init')
Anot.ss('app-init', appInit)
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({
$id: 'app',
state: {
@@ -186,6 +179,32 @@ Anot({
remote.app.on('browser-window-blur', _ => {
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: {
quit(force) {
@@ -203,8 +222,14 @@ Anot({
WIN.minimize()
},
change2mini() {
+ this.optBoxShow = false
WIN.hide()
MINI_WIN.show()
+ let song = this.curr.$model
+ if (!this.isPlaying) {
+ delete song.id
+ }
+ MINI_WIN.emit('mini-init', song)
},
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) {
let _p = null
if (step > 0) {
@@ -304,13 +350,10 @@ Anot({
})
},
- pause() {
- this.isPlaying = false
- },
-
updateCurr(obj) {
let old = this.curr.$model
this.curr = Object.assign(old, obj)
+ MINI_WIN.emit('mini-init', this.curr.$model)
},
play(song) {
diff --git a/src/js/mini-win.js b/src/js/mini-win.js
index b0760b8..5adabec 100644
--- a/src/js/mini-win.js
+++ b/src/js/mini-win.js
@@ -8,36 +8,58 @@
import '/lib/anot.next.js'
-const { remote } = require('electron')
+const { remote, ipcRenderer } = require('electron')
const WIN = remote.getCurrentWindow()
-const MAIN_WIN = WIN.getParentWindow()
-window.WIN = WIN
+ipcRenderer.on('post-main', (ev, val) => {
+ window.__MAIN__ = val
+})
+
Anot({
$id: 'mini',
state: {
isPlaying: false,
curr: {
id: '',
- title: '假装不合适',
+ title: '',
artist: '',
album: '',
time: 0,
duration: 0,
- cover: '/images/album.png'
+ cover: ''
},
pinned: true,
playMode: Anot.ls('play-mode') >>> 0
},
mounted() {
- WIN.on('ktv-lrc', lrc => {
- this.lrc = lrc
+ WIN.on('mini-init', song => {
+ this.curr = song
+ if (song.id) {
+ this.isPlaying = true
+ }
+ this.playMode = Anot.ls('play-mode') >>> 0
})
},
methods: {
- play() {},
- nextSong() {},
+ handleCtrl(ev) {
+ 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) {
let key = ev.target.dataset.key
@@ -48,7 +70,7 @@ Anot({
break
case 'quit':
WIN.hide()
- MAIN_WIN.show()
+ remote.app.__MAIN__.show()
break
default:
break
@@ -58,7 +80,7 @@ Anot({
let key = ev.target.dataset.key
switch (key) {
case 'lrc':
- MAIN_WIN.emit('toggle-desktoplrc')
+ remote.app.__MAIN__.emit('mini-ctrl', 'desktoplrc')
break
case 'mode':
let mod = this.playMode
@@ -67,7 +89,10 @@ Anot({
mod = 0
}
this.playMode = mod
- MAIN_WIN.emit('play-mode', mod)
+ remote.app.__MAIN__.emit('mini-ctrl', {
+ name: 'play-mode',
+ value: mod
+ })
}
}
}
diff --git a/src/main.js b/src/main.js
index 98c5cb8..e1e34e6 100644
--- a/src/main.js
+++ b/src/main.js
@@ -63,6 +63,7 @@ app.once('ready', () => {
let win = createMainWindow(path.resolve(ROOT, './images/app.png'))
createTray(win)
createMenu(win)
+ app.__MAIN__ = win
// mac专属事件,点击dock栏图标,可激活窗口
app.on('activate', _ => {
if (win) {
diff --git a/src/mini-win.html b/src/mini-win.html
index 45c4900..054642e 100644
--- a/src/mini-win.html
+++ b/src/mini-win.html
@@ -11,23 +11,23 @@
-
-
+
+
-
-
-
+
+
+
+ data-key="play"
+ :class="{'s-icon-play': !isPlaying, 's-icon-pause': isPlaying}" >
-
+
-