Skip to content

Commit

Permalink
新增眨眨眼提醒
Browse files Browse the repository at this point in the history
修复提示框无法关闭
修复无法重置番茄
修复初始化数据不正常
  • Loading branch information
maxiloEmmmm committed Oct 27, 2021
1 parent c5d4888 commit 9d9e0a9
Show file tree
Hide file tree
Showing 15 changed files with 144 additions and 83 deletions.
7 changes: 4 additions & 3 deletions tomato-app/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"name": "tomato-app",
"description": "变得更好",
"version": "0.0.1",
"description": "休息屁股、背及肩膀和颈椎",
"version": "0.0.2",
"main": "main.js",
"productName": "番茄钟",
"scripts": {
"start": "electron .",
"pack-win": "electron-builder --win --x64",
"pack-mac": "electron-builder --mac --x64"
"pack-mac": "electron-builder --mac --x64",
"pack-all": "npm run pack-mac && npm run pack-win"
},
"repository": "https://github.com/electron/electron-quick-start",
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion tomato-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"core-js": "^3.6.5",
"less": "^3.8.1",
"less-loader": "^4.1.0",
"maxilo-vue": "3.0.7-beta13",
"maxilo-vue": "3.0.7-beta14",
"maxilo-vue-ysz-ui": "0.0.15-beta3",
"moment": "^2.24.0",
"normalize.css": "^8.0.1",
Expand Down
13 changes: 10 additions & 3 deletions tomato-web/src/boostrap.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import maxiloVue from 'maxilo-vue';
import configDefault from "config/tomato"

