From f2ec258e7a4c1673c0c08ecf80c6b3009b476cc1 Mon Sep 17 00:00:00 2001 From: Cutls Date: Sun, 22 Sep 2019 19:55:59 +0900 Subject: [PATCH] Change: markers API trigger --- app/js/lang/lang.bg.js | 2 + app/js/lang/lang.cs.js | 2 + app/js/lang/lang.de.js | 2 + app/js/lang/lang.en.js | 2 + app/js/lang/lang.ja.js | 2 + app/js/platform/end.js | 4 ++ app/js/platform/preload.js | 8 ++++ app/js/tl/tl.js | 70 +++++++++++++++++++++-------- app/main.js | 91 +++++++++++++++++++++++++++++--------- app/package.json | 4 +- 10 files changed, 144 insertions(+), 43 deletions(-) diff --git a/app/js/lang/lang.bg.js b/app/js/lang/lang.bg.js index 85ba630a..a5a5a240 100644 --- a/app/js/lang/lang.bg.js +++ b/app/js/lang/lang.bg.js @@ -107,6 +107,8 @@ var lang={ "lang_tags_tagwarn": "Автоматично попълване на {{tag}}, ако раздумката няма {{tag}}", "lang_tl_media": "Media", "lang_tl_reconnect": "Reconnect to streaming API", + "lang_tl_postmarkers_title": "Process...", + "lang_tl_postmarkers": "POST markers data. Please wait", "lang_img_DLDone": "Downloaded:", "lang_layout_gotop": "Go top of this column. When icon is red, this column cannot connect straming API. Please reload.", "lang_layout_thisacct": "{{notf}} of this account", diff --git a/app/js/lang/lang.cs.js b/app/js/lang/lang.cs.js index 689395bc..80c1a727 100644 --- a/app/js/lang/lang.cs.js +++ b/app/js/lang/lang.cs.js @@ -107,6 +107,8 @@ var lang={ "lang_tags_tagwarn": "Auto complete {{tag}}, if toot without {{tag}}", "lang_tl_media": "Média", "lang_tl_reconnect": "Reconnect to streaming API", + "lang_tl_postmarkers_title": "Process...", + "lang_tl_postmarkers": "POST markers data. Please wait", "lang_img_DLDone": "Downloaded:", "lang_layout_gotop": "Go top of this column. When icon is red, this column cannot connect straming API. Please reload.", "lang_layout_thisacct": "{{notf}} tohoto účtu", diff --git a/app/js/lang/lang.de.js b/app/js/lang/lang.de.js index 1e85ba60..5972c984 100644 --- a/app/js/lang/lang.de.js +++ b/app/js/lang/lang.de.js @@ -107,6 +107,8 @@ var lang={ "lang_tags_tagwarn": "Automatisch {{tag}} anfügen, wenn Tröt ohne {{tag}} ist", "lang_tl_media": "Medien", "lang_tl_reconnect": "Mit Streaming API erneut verbinden", + "lang_tl_postmarkers_title": "Process...", + "lang_tl_postmarkers": "POST markers data. Please wait", "lang_img_DLDone": "Heruntergeladen:", "lang_layout_gotop": "Gehen Sie zum Anfang dieser Spalte. Wenn das Symbol rot ist, kann diese Spalte keine Verbindung zur Streaming-API herstellen. Bitte neu laden.", "lang_layout_thisacct": "{{notf}} dieses Kontos", diff --git a/app/js/lang/lang.en.js b/app/js/lang/lang.en.js index 997fa78e..27157ad0 100644 --- a/app/js/lang/lang.en.js +++ b/app/js/lang/lang.en.js @@ -131,6 +131,8 @@ var lang = { //tl/tl.js "lang_tl_media": "Media", "lang_tl_reconnect": "Reconnect to streaming API", + "lang_tl_postmarkers_title": "Process...", + "lang_tl_postmarkers": "POST markers data. Please wait", //ui/img.js "lang_img_DLDone": "Downloaded:", //ui/layout.js diff --git a/app/js/lang/lang.ja.js b/app/js/lang/lang.ja.js index 60dfc79a..e307ead7 100644 --- a/app/js/lang/lang.ja.js +++ b/app/js/lang/lang.ja.js @@ -131,6 +131,8 @@ var lang = { //tl/tl.js "lang_tl_media": "メディア", "lang_tl_reconnect": "Streamingに再接続しました", + "lang_tl_postmarkers_title": "処理中", + "lang_tl_postmarkers": "未読マーカーを送信しています。3秒以内に閉じられます。", //ui/img.js "lang_img_DLDone": "ダウンロード先:", //ui/layout.js diff --git a/app/js/platform/end.js b/app/js/platform/end.js index d0f870da..60b846b1 100644 --- a/app/js/platform/end.js +++ b/app/js/platform/end.js @@ -183,6 +183,10 @@ onmessage = function (e) { updateMess(e.data[1]); } else if (e.data[0] == "renderAbout") { renderAbout(e.data[1]); + } else if (e.data[0] == "asRead") { + asRead() + } else if (e.data[0] == "asReadEnd") { + asReadEnd() } else if (e.data[0] == "alert") { Swal.fire({ type: 'info', diff --git a/app/js/platform/preload.js b/app/js/platform/preload.js index b5770133..1b277dd5 100644 --- a/app/js/platform/preload.js +++ b/app/js/platform/preload.js @@ -57,6 +57,8 @@ onmessage = function (e) { ipc.send('download-btn', e.data[1]); } else if (e.data[0] == "nano") { ipc.send('nano', null); + } else if (e.data[0] == "asReadComp") { + ipc.send('sendMarkersComplete', null); } } //version.js @@ -164,6 +166,12 @@ ipc.on('prog', function (event, arg) { ipc.on('mess', function (event, arg) { postMessage(["updateMess", arg], "*") }) +ipc.on('asRead', function (event, arg) { + postMessage(["asRead", ""], "*") +}) +ipc.on('asReadEnd', function (event, arg) { + postMessage(["asReadEnd", ""], "*") +}) var webviewDom = document.getElementById('webview'); if (webviewDom) { webviewDom.addEventListener('new-window', function (e) { diff --git a/app/js/tl/tl.js b/app/js/tl/tl.js index e9419abf..039a2ef3 100644 --- a/app/js/tl/tl.js +++ b/app/js/tl/tl.js @@ -999,24 +999,24 @@ function ueload(tlid) { columnReload(tlid, type) } if (localStorage.getItem("filter_" + acct_id) != "undefined") { - var mute = getFilterType(JSON.parse(localStorage.getItem("filter_" + acct_id)), type); + var mute = getFilterType(JSON.parse(localStorage.getItem("filter_" + acct_id)), type) } else { - var mute = []; + var mute = [] } - var templete = parse(json, '', acct_id, tlid, "", mute, type); + var templete = parse(json, '', acct_id, tlid, "", mute, type) var len = json.length - 1 - $("#timeline_" + tlid).prepend(templete); + $("#timeline_" + tlid).prepend(templete) if ($("#timeline_" + tlid + " .cvo:eq(" + len + ")").length) { var to = $("#timeline_" + tlid + " .cvo:eq(" + len + ")").offset().top $("#timeline_box_" + tlid + "_box .tl-box").scrollTop(to) } - additional(acct_id, tlid); - jQuery("time.timeago").timeago(); - todc(); + additional(acct_id, tlid) + jQuery("time.timeago").timeago() + todc() ueloadlock = false }); } -function asRead() { +function asRead(callback) { //Markers var markers = localStorage.getItem("markers"); if (markers == "no") { @@ -1027,7 +1027,9 @@ function asRead() { if (markers) { var multi = localStorage.getItem("column") var obj = JSON.parse(multi) - for (var i = 0; i < obj.length; i++) { + var obl = obj.length + ct = 0 + for (var i = 0; i < obl; i++) { var acct_id = obj[i].domain var type = obj[i].type if (type == "home" || type == "notf") { @@ -1046,23 +1048,53 @@ function asRead() { } } } - var domain = localStorage.getItem("domain_" + acct_id); - var at = localStorage.getItem("acct_" + acct_id + "_at"); - var httpreq = new XMLHttpRequest(); + + var domain = localStorage.getItem("domain_" + acct_id) + var at = localStorage.getItem("acct_" + acct_id + "_at") + var httpreq = new XMLHttpRequest() var start = "https://" + domain + "/api/v1/markers" - httpreq.open('POST', start, true); - httpreq.setRequestHeader('Content-Type', 'application/json'); - httpreq.setRequestHeader('Authorization', 'Bearer ' + at); - httpreq.responseType = "json"; - httpreq.send(JSON.stringify(poster)); + httpreq.open('POST', start, true) + httpreq.setRequestHeader('Content-Type', 'application/json') + httpreq.setRequestHeader('Authorization', 'Bearer ' + at) + httpreq.responseType = "json" + httpreq.send(JSON.stringify(poster)) httpreq.onreadystatechange = function () { if (httpreq.readyState === 4) { - var json = httpreq.response; + var json = httpreq.response console.log(json) + ct++ + if (ct == obl && callback) { + postMessage(["asReadComp", ""], "*") + } } } } } } } -cbTimer1 = setInterval(asRead, 60000); \ No newline at end of file +function asReadEnd() { + //Markers + var markers = localStorage.getItem("markers"); + if (markers == "no") { + markers = false; + } else { + markers = true + } + if (markers) { + asRead(true) + Swal.fire({ + title: lang.lang_tl_postmarkers_title, + html: lang.lang_tl_postmarkers, + timer: 3000, + onBeforeOpen: () => { + Swal.showLoading() + }, + onClose: () => { + } + }).then((result) => { + + }) + } else { + postMessage(["asReadComp", ""], "*") + } +} \ No newline at end of file diff --git a/app/main.js b/app/main.js index 9ecfc658..3cc9674e 100644 --- a/app/main.js +++ b/app/main.js @@ -12,6 +12,7 @@ const np = require('./main/np.js'); const systemFunc = require('./main/system.js'); const Menu = electron.Menu const join = require('path').join; + // アプリケーションをコントロールするモジュール const app = electron.app; // ウィンドウを作成するモジュール @@ -29,8 +30,8 @@ if (!gotTheLock) { // 多重起動を試みた場合、既に存在するウィンドウにフォーカスを移す // Someone tried to run a second instance, we should focus our window. if (mainWindow) { - if (mainWindow.isMinimized()) mainWindow.restore() - mainWindow.focus() + if (mainWindow.isMinimized()) mainWindow.restore() + mainWindow.focus() } }) } @@ -40,18 +41,18 @@ if (process.argv.indexOf("--dev") === -1) { } else { var packaged = false; console.log( - "||\\\\\\ \n"+ - "|||| \\\\\\\\ \n"+ - "|||| \\\\\\\\ \n"+ - "|||| Am I a \\\\\\\\ \n"+ - "|||| cat? ^ ^ \\\\\\\\\\ _____ _ ____ _ \n"+ - "|||| (.-.) \\\\\\\\\\ |_ _| |__ ___| _ \\ ___ ___| | __\n"+ - "|||| ___> ) ||||| | | | '_ \\ / _ \\ | | |/ _ \\/ __| |/ /\n"+ - "|||| < _ _) ////// | | | | | | __/ |_| | __/\__ \\ < \n"+ - "|||| |_||_| ///// |_| |_| |_|\\___|____/ \\___||___/_|\\_\\ \n"+ - "|||| ///// \n"+ - "|||| /////\n"+ - "|||| /////\n"+ + "||\\\\\\ \n" + + "|||| \\\\\\\\ \n" + + "|||| \\\\\\\\ \n" + + "|||| Am I a \\\\\\\\ \n" + + "|||| cat? ^ ^ \\\\\\\\\\ _____ _ ____ _ \n" + + "|||| (.-.) \\\\\\\\\\ |_ _| |__ ___| _ \\ ___ ___| | __\n" + + "|||| ___> ) ||||| | | | '_ \\ / _ \\ | | |/ _ \\/ __| |/ /\n" + + "|||| < _ _) ////// | | | | | | __/ |_| | __/\__ \\ < \n" + + "|||| |_||_| ///// |_| |_| |_|\\___|____/ \\___||___/_|\\_\\ \n" + + "|||| ///// \n" + + "|||| /////\n" + + "|||| /////\n" + "||||//////" ) console.log("Welcome!") @@ -63,9 +64,9 @@ var ha_path = join(app.getPath("userData"), "hardwareAcceleration"); try { fs.readFileSync(ha_path, 'utf8'); app.disableHardwareAcceleration() - if(!packaged) console.log("disabled: Hardware Acceleration"); + if (!packaged) console.log("disabled: Hardware Acceleration"); } catch{ - if(!packaged) console.log("enabled: Hardware Acceleration"); + if (!packaged) console.log("enabled: Hardware Acceleration"); } var window_size; try { @@ -131,8 +132,8 @@ function createWindow() { fs.writeFileSync(lang_path, lang); }); } - if(!packaged) console.log("your lang:" + app.getLocale()); - if(!packaged) console.log("launch:" + lang); + if (!packaged) console.log("your lang:" + app.getLocale()); + if (!packaged) console.log("launch:" + lang); // メイン画面の表示。ウィンドウの幅、高さを指定できる var platform = process.platform; var bit = process.arch; @@ -173,7 +174,7 @@ function createWindow() { if (window_size.max) { mainWindow.maximize(); } - }) + }) electron.session.defaultSession.clearCache(() => { }) if (process.argv) { if (process.argv[1]) { @@ -200,7 +201,27 @@ function createWindow() { electron.ipcMain.removeAllListeners(); mainWindow = null; }); - mainWindow.on('close', function () { + closeArg = false + mainWindow.on('close', function (e, arg) { + if(!closeArg){ + e.preventDefault() + } + const promise = new Promise(function (resolve) { + mainWindow.webContents.send('asReadEnd', "") + setTimeout(function () { resolve() }, 3000) + }) + promise.then((function (response) { + writePos(mainWindow) + closeArg = true + mainWindow.close() + }) + ); + }); + electron.ipcMain.on('sendMarkersComplete', function (e, arg) { + closeArg = true + mainWindow.close() + }) + function writePos(mainWindow){ if ( max_window_size.width == mainWindow.getBounds().width && max_window_size.height == mainWindow.getBounds().height && @@ -211,11 +232,14 @@ function createWindow() { } else { var size = { width: mainWindow.getBounds().width, height: mainWindow.getBounds().height, x: mainWindow.getBounds().x, y: mainWindow.getBounds().y } } - fs.writeFileSync(info_path, JSON.stringify(size)); - }); + fs.writeFileSync(info_path, JSON.stringify(size)) + } mainWindow.on('maximize', function () { fs.writeFileSync(max_info_path, JSON.stringify(mainWindow.getBounds())); }); + mainWindow.on('minimize', function () { + mainWindow.webContents.send('asRead', "") + }) var platform = process.platform; var bit = process.arch; @@ -230,6 +254,29 @@ function createWindow() { np.TheDeskNowPlaying(mainWindow); //その他system systemFunc.system(mainWindow, dir, lang, dirname); + setInterval(function () { mouseTrack(mainWindow) }, 1000); +} +var x = 0 +var y = 0 +var unchanged = 0 +var locked = false +function mouseTrack(mainWindow) { + let mousePos = electron.screen.getCursorScreenPoint() + let xNow = mousePos.x + let yNow = mousePos.x + if (x != xNow || y != yNow) { + unchanged = 0 + locked = false + } else { + unchanged++ + if (unchanged > 60 && !locked) { + unchanged = 0 + locked = true + mainWindow.webContents.send('asRead', "") + } + } + x = xNow + y = yNow } // Electronの初期化完了後に実行 app.on('ready', createWindow); diff --git a/app/package.json b/app/package.json index 50a43554..c4e171d5 100644 --- a/app/package.json +++ b/app/package.json @@ -62,8 +62,8 @@ "vue": "^2.6.10" }, "optionalDependencies": { - "itunes-nowplaying-mac": "kPherox/itunes-nowplaying-mac#get-artworks-base64", - "font-manager": "^0.3.0" + "font-manager": "^0.3.0", + "itunes-nowplaying-mac": "kPherox/itunes-nowplaying-mac#get-artworks-base64" }, "devDependencies": { "electron": "^6.0.0",