master
宇天 2021-01-04 18:54:53 +08:00
parent 5673d107e7
commit 267f395476
9 changed files with 149 additions and 670 deletions

View File

@ -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;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:'🌘'}} 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 .category{width:200px;height:100%;background:#fff}.app .category .item{display:flex;justify-content:space-between;align-items:center;height:54px;padding:8px;border-bottom:1px solid var(--color-plain-1);background:#fff;transition:background 0.2s ease-in-out, color 0.2s ease-in-out;cursor:pointer}.app .category .item strong{max-width:150px}.app .category .item .num{display:flex;justify-content:center;align-items:center;min-width:16px;height:16px;padding:2px;line-height:1;border-radius:50%;font-size:12px;background:var(--color-grey-1);color:#fff}.app .category .item:last-child{border-bottom:0}.app .category .item:hover{color:var(--color-blue-1);background:var(--color-plain-1)}.app .category .item.active{color:var(--color-plain-1);background:var(--color-blue-1)}.app .category .item.active .num{background:#fff;color:var(--color-blue-1)}.app .detail{position:relative;flex:1;height:100%;border-left:1px solid var(--color-plain-2);background:rgba(255,255,255,0.5)}.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.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}.app .drag-mask{display:flex;align-items:center;position:fixed;left:0;top:0;z-index:9999;width:100%;height:100%;background:linear-gradient(to right, transparent, transparent 200px, #fff3e3 200px)}.app .drag-mask::after{font-size:46px;text-indent:300px;content:'Drop epub file here...';color:var(--color-grey-1)}@-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:'🌘'}}

View File

@ -36,108 +36,55 @@ body {
display: flex; display: flex;
height: 100%; height: 100%;
.sidebar { .category {
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);
.item {
cursor: pointer;
&:hover,
&.active {
color: var(--color-orange-1);
}
&:active {
color: var(--color-orange-2);
}
}
}
.select-box {
display: flex;
flex-direction: column;
width: 200px; width: 200px;
height: 100%; height: 100%;
background: rgba(255, 255, 255, 0.5); background: #fff;
.form { .item {
display: flex; display: flex;
justify-content: space-between;
align-items: center; align-items: center;
width: 100%; height: 54px;
height: 35px; padding: 8px;
padding: 0 6px; border-bottom: 1px solid var(--color-plain-1);
background: #fff; background: #fff;
border-bottom: 1px solid var(--color-plain-2); transition: background 0.2s ease-in-out, color 0.2s ease-in-out;
cursor: pointer;
wc-input { strong {
flex: 1; max-width: 150px;
} }
} .num {
.list {
flex: 1;
.item {
display: flex; display: flex;
flex-direction: column;
justify-content: center; justify-content: center;
height: 48px; align-items: center;
padding: 6px; min-width: 16px;
border-bottom: 1px solid rgba(200, 200, 200, 0.3); height: 16px;
transition: color 0.15s ease-in-out, background 0.15s ease-in-out; padding: 2px;
cursor: pointer; line-height: 1;
border-radius: 50%;
font-size: 12px;
background: var(--color-grey-1);
color: #fff;
}
section { &:last-child {
display: flex; border-bottom: 0;
justify-content: space-between; }
align-items: center;
}
cite { &:hover {
color: var(--color-grey-2); color: var(--color-blue-1);
} background: var(--color-plain-1);
}
.percent { &.active {
padding: 0 4px; color: var(--color-plain-1);
border-radius: 2px; background: var(--color-blue-1);
font-size: 12px;
font-weight: bold;
color: var(--color-grey-1);
&.red { .num {
color: var(--color-red-1); background: #fff;
}
&.green {
color: var(--color-green-3);
}
}
&:last-child {
border-bottom: 0;
}
&:hover {
color: var(--color-blue-1); color: var(--color-blue-1);
background: rgba(255, 255, 255, 0.7);
}
&.active {
color: var(--color-plain-1);
background: var(--color-blue-1);
cite {
color: inherit;
}
.percent {
color: #fff;
}
} }
} }
} }
@ -148,7 +95,7 @@ body {
flex: 1; flex: 1;
height: 100%; height: 100%;
border-left: 1px solid var(--color-plain-2); border-left: 1px solid var(--color-plain-2);
background: #fff; background: rgba(255, 255, 255, 0.5);
.title { .title {
display: flex; display: flex;
@ -182,91 +129,6 @@ body {
color: #64b5f6; color: #64b5f6;
} }
} }
&.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;
}
}
}
.preferences {
width: 640px;
height: 360px;
border-radius: 10px;
.titlebar {
width: 100%;
height: 72px;
border-bottom: 1px solid var(--color-plain-3);
background: var(--color-plain-1);
.title {
width: 100%;
height: 24px;
line-height: 24px;
text-align: center;
}
nav {
display: flex;
width: 100%;
height: 40px;
padding: 0 16px;
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;
&.active {
background: var(--color-plain-2);
color: var(--color-blue-1);
}
&:hover {
background: var(--color-plain-2);
}
}
--size: 18px;
}
}
.tab-panel {
padding: 64px;
p {
margin-bottom: 16px;
}
.field {
display: flex;
align-items: center;
height: 64px;
.label {
width: 200px;
color: var(--color-grey-1);
}
}
}
} }
&.loading { &.loading {
@ -288,6 +150,30 @@ body {
animation: loading 1s infinite; animation: loading 1s infinite;
} }
} }
.drag-mask {
display: flex;
align-items: center;
position: fixed;
left: 0;
top: 0;
z-index: 9999;
width: 100%;
height: 100%;
background: linear-gradient(
to right,
transparent,
transparent 200px,
#fff3e3 200px
);
&::after {
font-size: 46px;
text-indent: 300px;
content: 'Drop epub file here...';
color: var(--color-grey-1);
}
}
} }
@keyframes loading { @keyframes loading {

View File

@ -13,105 +13,27 @@
<div class="app" anot="app" :class="{loading: loading}"> <div class="app" anot="app" :class="{loading: loading}">
<aside class="sidebar app-drag"> <wc-scroll class="category">
<wc-icon class="app-nodrag item stat active" is="chart"></wc-icon> <item
<wc-icon class="app-nodrag item opt" is="menu-dot" @click="showPreferencesPanel"></wc-icon> class="item"
</aside> :class="{active: curr === it.id}"
:for="it in list">
<strong :text="it.name"></strong>
<span class="num" :text="it.num"></span>
</item>
</wc-scroll>
<div class="select-box">
<section class="form">
<wc-input
maxlength="6"
placeholder="输入编号搞新基"
round
@submit="addGay"
:duplex="input"
size="mini">
</wc-input>
</section>
<wc-scroll class="list">
<item
class="item"
:class="{active: curr.code === it.code}"
@click="viewGay(it)"
:for="it in list">
<strong class="text-ell" :text="it.name"></strong>
<section>
<cite :text="it.code"></cite>
<span
class="percent"
:class="{red: it.cp > 0, green: it.cp < 0}"
:text="it.cp + '%'">
</span>
</section>
</item>
</wc-scroll>
</div>
<div class="detail" :class="{blur: !curr.code}"> <div class="detail" :class="{blur: !curr.code}">
<section class="title app-drag">
<span>[{{curr.code}}] {{curr.name}}</span>
<span>
<wc-button
circle
size="mini"
@click="removeGay"
icon="trash">
</wc-button>
<wc-button
circle
color="red"
size="mini"
@click="updateGays"
icon="eye">
</wc-button>
</span>
</section>
<fieldset class="card">
<legend>实时数据</legend>
<wc-rank :attr-stat="curr.stat"></wc-rank>
</fieldset>
<fieldset class="card">
<legend>单位净值走势</legend>
<wc-line :attr-list="curr.line"></wc-line>
</fieldset>
</div> </div>
<wc-layer ref="pre" mask mask-close radius="10px" >
<div class="preferences">
<div class="titlebar">
<div class="title">hello</div>
<nav>
<span :class="{active: preferences.tab === 1}" @click="switchTab(1)">
<wc-icon is="setting"></wc-icon>
常规
</span>
<span :class="{active: preferences.tab === 2}" @click="switchTab(2)">
<wc-icon is="info"></wc-icon>
关于
</span>
</nav>
</div>
<div class="tab-panel" :visible="preferences.tab === 1"> <div class="drag-mask" ref="mask" :visible="isDragIn"></div>
<section class="field">
<span class="label">神奇的2点半提醒</span>
<wc-switch :duplex="preferences.notify"></wc-switch>
</section>
</div>
<div class="tab-panel" :visible="preferences.tab === 2">
<p>“搞基爱啪啪” 是一款开源的, 非专业的搞基软件, 上面的数据全来自网络, 不对准确性作任何保证. </p>
<p>搞基有风险, 入行需谨慎. 你亏了别找我, 赚了可以给我发红包.</p>
</div>
</div>
</wc-layer>
</div> </div>

View File

@ -18,294 +18,49 @@ import Utils from '/lib/utils.js'
import app from '/lib/socket.js' import app from '/lib/socket.js'
const $doc = Anot(document)
const log = console.log const log = console.log
function getJsonp(str) {
if (~str.indexOf('jsonpgz')) {
return new Function(`function jsonpgz(d){return d}; return ${str}`)()
}
return false
}
function getLineStat(str) {
return new Function(`${str}; return {line: Data_netWorthTrend.map(it => ({
x: ~~(it.x/1000),
y: +(it.y * 10000).toFixed(0),
p: it.equityReturn
})), e1: +syl_1y, e3: +syl_3y, e6: +syl_6y, e12: +syl_1n}`)()
}
function sleep(ms) { function sleep(ms) {
return new Promise(_ => setTimeout(_, ms)) return new Promise(_ => setTimeout(_, ms))
} }
window.app = app
Anot({ Anot({
$id: 'app', $id: 'app',
state: { state: {
input: '', input: '',
curr: { curr: 1,
code: '', list: [{ id: 1, name: '默认分类', num: 12 }],
name: '',
stat: '',
line: ''
},
list: [],
$dict: {}, $dict: {},
loading: false, loading: false,
isDragIn: false,
preferences: { preferences: {
tab: 1, tab: 1,
notify: Anot.ls('notify') === '1' notify: Anot.ls('notify') === '1'
} }
}, },
watch: { watch: {},
'preferences.notify'(v) {
Anot.ls('notify', v ^ 0)
if (v) {
app.dispatch('notify')
}
}
},
mounted() { mounted() {
var old = this.syncOldStat() $doc.bind('dragover', ev => {
ev.stopPropagation()
ev.preventDefault()
if (old === false) { this.isDragIn = true
this.reloadGays() })
} Anot(this.$refs.mask).bind('dragleave', ev => {
ev.stopPropagation()
ev.preventDefault()
this.isDragIn = false
})
if (this.preferences.notify) { $doc.bind('drop', ev => {
app.dispatch('notify') ev.stopPropagation()
} ev.preventDefault()
// clearTimeout(this.timer)
app.on('data-reload', data => { this.isDragIn = false
this.reloadGays()
}) })
}, },
methods: { 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 = []
var dict = {}
if (old) {
old = JSON.parse(old)
for (let it of old) {
dict[it.code] = {
name: it.name,
cm: +it.curr,
cp: it.percent,
t: Date.now()
}
list.push({ code: it.code, ...dict[it.code] })
}
list.sort((a, b) => b.cp - a.cp)
this.list = list
Anot.ls('gays', dict)
Anot.ls('watch_list', null)
return true
}
return false
},
showPreferencesPanel() {
this.$refs.pre.show()
},
switchTab(n) {
this.preferences.tab = n
},
getGayStat(id) {
var res = app.dispatch(
'fetch',
`https://fundgz.1234567.com.cn/js/${id}.js`
)
return getJsonp(res)
},
addGay() {
var code = this.input
var gay
if (this.$dict[code]) {
layer.toast('这个鸡精在列表呢~~~', 'warn')
this.input = ''
return
}
if (code === 'debug') {
this.input = ''
return app.dispatch('devtools')
}
if (code.length < 6) {
return
}
if (/[^\d]/.test(code)) {
layer.toast('只能通过鸡精编号添加', 'error')
this.input = ''
return
}
gay = this.getGayStat(code)
if (gay) {
let tmp = {
code: gay.fundcode,
name: gay.name,
cm: +gay.gsz,
cp: +gay.gszzl,
t: Date.now()
}
this.input = ''
this.list.push(tmp)
this.$dict[tmp.code] = 1
this.list.sort((a, b) => b.cp - a.cp)
this.saveCache()
} else {
layer.toast('鸡精不存在', 'error')
}
},
async updateGays() {
var { code, stat } = this.curr
this.loading = true
for (let it of this.list) {
//
let info = this.getGayStat(it.code)
let time, needUpdate
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) {
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)
}
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() {
var { code, name } = this.curr
layer
.confirm(`是否移除「${name}」?`)
.then(_ => {
for (let it of this.list) {
if (it.code === code) {
this.list.remove(it)
delete this.$dict[code]
Anot.ls(code, null)
this.saveCache()
break
}
}
this.viewGay(this.list[0])
})
.catch(Anot.noop)
},
saveCache() {
var dict = {}
for (let it of this.list) {
var { code, name, cm, cp, t } = it
dict[code] = { name, cm, cp, t }
}
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
var { cm, cp, t } = item
this.curr.code = item.code
this.curr.name = item.name
if (gay) {
gay = JSON.parse(gay)
var last = gay.line[gay.line.length - 1].x
if (last < t) {
gay = null
}
}
if (!gay) {
gay = this.updateLine(item.code)
item.t = gay.line[gay.line.length - 1].x
this.saveCache()
}
rank = gay.line.slice(-60).map(_ => _.p)
line = JSON.stringify(gay.line)
this.curr.stat = JSON.stringify({
rank,
e1: gay.e1,
e3: gay.e3,
e6: gay.e6,
e12: gay.e12,
cm,
cp
})
this.curr.line = line
}
}
}) })

View File

@ -4,20 +4,13 @@
* @date 2019/09/16 20:51:19 * @date 2019/09/16 20:51:19
*/ */
const { const { app, BrowserWindow, protocol, ipcMain } = require('electron')
app,
BrowserWindow,
protocol,
ipcMain,
net,
Notification
} = require('electron')
const path = require('path') const path = require('path')
const fs = require('iofs') const fs = require('iofs')
const { createMainWindow, createFloatWindow } = require('./tools/window') const { createMainWindow, createFloatWindow } = require('./tools/window')
const createMenu = require('./tools/menu') const createMenu = require('./tools/menu')
const createTay = require('./tools/tray') const Socket = require('./tools/socket')
const MIME_TYPES = { const MIME_TYPES = {
'.js': 'text/javascript', '.js': 'text/javascript',
@ -35,45 +28,6 @@ const ROOT = __dirname
var timer 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(() => {
var notify = new Notification({
title: '搞基⏰',
subtitle: '神奇的2点半到啦',
body: '神奇的2点半到啦, 该加仓的加仓, 该卖的卖啦'
})
notify.show()
n--
if (n === 0) {
clearInterval(t)
}
}, 1000)
}
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
app.commandLine.appendSwitch('--lang', 'zh-CN') app.commandLine.appendSwitch('--lang', 'zh-CN')
app.commandLine.appendSwitch('--autoplay-policy', 'no-user-gesture-required') app.commandLine.appendSwitch('--autoplay-policy', 'no-user-gesture-required')
@ -101,7 +55,7 @@ app.once('ready', () => {
app.__float__ = createFloatWindow() app.__float__ = createFloatWindow()
createMenu(app.__main__) createMenu(app.__main__)
createTay(app.__float__, app.__main__) Socket(app)
app.__main__.on('closed', () => { app.__main__.on('closed', () => {
app.__main__ = null app.__main__ = null
@ -116,38 +70,3 @@ app.once('ready', () => {
// } // }
// }) // })
}) })
ipcMain.on('app', (ev, conn) => {
switch (conn.type) {
case 'fetch':
fetch(conn.data).then(r => {
ev.returnValue = r
})
break
case 'notify':
clearTimeout(timer)
var t1 = Date.now()
var t2 = new Date()
t2.setHours(14)
t2.setMinutes(30)
t2.setSeconds(0)
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
}
})

View File

@ -9,9 +9,9 @@ const { Menu } = require('electron')
module.exports = function(win) { module.exports = function(win) {
var menuList = Menu.buildFromTemplate([ var menuList = Menu.buildFromTemplate([
{ {
label: '搞基数据', label: 'E-pub Reader',
submenu: [ submenu: [
{ role: 'about', label: '关于搞基数据' }, { role: 'about', label: '关于E-pub Reader' },
{ type: 'separator' }, { type: 'separator' },
{ {
label: '退出', label: '退出',

45
src/tools/socket.js Normal file
View File

@ -0,0 +1,45 @@
/**
* 进程通讯交互
* @author yutent<yutent.io@gmail.com>
* @date 2021/01/04 14:58:46
*/
const { ipcMain, net } = require('electron')
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()
})
}
module.exports = function(app) {
ipcMain.on('app', (ev, conn) => {
switch (conn.type) {
case 'fetch':
fetch(conn.data).then(r => {
ev.returnValue = r
})
break
case 'parse-book':
break
}
})
}

View File

@ -1,42 +0,0 @@
/**
* 托盘
* @author yutent<yutent.io@gmail.com>
* @date 2020/12/10 19:30:20
*/
const { Tray, Menu } = require('electron')
const path = require('path')
const ROOT = __dirname
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'))
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
}

View File

@ -11,19 +11,13 @@ const { BrowserWindow } = require('electron')
*/ */
exports.createMainWindow = function(icon) { exports.createMainWindow = function(icon) {
var win = new BrowserWindow({ var win = new BrowserWindow({
title: '搞基数据', title: 'E-pub Reader',
width: 1024, width: 960,
height: 540, height: 540,
frame: false,
titleBarStyle: 'hiddenInset',
resizable: false, resizable: false,
maximizable: false, maximizable: false,
icon, icon,
transparent: true,
vibrancy: 'hud',
visualEffectState: 'active',
webPreferences: { webPreferences: {
// webSecurity: false,
experimentalFeatures: true, experimentalFeatures: true,
nodeIntegration: true, nodeIntegration: true,
spellcheck: false spellcheck: false
@ -33,10 +27,10 @@ exports.createMainWindow = function(icon) {
win.loadURL('app://local/index.html') win.loadURL('app://local/index.html')
// win.on('ready-to-show', _ => { win.on('ready-to-show', _ => {
// win.show() win.show()
// win.openDevTools() win.openDevTools()
// }) })
win.on('close', ev => { win.on('close', ev => {
ev.preventDefault() ev.preventDefault()