Compare commits
6 Commits
Author | SHA1 | Date |
---|---|---|
|
2ec418479b | |
|
65238a97d6 | |
|
59b5e4da96 | |
|
17261cd567 | |
|
e5a44fc917 | |
|
239a69d724 |
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "io.yutent.gaystat",
|
||||
"version": "2.0.0",
|
||||
"version": "2.2.0",
|
||||
"description": "搞基数据",
|
||||
"main": "src/main.js",
|
||||
"scripts": {
|
||||
|
@ -26,7 +26,7 @@
|
|||
"version": "11.0.4",
|
||||
"mirror": "https://npm.taobao.org/mirrors/electron/"
|
||||
},
|
||||
"files": ["src/**/*", "node_modules/iofs/*"],
|
||||
"files": ["src/**/*", "node_modules/iofs/*", "node_modules/node-fetch/*"],
|
||||
"mac": {
|
||||
"category": "public.app-category.developer-tools",
|
||||
"target": "dmg",
|
||||
|
@ -39,6 +39,7 @@
|
|||
"electron-builder": "^22.1.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"iofs": "^1.3.2"
|
||||
"iofs": "^1.5.2",
|
||||
"node-fetch": "^2.6.1"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
html{font-size:12.8px;width:100%;height:100vh}body{overflow:hidden;display:flex;flex-direction:column;width:100%;height:100%;line-height:1.25;font-size:14px;color:var(--color-dark-1);background:rgba(255,255,255,0.3)}.app-drag{-webkit-app-region:drag;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.app-nodrag{-webkit-app-region:no-drag}.app{position:relative;display:flex;height:100%}.app .sidebar{display:flex;flex-direction:column;justify-content:space-between;width:76px;height:100%;padding:48px 22px 24px;background:var(--color-dark-1);color:var(--color-plain-1)}.app .sidebar .item{cursor:pointer}.app .sidebar .item:hover,.app .sidebar .item.active{color:var(--color-orange-1)}.app .sidebar .item:active{color:var(--color-orange-2)}.app .select-box{display:flex;flex-direction:column;width:200px;height:100%;background:rgba(255,255,255,0.5)}.app .select-box .form{display:flex;align-items:center;width:100%;height:35px;padding:0 6px;background:#fff;border-bottom:1px solid var(--color-plain-2)}.app .select-box .form wc-input{flex:1}.app .select-box .list{flex:1}.app .select-box .list .item{display:flex;flex-direction:column;justify-content:center;height:48px;padding:6px;transition:color 0.15s ease-in-out, background 0.15s ease-in-out;cursor:pointer}.app .select-box .list .item section{display:flex;justify-content:space-between;align-items:center}.app .select-box .list .item cite{color:var(--color-grey-2)}.app .select-box .list .item .percent{padding:0 4px;border-radius:2px;font-size:12px;font-weight:bold;color:var(--color-grey-1)}.app .select-box .list .item .percent.red{color:var(--color-red-1)}.app .select-box .list .item .percent.green{color:var(--color-green-3)}.app .select-box .list .item:nth-child(odd){background:rgba(255,255,255,0.35)}.app .select-box .list .item:hover{color:var(--color-blue-1);background:rgba(255,255,255,0.35)}.app .select-box .list .item.active{color:var(--color-blue-3);background:rgba(255,255,255,0.7)}.app .detail{position:relative;flex:1;height:100%;border-left:1px solid var(--color-plain-2);background:#fff}.app .detail .title{display:flex;justify-content:space-between;align-items:center;width:100%;height:35px;padding:0 16px;font-size:16px;font-weight:bold}.app .detail .title span{display:inline-flex}.app .detail .title wc-button{margin:0 6px}.app .detail .card{width:96%;padding:12px 12px 16px;margin:12px 2% 24px;border:0;background:#fff;box-shadow:0 0 8px rgba(0,0,0,0.075)}.app .detail .card legend{-webkit-touch-callout:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;color:#64b5f6}.app .detail.blur::after{position:absolute;left:0;top:0;z-index:999;width:100%;height:100%;content:'';background:rgba(255,255,255,0.75);-webkit-backdrop-filter:blur(10px);backdrop-filter:blur(10px)}.app .preferences{width:640px;height:360px;border-radius:10px}.app .preferences .titlebar{width:100%;height:72px;border-bottom:1px solid var(--color-plain-3);background:var(--color-plain-1)}.app .preferences .titlebar .title{width:100%;height:24px;line-height:24px;text-align:center}.app .preferences .titlebar nav{display:flex;width:100%;height:40px;padding:0 16px;--size: 18px}.app .preferences .titlebar nav span{display:flex;flex-direction:column;align-items:center;justify-content:center;width:52px;height:40px;margin:0 6px;border-radius:6px;font-size:12px}.app .preferences .titlebar nav span.active{background:var(--color-plain-2);color:var(--color-blue-1)}.app .preferences .titlebar nav span:hover{background:var(--color-plain-2)}.app .preferences .tab-panel{padding:64px}.app .preferences .tab-panel p{margin-bottom:16px}.app .preferences .tab-panel .field{display:flex;align-items:center;height:64px}.app .preferences .tab-panel .field .label{width:200px;color:var(--color-grey-1)}
|
||||
html{font-size:12.8px;width:100%;height:100vh}body{overflow:hidden;display:flex;flex-direction:column;width:100%;height:100%;line-height:1.25;font-size:14px;color:var(--color-dark-1);background:rgba(255,255,255,0.3)}.app-drag{-webkit-app-region:drag;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.app-nodrag{-webkit-app-region:no-drag}.app{position:relative;display:flex;height:100%}.app .sidebar{display:flex;flex-direction:column;justify-content:space-between;width:76px;height:100%;padding:48px 22px 24px;background:var(--color-dark-1);color:var(--color-plain-1)}.app .sidebar .item{cursor:pointer}.app .sidebar .item:hover,.app .sidebar .item.active{color:var(--color-orange-1)}.app .sidebar .item:active{color:var(--color-orange-2)}.app .select-box{display:flex;flex-direction:column;width:200px;height:100%;background:rgba(255,255,255,0.5)}.app .select-box .form{display:flex;align-items:center;width:100%;height:35px;padding:0 6px;background:#fff;border-bottom:1px solid var(--color-plain-2)}.app .select-box .form wc-input{flex:1}.app .select-box .list{flex:1}.app .select-box .list .item{display:flex;flex-direction:column;justify-content:center;height:48px;padding:6px;border-bottom:1px solid rgba(200,200,200,0.3);transition:color 0.15s ease-in-out, background 0.15s ease-in-out;cursor:pointer}.app .select-box .list .item section{display:flex;justify-content:space-between;align-items:center}.app .select-box .list .item cite{color:var(--color-grey-2)}.app .select-box .list .item .percent{padding:0 4px;border-radius:2px;font-size:12px;font-weight:bold;color:var(--color-grey-1)}.app .select-box .list .item .percent.red{color:var(--color-red-1)}.app .select-box .list .item .percent.green{color:var(--color-green-3)}.app .select-box .list .item:last-child{border-bottom:0}.app .select-box .list .item:hover{color:var(--color-blue-1);background:rgba(255,255,255,0.7)}.app .select-box .list .item.active{color:var(--color-plain-1);background:var(--color-blue-1)}.app .select-box .list .item.active cite{color:inherit}.app .select-box .list .item.active .percent{color:#fff}.app .detail{position:relative;flex:1;height:100%;border-left:1px solid var(--color-plain-2);background:#fff}.app .detail .title{display:flex;justify-content:space-between;align-items:center;width:100%;height:35px;padding:0 16px;font-size:16px;font-weight:bold}.app .detail .title span{display:inline-flex}.app .detail .title wc-button{margin:0 6px}.app .detail .card{width:96%;padding:12px 12px 16px;margin:12px 2% 24px;border:0;background:#fff;box-shadow:0 0 8px rgba(0,0,0,0.075)}.app .detail .card legend{-webkit-touch-callout:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;color:#64b5f6}.app .detail.blur::after{display:flex;justify-content:center;align-items:center;position:absolute;left:0;top:0;z-index:999;width:100%;height:100%;content:'搞基数据';background:#fff;color:#f7f8fb;font-size:100px}.app .preferences{width:640px;height:360px;border-radius:10px}.app .preferences .titlebar{width:100%;height:72px;border-bottom:1px solid var(--color-plain-3);background:var(--color-plain-1)}.app .preferences .titlebar .title{width:100%;height:24px;line-height:24px;text-align:center}.app .preferences .titlebar nav{display:flex;width:100%;height:40px;padding:0 16px;--size: 18px}.app .preferences .titlebar nav span{display:flex;flex-direction:column;align-items:center;justify-content:center;width:52px;height:40px;margin:0 6px;border-radius:6px;font-size:12px}.app .preferences .titlebar nav span.active{background:var(--color-plain-2);color:var(--color-blue-1)}.app .preferences .titlebar nav span:hover{background:var(--color-plain-2)}.app .preferences .tab-panel{padding:64px}.app .preferences .tab-panel p{margin-bottom:16px}.app .preferences .tab-panel .field{display:flex;align-items:center;height:64px}.app .preferences .tab-panel .field .label{width:200px;color:var(--color-grey-1)}.app.loading::after{display:flex;justify-content:center;align-items:center;position:absolute;left:0;top:0;z-index:999;width:100%;height:100%;content:'🌑';background:rgba(255,255,255,0.01);-webkit-backdrop-filter:blur(2px);backdrop-filter:blur(2px);color:var(--color-orange-1);font-size:50px;-webkit-animation:loading 1s infinite;animation:loading 1s infinite}@-webkit-keyframes loading{1%,100%{content:'🌑'}12.5%{content:'🌒'}25%{content:'🌓'}37.5%{content:'🌔'}50%{content:'🌕'}62.5%{content:'🌖'}75%{content:'🌗'}87.5%{content:'🌘'}}@keyframes loading{1%,100%{content:'🌑'}12.5%{content:'🌒'}25%{content:'🌓'}37.5%{content:'🌔'}50%{content:'🌕'}62.5%{content:'🌖'}75%{content:'🌗'}87.5%{content:'🌘'}}
|
||||
|
|
|
@ -89,6 +89,7 @@ body {
|
|||
justify-content: center;
|
||||
height: 48px;
|
||||
padding: 6px;
|
||||
border-bottom: 1px solid rgba(200, 200, 200, 0.3);
|
||||
transition: color 0.15s ease-in-out, background 0.15s ease-in-out;
|
||||
cursor: pointer;
|
||||
|
||||
|
@ -117,18 +118,26 @@ body {
|
|||
}
|
||||
}
|
||||
|
||||
&:nth-child(odd) {
|
||||
background: rgba(255, 255, 255, 0.35);
|
||||
&:last-child {
|
||||
border-bottom: 0;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
color: var(--color-blue-1);
|
||||
background: rgba(255, 255, 255, 0.35);
|
||||
background: rgba(255, 255, 255, 0.7);
|
||||
}
|
||||
|
||||
&.active {
|
||||
color: var(--color-blue-3);
|
||||
background: rgba(255, 255, 255, 0.7);
|
||||
color: var(--color-plain-1);
|
||||
background: var(--color-blue-1);
|
||||
|
||||
cite {
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.percent {
|
||||
color: #fff;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -176,15 +185,19 @@ body {
|
|||
|
||||
&.blur {
|
||||
&::after {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
z-index: 999;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
content: '';
|
||||
background: rgba(255, 255, 255, 0.75);
|
||||
backdrop-filter: blur(10px);
|
||||
content: '搞基数据';
|
||||
background: #fff;
|
||||
color: #f7f8fb;
|
||||
font-size: 100px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -255,4 +268,52 @@ body {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
&.loading {
|
||||
&::after {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
z-index: 999;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
content: '🌑';
|
||||
background: rgba(255, 255, 255, 0.01);
|
||||
backdrop-filter: blur(2px);
|
||||
color: var(--color-orange-1);
|
||||
font-size: 50px;
|
||||
animation: loading 1s infinite;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes loading {
|
||||
1%,
|
||||
100% {
|
||||
content: '🌑';
|
||||
}
|
||||
12.5% {
|
||||
content: '🌒';
|
||||
}
|
||||
25% {
|
||||
content: '🌓';
|
||||
}
|
||||
37.5% {
|
||||
content: '🌔';
|
||||
}
|
||||
50% {
|
||||
content: '🌕';
|
||||
}
|
||||
62.5% {
|
||||
content: '🌖';
|
||||
}
|
||||
75% {
|
||||
content: '🌗';
|
||||
}
|
||||
87.5% {
|
||||
content: '🌘';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
</head>
|
||||
<body class="noselect">
|
||||
|
||||
<div class="app" anot="app">
|
||||
<div class="app" anot="app" :class="{loading: loading}">
|
||||
|
||||
<aside class="sidebar app-drag">
|
||||
<wc-icon class="app-nodrag item stat active" is="chart"></wc-icon>
|
||||
|
@ -63,7 +63,7 @@
|
|||
circle
|
||||
color="red"
|
||||
size="mini"
|
||||
@click="updateGay"
|
||||
@click="updateGays"
|
||||
icon="eye">
|
||||
</wc-button>
|
||||
</span>
|
||||
|
|
132
src/js/app.js
132
src/js/app.js
|
@ -28,6 +28,10 @@ function getJsonp(str) {
|
|||
}
|
||||
|
||||
function getLineStat(str) {
|
||||
str = str.replace(
|
||||
/.*var syl_1n(.*?)var Data_netWorthTrend([^;]*?);.*/,
|
||||
'var syl_1n$1var Data_netWorthTrend$2;'
|
||||
)
|
||||
return new Function(`${str}; return {line: Data_netWorthTrend.map(it => ({
|
||||
x: ~~(it.x/1000),
|
||||
y: +(it.y * 10000).toFixed(0),
|
||||
|
@ -35,6 +39,12 @@ function getLineStat(str) {
|
|||
})), e1: +syl_1y, e3: +syl_3y, e6: +syl_6y, e12: +syl_1n}`)()
|
||||
}
|
||||
|
||||
function sleep(ms) {
|
||||
return new Promise(_ => setTimeout(_, ms))
|
||||
}
|
||||
|
||||
window.app = app
|
||||
|
||||
Anot({
|
||||
$id: 'app',
|
||||
state: {
|
||||
|
@ -47,6 +57,7 @@ Anot({
|
|||
},
|
||||
list: [],
|
||||
$dict: {},
|
||||
loading: false,
|
||||
preferences: {
|
||||
tab: 1,
|
||||
notify: Anot.ls('notify') === '1'
|
||||
|
@ -63,28 +74,36 @@ Anot({
|
|||
},
|
||||
|
||||
mounted() {
|
||||
var gays = Anot.ls('gays') || '{}'
|
||||
var list = []
|
||||
var old = this.syncOldStat()
|
||||
|
||||
if (old === false) {
|
||||
gays = JSON.parse(gays)
|
||||
|
||||
for (let code in gays) {
|
||||
let { name, cm, cp, t } = gays[code]
|
||||
list.push({ code, name, cm, cp, t })
|
||||
this.$dict[code] = 1
|
||||
}
|
||||
list.sort((a, b) => b.cp - a.cp)
|
||||
|
||||
this.list = list
|
||||
this.reloadGays()
|
||||
}
|
||||
|
||||
if (this.preferences.notify) {
|
||||
app.dispatch('notify')
|
||||
}
|
||||
|
||||
app.on('data-reload', data => {
|
||||
this.reloadGays()
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
reloadGays() {
|
||||
var gays = Anot.ls('gays') || '{}'
|
||||
var list = []
|
||||
gays = JSON.parse(gays)
|
||||
|
||||
for (let code in gays) {
|
||||
let { name, cm, cp, t } = gays[code]
|
||||
list.push({ code, name, cm, cp, t: t || 0 })
|
||||
this.$dict[code] = 1
|
||||
}
|
||||
list.sort((a, b) => b.cp - a.cp)
|
||||
|
||||
this.list = list
|
||||
},
|
||||
|
||||
syncOldStat() {
|
||||
var old = Anot.ls('watch_list')
|
||||
var list = []
|
||||
|
@ -125,6 +144,7 @@ Anot({
|
|||
'fetch',
|
||||
`https://fundgz.1234567.com.cn/js/${id}.js`
|
||||
)
|
||||
|
||||
return getJsonp(res)
|
||||
},
|
||||
|
||||
|
@ -138,6 +158,11 @@ Anot({
|
|||
return
|
||||
}
|
||||
|
||||
if (code === 'debug') {
|
||||
this.input = ''
|
||||
return app.dispatch('devtools')
|
||||
}
|
||||
|
||||
if (code.length < 6) {
|
||||
return
|
||||
}
|
||||
|
@ -168,42 +193,54 @@ Anot({
|
|||
}
|
||||
},
|
||||
|
||||
updateGay() {
|
||||
async updateGays() {
|
||||
var { code, stat } = this.curr
|
||||
var info = this.getGayStat(code)
|
||||
|
||||
this.loading = true
|
||||
for (let it of this.list) {
|
||||
//
|
||||
let info = this.getGayStat(it.code)
|
||||
let time, needUpdate
|
||||
|
||||
if (!info) {
|
||||
console.log(it)
|
||||
continue
|
||||
}
|
||||
|
||||
it.cm = +info.gsz
|
||||
it.cp = +info.gszzl
|
||||
|
||||
time = new Date(info.gztime.slice(0, 10) + ' 00:00:00')
|
||||
time = ~~(time.getTime() / 1000) - 24 * 3600
|
||||
|
||||
// 如果走势最后的日期比当前最新的小, 则全量更新
|
||||
if (it.t < time) {
|
||||
it.t = time
|
||||
needUpdate = this.updateLine(it.code)
|
||||
}
|
||||
|
||||
if (it.code === code) {
|
||||
let d
|
||||
|
||||
it.cm = +info.gsz
|
||||
it.cp = +info.gszzl
|
||||
|
||||
this.list.sort((a, b) => b.cp - a.cp)
|
||||
|
||||
d = new Date(info.gztime.slice(0, 10) + ' 00:00:00')
|
||||
d = ~~(d.getTime() / 1000) - 24 * 3600
|
||||
|
||||
// 如果走势最后的日期比当前最新的小, 则全量更新
|
||||
if (it.t < d) {
|
||||
Anot.ls(code, null)
|
||||
this.viewGay(it)
|
||||
console.log('update all stat...')
|
||||
return
|
||||
}
|
||||
|
||||
stat = JSON.parse(stat)
|
||||
stat.cm = it.cm
|
||||
stat.cp = it.cp
|
||||
if (needUpdate) {
|
||||
stat.rank = needUpdate.line.slice(-60).map(_ => _.p)
|
||||
stat.e1 = needUpdate.e1
|
||||
stat.e3 = needUpdate.e3
|
||||
stat.e6 = needUpdate.e6
|
||||
stat.e12 = needUpdate.e12
|
||||
this.curr.line = JSON.stringify(needUpdate.line)
|
||||
}
|
||||
this.curr.stat = JSON.stringify(stat)
|
||||
|
||||
this.saveCache()
|
||||
layer.toast('数据更新成功', 'success')
|
||||
Anot.ss('last_update', Date.now())
|
||||
|
||||
return
|
||||
}
|
||||
await sleep(500)
|
||||
}
|
||||
//
|
||||
this.loading = false
|
||||
Anot.ss('last_update', Date.now())
|
||||
layer.toast('数据更新成功', 'success')
|
||||
this.list.sort((a, b) => b.cp - a.cp)
|
||||
this.saveCache()
|
||||
},
|
||||
|
||||
removeGay() {
|
||||
|
@ -234,6 +271,16 @@ Anot({
|
|||
Anot.ls('gays', dict)
|
||||
},
|
||||
|
||||
updateLine(code) {
|
||||
var gay = app.dispatch(
|
||||
'fetch',
|
||||
`http://fund.eastmoney.com/pingzhongdata/${code}.js?v=${Date.now()}`
|
||||
)
|
||||
gay = getLineStat(gay)
|
||||
Anot.ls(code, JSON.stringify(gay))
|
||||
return gay
|
||||
},
|
||||
|
||||
viewGay(item) {
|
||||
var gay = Anot.ls(item.code)
|
||||
var rank, line
|
||||
|
@ -251,16 +298,9 @@ Anot({
|
|||
}
|
||||
|
||||
if (!gay) {
|
||||
gay = app.dispatch(
|
||||
'fetch',
|
||||
`http://fund.eastmoney.com/pingzhongdata/${
|
||||
item.code
|
||||
}.js?v=${Date.now()}`
|
||||
)
|
||||
gay = getLineStat(gay)
|
||||
gay = this.updateLine(item.code)
|
||||
item.t = gay.line[gay.line.length - 1].x
|
||||
this.saveCache()
|
||||
Anot.ls(item.code, JSON.stringify(gay))
|
||||
}
|
||||
|
||||
rank = gay.line.slice(-60).map(_ => _.p)
|
||||
|
|
|
@ -29,13 +29,19 @@ Anot({
|
|||
var time = +Anot.ss('last_update') || 0
|
||||
var now = Date.now()
|
||||
|
||||
// 如果离上次更新超过15分钟, 则自动更新
|
||||
if (now - time > 15 * 60 * 1000) {
|
||||
this.updateGays()
|
||||
Anot.ss('last_update', now)
|
||||
} else {
|
||||
this.reloadGays()
|
||||
// 有触发小窗口显示时, 更新通知提醒
|
||||
if (Anot.ls('notify') === '1') {
|
||||
app.dispatch('notify')
|
||||
}
|
||||
|
||||
this.reloadGays()
|
||||
setTimeout(() => {
|
||||
// 如果离上次更新超过15分钟, 则自动更新
|
||||
if (now - time > 15 * 60 * 1000) {
|
||||
this.updateGays()
|
||||
Anot.ss('last_update', now)
|
||||
}
|
||||
}, 500)
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
|
@ -74,6 +80,7 @@ Anot({
|
|||
}
|
||||
this.list.sort((a, b) => b.cp - a.cp)
|
||||
this.saveCache()
|
||||
app.dispatch('data-reload')
|
||||
},
|
||||
saveCache() {
|
||||
var dict = {}
|
||||
|
|
90
src/main.js
90
src/main.js
|
@ -14,8 +14,11 @@ const {
|
|||
} = require('electron')
|
||||
const path = require('path')
|
||||
const fs = require('iofs')
|
||||
const fetch = require('node-fetch')
|
||||
|
||||
const { createMainWindow, createFloatWindow } = require('./tools/window')
|
||||
const createMenu = require('./tools/menu')
|
||||
const createTay = require('./tools/tray')
|
||||
|
||||
const MIME_TYPES = {
|
||||
'.js': 'text/javascript',
|
||||
|
@ -33,29 +36,6 @@ const ROOT = __dirname
|
|||
|
||||
var timer
|
||||
|
||||
function fetch(url) {
|
||||
return new Promise((y, n) => {
|
||||
var conn = net.request(url)
|
||||
var r = []
|
||||
|
||||
conn.on('response', res => {
|
||||
res.on('data', c => {
|
||||
r.push(c)
|
||||
})
|
||||
|
||||
res.on('end', _ => {
|
||||
y(Buffer.concat(r).toString())
|
||||
})
|
||||
})
|
||||
|
||||
conn.on('error', e => {
|
||||
n(e)
|
||||
})
|
||||
|
||||
conn.end()
|
||||
})
|
||||
}
|
||||
|
||||
function ring() {
|
||||
var n = 5
|
||||
var t = setInterval(() => {
|
||||
|
@ -82,7 +62,7 @@ protocol.registerSchemesAsPrivileged([
|
|||
|
||||
/* ----------------------------------------------------- */
|
||||
|
||||
// app.dock.hide()
|
||||
app.dock.hide()
|
||||
|
||||
// 初始化应用
|
||||
app.once('ready', () => {
|
||||
|
@ -98,6 +78,9 @@ app.once('ready', () => {
|
|||
app.__main__ = createMainWindow(path.resolve(ROOT, './images/app.png'))
|
||||
app.__float__ = createFloatWindow()
|
||||
|
||||
createMenu(app.__main__)
|
||||
createTay(app.__float__, app.__main__)
|
||||
|
||||
app.__main__.on('closed', () => {
|
||||
app.__main__ = null
|
||||
app.__float__ = null
|
||||
|
@ -105,30 +88,49 @@ app.once('ready', () => {
|
|||
})
|
||||
|
||||
// mac专属事件,点击dock栏图标,可激活窗口
|
||||
app.on('activate', _ => {
|
||||
if (app.__main__) {
|
||||
app.__main__.restore()
|
||||
}
|
||||
})
|
||||
// app.on('activate', _ => {
|
||||
// if (app.__main__) {
|
||||
// app.__main__.restore()
|
||||
// }
|
||||
// })
|
||||
})
|
||||
|
||||
ipcMain.on('app', (ev, conn) => {
|
||||
if (conn.type === 'fetch') {
|
||||
fetch(conn.data).then(r => {
|
||||
ev.returnValue = r
|
||||
})
|
||||
} else if (conn.type === 'notify') {
|
||||
clearTimeout(timer)
|
||||
var t1 = Date.now()
|
||||
var t2 = new Date()
|
||||
t2.setHours(14)
|
||||
t2.setMinutes(0)
|
||||
t2.setSeconds(0)
|
||||
switch (conn.type) {
|
||||
case 'fetch':
|
||||
fetch(conn.data, {
|
||||
headers: {
|
||||
'user-agent':
|
||||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36'
|
||||
}
|
||||
})
|
||||
.then(r => r.text())
|
||||
.then(r => (ev.returnValue = r))
|
||||
break
|
||||
|
||||
if (t2.getTime() - t1 > 0) {
|
||||
timer = setTimeout(ring, t2.getTime() - t1)
|
||||
}
|
||||
case 'notify':
|
||||
clearTimeout(timer)
|
||||
var t1 = Date.now()
|
||||
var t2 = new Date()
|
||||
t2.setHours(14)
|
||||
t2.setMinutes(30)
|
||||
t2.setSeconds(0)
|
||||
|
||||
ev.returnValue = true
|
||||
if (t2.getTime() - t1 > 0) {
|
||||
timer = setTimeout(ring, t2.getTime() - t1)
|
||||
}
|
||||
|
||||
ev.returnValue = true
|
||||
break
|
||||
|
||||
case 'data-reload':
|
||||
app.__main__.webContents.send('app', { type: 'data-reload', data: null })
|
||||
ev.returnValue = true
|
||||
break
|
||||
|
||||
case 'devtools':
|
||||
app.__main__.openDevTools()
|
||||
ev.returnValue = true
|
||||
break
|
||||
}
|
||||
})
|
||||
|
|
|
@ -4,18 +4,39 @@
|
|||
* @date 2020/12/10 19:30:20
|
||||
*/
|
||||
|
||||
const { Tray } = require('electron')
|
||||
const { Tray, Menu } = require('electron')
|
||||
const path = require('path')
|
||||
const ROOT = __dirname
|
||||
|
||||
module.exports = function(win) {
|
||||
win.__TRAY__ = new Tray(path.join(ROOT, '../images/tray.png'))
|
||||
module.exports = function(mini, main) {
|
||||
var menuList = Menu.buildFromTemplate([
|
||||
{
|
||||
label: '显示主窗口',
|
||||
click(a, b, ev) {
|
||||
main.restore()
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '不搞基了',
|
||||
accelerator: 'Command+Q',
|
||||
click(a, b, ev) {
|
||||
main.destroy()
|
||||
}
|
||||
}
|
||||
])
|
||||
var tray = new Tray(path.join(ROOT, '../images/tray.png'))
|
||||
|
||||
win.__TRAY__.on('click', _ => {
|
||||
var b = win.__TRAY__.getBounds()
|
||||
win.setBounds({ x: b.x - 120, y: b.y + b.height })
|
||||
win.show()
|
||||
win.focus()
|
||||
win.webContents.send('app', { type: 'float-visible', data: null })
|
||||
tray.on('click', _ => {
|
||||
var b = tray.getBounds()
|
||||
mini.setBounds({ x: b.x - 120, y: b.y + b.height })
|
||||
mini.show()
|
||||
mini.focus()
|
||||
mini.webContents.send('app', { type: 'float-visible', data: null })
|
||||
})
|
||||
|
||||
tray.on('right-click', _ => {
|
||||
tray.popUpContextMenu(menuList)
|
||||
})
|
||||
|
||||
main.__tray__ = tray
|
||||
}
|
||||
|
|
|
@ -6,9 +6,6 @@
|
|||
|
||||
const { BrowserWindow } = require('electron')
|
||||
|
||||
const createMenu = require('./menu')
|
||||
const createTay = require('./tray')
|
||||
|
||||
/**
|
||||
* 应用主窗口
|
||||
*/
|
||||
|
@ -36,12 +33,10 @@ exports.createMainWindow = function(icon) {
|
|||
|
||||
win.loadURL('app://local/index.html')
|
||||
|
||||
createMenu(win)
|
||||
|
||||
win.on('ready-to-show', _ => {
|
||||
win.show()
|
||||
// win.openDevTools()
|
||||
})
|
||||
// win.on('ready-to-show', _ => {
|
||||
// win.show()
|
||||
// win.openDevTools()
|
||||
// })
|
||||
|
||||
win.on('close', ev => {
|
||||
ev.preventDefault()
|
||||
|
@ -75,7 +70,6 @@ exports.createFloatWindow = function() {
|
|||
win.hide()
|
||||
})
|
||||
|
||||
createTay(win)
|
||||
win.loadURL('app://local/float.html')
|
||||
|
||||
return win
|
||||
|
|
Loading…
Reference in New Issue