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/js/modules/profile.js

69 lines
1.3 KiB
JavaScript
Raw Normal View History

2018-12-27 03:02:37 +08:00
/**
* 设置模块
* @author yutent<yutent@doui.cc>
* @date 2018/12/27 02:02:54
*/
'use strict'
2019-01-04 16:24:42 +08:00
import '/lib/form/index.js'
2018-12-27 03:02:37 +08:00
const fs = require('iofs')
const path = require('path')
const { app, dialog } = require('electron').remote
const log = console.log
const HOME_PATH = app.getPath('appData')
const APP_INI_PATH = path.join(HOME_PATH, 'app.ini')
let appInit = fs.cat(APP_INI_PATH)
appInit = JSON.parse(appInit)
export default Anot({
$id: 'profile',
state: {
setting: {
2018-12-28 18:47:45 +08:00
allowPlayOnBack: appInit.allowPlayOnBack,
2018-12-27 03:02:37 +08:00
autoLrc: appInit.autoLrc,
2018-12-27 03:09:11 +08:00
theme: appInit.theme || 1,
2018-12-27 03:02:37 +08:00
musicPath: appInit.musicPath
}
},
2018-12-27 03:09:11 +08:00
watch: {
'setting.theme'(v) {
v = +v
this.__APP__.theme = v
}
},
2018-12-27 03:02:37 +08:00
methods: {
2018-12-27 03:09:11 +08:00
__init__() {
this.__APP__ = Anot.vmodels.app
},
2018-12-27 03:02:37 +08:00
openDir() {
dialog.showOpenDialog(
{
properties: ['openDirectory'],
defaultPath: app.getPath('home')
},
dir => {
if (dir) {
this.setting.musicPath = dir[0]
}
}
)
},
save() {
let setting = this.setting.$model
Object.assign(appInit, setting)
2018-12-28 18:47:45 +08:00
let cache = JSON.stringify(appInit, '', 2)
fs.echo(cache, APP_INI_PATH)
Anot.ss('app-init', cache)
2018-12-27 03:02:37 +08:00
layer.toast('保存成功')
}
}
})