import {configToDB} from 'store/doing/config'
maxiloVue.register({
register(app){

},
async boot(app){
let db = await app.make("db")
Expand All @@ -13,7 +14,6 @@ maxiloVue.register({
Object.keys(cs).forEach(c => {
existKeys[c] = cs[c].value
})
store.commit("config/setDBConfig", existKeys)
utils.add("app.refreshConfig", (tmp) => {
store.commit("config/setDBConfig", tmp)
})
Expand All @@ -40,9 +40,16 @@ maxiloVue.register({
if(appendConfigKeys.length != 0) {
let configInitSql = "insert into `config`(`key`, `value`) values"
appendConfigKeys.forEach(c => {
configInitSql += `("${c}", ""),`
configInitSql += `("${c}", "${configToDB({[c]: configDefault[c]})[c]}"),`
})
db.iexec(configInitSql.slice(0, -1))
}

let dbConfig = utils.tool.makeKey(db.iquery("select * from config"), "key")
let dc = {}
Object.keys(dbConfig).forEach(c => {
dc[c] = dbConfig[c].value
})
store.commit("config/setDBConfig", dc)
}
})
2 changes: 2 additions & 0 deletions tomato-web/src/component/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
Checkbox,
Progress,
Statistic,
Slider,
Alert,
Rate
} from 'ant-design-vue'
Expand Down Expand Up @@ -71,6 +72,7 @@ maxiloVue.vue.use(Drawer)
maxiloVue.vue.use(Alert)
maxiloVue.vue.use(Checkbox)
maxiloVue.vue.use(Progress)
maxiloVue.vue.use(Slider)
maxiloVue.vue.use(Statistic)
maxiloVue.vue.use(function(Vue){
Vue.prototype.$message = Message
Expand Down
5 changes: 4 additions & 1 deletion tomato-web/src/config/tomato.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ export default {
restConfirmGoTomato: false,
workTipTime: 0,
workTipMsg: "",
pauseKey: "z"
pauseKey: "z",
blinkEnable: true,
maxBlinkMinute: 5,
blinkTomatoPercent: 0.2
}
3 changes: 2 additions & 1 deletion tomato-web/src/pages/action-confirm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ export default {
this.$emit("notification", {
title: "长时间未处理",
msg: "请尽快处理",
win_time: 5
win_time: 5,
focus: !!this.$store.state.config.confirmTipMissFocus
})
}, this.$store.state.config.waitTipInterval * 1000)
}
Expand Down
20 changes: 12 additions & 8 deletions tomato-web/src/pages/action-layout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,21 @@ export default {
frame: false, show: false, title: '提醒', icon: ico,
width: 350,
height: 90,
x: 0,
y: 0
x: payload.x === undefined ? 0 : payload.x,
y: payload.y === undefined ? 0 : payload.y
})
let r = this.$utils.tool.random('win-')
this.setInfo({
title: payload.title ? payload.title : "",
msg: payload.msg ? payload.msg : "~",
wid: notificationWin.id,
time: !!payload.win_time ? payload.win_time : 0,
ws: {
title: payload.title ? payload.title : "",
msg: payload.msg ? payload.msg : "~",
wid: notificationWin.id,
key: r,
time: !!payload.win_time ? payload.win_time : 0,
}
})
notificationWin.loadURL(this.$utils.href('/notification'))
notificationWin.loadURL(this.$utils.href(`/notification/${r}`))
// notificationWin.webContents.openDevTools()
if(payload.focus) {
notificationWin.show()
}else {
Expand Down
95 changes: 56 additions & 39 deletions tomato-web/src/pages/action-tomato.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@
</style>

<script>
import {TomatoStart, TomatoEnd, TomatoToRest, MusicPlayTomatoEnd, ActionPause} from "config/log"
import {TomatoStart, TomatoEnd, TomatoToRest, TomatoReset, MusicPlayTomatoEnd, ActionPause} from "config/log"
export default {
data(){return {time: 25, current: 0, action: '', handler: null}},
computed: {
_percent(){return (this.current / (this.time * 60)) * 100},
_running(){return !!this.handler && this.current < this.time}
_running(){return !!this.handler && this.current < (this.time * 60)}
},
beforeCreate(){
this.$emit('navInfo', {name: 'action-before'})
Expand All @@ -84,44 +84,61 @@ export default {
methods: {
setActionStatus(mode){this.action = mode},
run(){
if(this._running) return
this.$emit("notification", {
title: `${this.time}分钟番茄${this.current != 0 ? '继续' : '开始'}!`,
msg: "~",
win_time: 6
})
this.$emit("hide-app")
this.setActionStatus('run');
this.handler = setInterval(() => {
this.current++
if(this.$store.state.config.workTipTime > 0 && this.current == (this.time - this.$store.state.config.workTipTime) * 60) {
this.$utils.app.log(MusicPlayTomatoEnd)
this.$emit("notification", {
title: this.$store.state.config.workTipMsg ? this.$store.state.config.workTipMsg : "提示!",
msg: "~",
win_time: 6
})
}
if(this.current >= this.time * 60) {
this.$utils.app.log(TomatoEnd, {
time: this.time,
current: this.current,
})
this.pause()
if(this.$store.state.config.resetEndMusicEnable) {
this.$emit("play", { key: "tomato_end" })
this.$nextTick(() => {
if(this._running) return
this.setActionStatus('run');
this.$emit("notification", {
title: `${this.time}分钟番茄${this.current != 0 ? '继续' : '开始'}!`,
msg: "~",
win_time: 6
})
this.$emit("hide-app")
this.handler = setInterval(() => {
this.current++
if(this.$store.state.config.blinkEnable) {
let t = this.$store.state.config.blinkTomatoPercent * this.time
if(t > this.$store.state.config.maxBlinkMinute) {
t = this.$store.state.config.maxBlinkMinute
}
if(this.current % Math.floor(t * 60) === 0) {
this.$emit("notification", {
title: `请眨眨眼😉`,
msg: "~",
win_time: 4,
x: 200, y: 200
})
}
}
this.$emit("notification", {
title: "番茄熟了!",
msg: "~",
win_time: 6
})
this.$router.push({name: "action-confirm", params: {
link: "action-rest",
title: "休息!"
}})
}
}, 1000)
if(this.$store.state.config.workTipTime > 0 && this.current == (this.time - this.$store.state.config.workTipTime) * 60) {
this.$utils.app.log(MusicPlayTomatoEnd)
this.$emit("notification", {
title: this.$store.state.config.workTipMsg ? this.$store.state.config.workTipMsg : "提示!",
msg: "~",
win_time: 6
})
}
if(this.current >= this.time * 60) {
this.$utils.app.log(TomatoEnd, {
time: this.time,
current: this.current,
})
this.pause()
if(this.$store.state.config.resetEndMusicEnable) {
this.$emit("play", { key: "tomato_end" })
}
this.$emit("notification", {
title: "番茄熟了!",
msg: "~",
win_time: 6
})
this.$router.push({name: "action-confirm", params: {
link: "action-rest",
title: "休息!"
}})
}
}, 1000)
})
},
pause(){
this.setActionStatus('pause')
Expand Down
29 changes: 15 additions & 14 deletions tomato-web/src/pages/notification.vue
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
<template>
<a-card size="small" :title="_title">
<a-card size="small" :title="title">
<a-button slot="extra" size="small" href="#" @click="handleClose">关闭</a-button>
{{_msg}}
{{msg}}
</a-card>
</template>

<script>
import { mapState } from 'vuex'
const {remote} = window.require("electron")
export default {
computed: {
...mapState('notification', {
_title: state => state.title,
_msg: state => state.msg,
_wid: state => state.wid,
_time: state => parseFloat(state.time)
})
data() {
let w = this.$store.state.notification.ws.filter(w => w.key == this.$route.params.id)[0]
return {
title: w.title,
msg: w.msg,
wid: parseInt(w.wid),
time: parseFloat(w.time)
}
},
created(){
console.log(this)
if(this._time != 0 && !isNaN(this._time)) {
setTimeout(this.handleClose, 1000 * this._time)
if(this.time != 0 && !isNaN(this.time)) {
setTimeout(this.handleClose, 1000 * this.time)
}
},
methods: {
handleClose(){remote.BrowserWindow.fromId(this._wid).destroy()}
handleClose(){
remote.BrowserWindow.fromId(this.wid).destroy()
}
},
}
</script>
Expand Down
12 changes: 12 additions & 0 deletions tomato-web/src/pages/setting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@
<a-input v-model="workTipMsg"></a-input>
</ysz-list-item>
</ysz-list-item-top>
<ysz-list-item-top>
<span slot="top">眨眼😉</span>
<ysz-list-item-top>
<ysz-list-item slot="top">
<span slot="left">开启</span><a-switch v-model="blinkEnable"></a-switch>
</ysz-list-item>
<ysz-list-item>
<span slot="left">番茄占比(实际间隔不会小于5分钟)</span>
<a-slider v-model="blinkTomatoPercent" :max="1" :min="0" :step="0.1" style="width:100%"/>
</ysz-list-item>
</ysz-list-item-top>
</ysz-list-item-top>
</a-modal>
</template>

Expand Down
2 changes: 1 addition & 1 deletion tomato-web/src/router/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import maxiloVue from 'maxilo-vue';
import './middleware';
let $router = maxiloVue.make("router").getRoute();

$router.add('/notification', () => import('pages/notification'))
$router.add('/notification/:id', () => import('pages/notification'))
$router.add('/setting', () => import('pages/setting'))
$router.add('/chart', () => import('pages/chart'))

Expand Down
12 changes: 10 additions & 2 deletions tomato-web/src/store/doing/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import maxiloVue from "maxilo-vue"

const state = Object.assign({}, configDefault)

let configToDB = (config) => {
export const configToDB = (config) => {
Object.keys(config).forEach(k => {
switch(k) {
case "volume":
Expand All @@ -14,10 +14,14 @@ let configToDB = (config) => {
case "maxWaitTime":
config[k] = `${parseInt(maxiloVue.make("utils").tool.number(config[k]))}`
break
case "blinkTomatoPercent":
config[k] = `${parseFloat(maxiloVue.make("utils").tool.number(config[k]))}`
break
case "confirmTipMissFocus":
case "workEndMusicEnable":
case "restEndMusicEnable":
case "showAppMissFocus":
case "blinkEnable":
case "restConfirmGoTomato":
config[k] = config[k] ? "1" : "0"
break
Expand All @@ -28,7 +32,7 @@ let configToDB = (config) => {
return config
}

let dbToStore = (config) => {
export const dbToStore = (config) => {
Object.keys(config).forEach(k => {
if(config[k] !== "") {
switch(k) {
Expand All @@ -48,10 +52,14 @@ let dbToStore = (config) => {
case "confirmTipMissFocus":
case "workEndMusicEnable":
case "restEndMusicEnable":
case "blinkEnable":
case "showAppMissFocus":
case "restConfirmGoTomato":
config[k] = config[k] == "1"
break
case "blinkTomatoPercent":
config[k] = parseFloat(maxiloVue.make("utils").tool.number(config[k]))
break
default:
break
}
Expand Down
1 change: 0 additions & 1 deletion tomato-web/src/store/doing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import maxiloVue from 'maxilo-vue';

import notification from './notification';
import config from './config';

//两种方式因人而异

//1
Expand Down
Loading

0 comments on commit 9d9e0a9

Please sign in to comment.