diff --git a/src/css/app.css b/src/css/app.css index 4811d2a..63c1f66 100644 --- a/src/css/app.css +++ b/src/css/app.css @@ -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:'๐ŸŒ˜'}} diff --git a/src/css/app.scss b/src/css/app.scss index 4b3039e..97d434e 100644 --- a/src/css/app.scss +++ b/src/css/app.scss @@ -36,108 +36,55 @@ body { display: flex; height: 100%; - .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); - - .item { - cursor: pointer; - - &:hover, - &.active { - color: var(--color-orange-1); - } - &:active { - color: var(--color-orange-2); - } - } - } - - .select-box { - display: flex; - flex-direction: column; + .category { width: 200px; height: 100%; - background: rgba(255, 255, 255, 0.5); + background: #fff; - .form { + .item { display: flex; + justify-content: space-between; align-items: center; - width: 100%; - height: 35px; - padding: 0 6px; + height: 54px; + padding: 8px; + border-bottom: 1px solid var(--color-plain-1); 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 { - flex: 1; + strong { + max-width: 150px; } - } - - .list { - flex: 1; - - .item { + .num { 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; + 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; + } - section { - display: flex; - justify-content: space-between; - align-items: center; - } + &:last-child { + border-bottom: 0; + } - cite { - color: var(--color-grey-2); - } + &:hover { + color: var(--color-blue-1); + background: var(--color-plain-1); + } - .percent { - padding: 0 4px; - border-radius: 2px; - font-size: 12px; - font-weight: bold; - color: var(--color-grey-1); + &.active { + color: var(--color-plain-1); + background: var(--color-blue-1); - &.red { - color: var(--color-red-1); - } - &.green { - color: var(--color-green-3); - } - } - - &:last-child { - border-bottom: 0; - } - - &:hover { + .num { + background: #fff; 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; height: 100%; border-left: 1px solid var(--color-plain-2); - background: #fff; + background: rgba(255, 255, 255, 0.5); .title { display: flex; @@ -182,91 +129,6 @@ body { 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 { @@ -288,6 +150,30 @@ body { 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 { diff --git a/src/index.html b/src/index.html index e387237..3391aa5 100644 --- a/src/index.html +++ b/src/index.html @@ -13,105 +13,27 @@
- - -
-
- - -
- - - -
- - - -
-
-
-
+ + + + + + +
-
- [{{curr.code}}] {{curr.name}} - - - - - - -
-
- ๅฎžๆ—ถๆ•ฐๆฎ - -
-
- ๅ•ไฝๅ‡€ๅ€ผ่ตฐๅŠฟ - -
+
- -
-
-
hello
- -
-
-
- ็ฅžๅฅ‡็š„2็‚นๅŠๆ้†’ - -
-
- -
-

โ€œๆžๅŸบ็ˆฑๅ•ชๅ•ชโ€ ๆ˜ฏไธ€ๆฌพๅผ€ๆบ็š„, ้žไธ“ไธš็š„ๆžๅŸบ่ฝฏไปถ, ไธŠ้ข็š„ๆ•ฐๆฎๅ…จๆฅ่‡ช็ฝ‘็ปœ, ไธๅฏนๅ‡†็กฎๆ€งไฝœไปปไฝ•ไฟ่ฏ.

-

ๆžๅŸบๆœ‰้ฃŽ้™ฉ, ๅ…ฅ่กŒ้œ€่ฐจๆ…Ž. ไฝ ไบไบ†ๅˆซๆ‰พๆˆ‘, ่ตšไบ†ๅฏไปฅ็ป™ๆˆ‘ๅ‘็บขๅŒ….

- -
- -
-
+
diff --git a/src/js/app.js b/src/js/app.js index 9eff464..d571c02 100644 --- a/src/js/app.js +++ b/src/js/app.js @@ -18,294 +18,49 @@ import Utils from '/lib/utils.js' import app from '/lib/socket.js' +const $doc = Anot(document) 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) { return new Promise(_ => setTimeout(_, ms)) } -window.app = app - Anot({ $id: 'app', state: { input: '', - curr: { - code: '', - name: '', - stat: '', - line: '' - }, - list: [], + curr: 1, + list: [{ id: 1, name: '้ป˜่ฎคๅˆ†็ฑป', num: 12 }], $dict: {}, loading: false, + isDragIn: false, preferences: { tab: 1, notify: Anot.ls('notify') === '1' } }, - watch: { - 'preferences.notify'(v) { - Anot.ls('notify', v ^ 0) - if (v) { - app.dispatch('notify') - } - } - }, + watch: {}, mounted() { - var old = this.syncOldStat() + $doc.bind('dragover', ev => { + ev.stopPropagation() + ev.preventDefault() - if (old === false) { - this.reloadGays() - } + this.isDragIn = true + }) + Anot(this.$refs.mask).bind('dragleave', ev => { + ev.stopPropagation() + ev.preventDefault() + this.isDragIn = false + }) - if (this.preferences.notify) { - app.dispatch('notify') - } - - app.on('data-reload', data => { - this.reloadGays() + $doc.bind('drop', ev => { + ev.stopPropagation() + ev.preventDefault() + // clearTimeout(this.timer) + this.isDragIn = false }) }, - 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 - } - } + methods: {} }) diff --git a/src/main.js b/src/main.js index 40fd494..8c4bab3 100644 --- a/src/main.js +++ b/src/main.js @@ -4,20 +4,13 @@ * @date 2019/09/16 20:51:19 */ -const { - app, - BrowserWindow, - protocol, - ipcMain, - net, - Notification -} = require('electron') +const { app, BrowserWindow, protocol, ipcMain } = require('electron') const path = require('path') const fs = require('iofs') const { createMainWindow, createFloatWindow } = require('./tools/window') const createMenu = require('./tools/menu') -const createTay = require('./tools/tray') +const Socket = require('./tools/socket') const MIME_TYPES = { '.js': 'text/javascript', @@ -35,45 +28,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(() => { - 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('--autoplay-policy', 'no-user-gesture-required') @@ -101,7 +55,7 @@ app.once('ready', () => { app.__float__ = createFloatWindow() createMenu(app.__main__) - createTay(app.__float__, app.__main__) + Socket(app) app.__main__.on('closed', () => { 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 - } -}) diff --git a/src/tools/menu.js b/src/tools/menu.js index 5f63419..cd7a3c2 100644 --- a/src/tools/menu.js +++ b/src/tools/menu.js @@ -9,9 +9,9 @@ const { Menu } = require('electron') module.exports = function(win) { var menuList = Menu.buildFromTemplate([ { - label: 'ๆžๅŸบๆ•ฐๆฎ', + label: 'E-pub Reader', submenu: [ - { role: 'about', label: 'ๅ…ณไบŽๆžๅŸบๆ•ฐๆฎ' }, + { role: 'about', label: 'ๅ…ณไบŽE-pub Reader' }, { type: 'separator' }, { label: '้€€ๅ‡บ', diff --git a/src/tools/socket.js b/src/tools/socket.js new file mode 100644 index 0000000..6451086 --- /dev/null +++ b/src/tools/socket.js @@ -0,0 +1,45 @@ +/** + * ่ฟ›็จ‹้€š่ฎฏไบคไบ’ + * @author yutent + * @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 + } + }) +} diff --git a/src/tools/tray.js b/src/tools/tray.js deleted file mode 100644 index 2cf498a..0000000 --- a/src/tools/tray.js +++ /dev/null @@ -1,42 +0,0 @@ -/** - * ๆ‰˜็›˜ - * @author yutent - * @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 -} diff --git a/src/tools/window.js b/src/tools/window.js index db16d3c..f7ea2e3 100644 --- a/src/tools/window.js +++ b/src/tools/window.js @@ -11,19 +11,13 @@ const { BrowserWindow } = require('electron') */ exports.createMainWindow = function(icon) { var win = new BrowserWindow({ - title: 'ๆžๅŸบๆ•ฐๆฎ', - width: 1024, + title: 'E-pub Reader', + width: 960, height: 540, - frame: false, - titleBarStyle: 'hiddenInset', resizable: false, maximizable: false, icon, - transparent: true, - vibrancy: 'hud', - visualEffectState: 'active', webPreferences: { - // webSecurity: false, experimentalFeatures: true, nodeIntegration: true, spellcheck: false @@ -33,10 +27,10 @@ exports.createMainWindow = function(icon) { win.loadURL('app://local/index.html') - // win.on('ready-to-show', _ => { - // win.show() - // win.openDevTools() - // }) + win.on('ready-to-show', _ => { + win.show() + win.openDevTools() + }) win.on('close', ev => { ev.preventDefault()