From 85468761d318e9d2af66fb24dd71cb923c31def9 Mon Sep 17 00:00:00 2001 From: cutls Date: Mon, 14 Oct 2019 00:28:10 +0900 Subject: [PATCH] Improve: nano --- app/js/platform/nano.js | 148 ++++++++++++++-- app/main/system.js | 32 +--- app/nano.html | 377 ++++++++++++++++------------------------ 3 files changed, 282 insertions(+), 275 deletions(-) diff --git a/app/js/platform/nano.js b/app/js/platform/nano.js index d7618bf1..c871b4ed 100644 --- a/app/js/platform/nano.js +++ b/app/js/platform/nano.js @@ -1,7 +1,11 @@ //TL取得 +var websocket; function tl(data) { var tlid = 0; + if(websocket){ + websocket.close() + } var acct_id = $("#post-acct-sel").val(); var type = $("#type-sel").val(); var domain = localStorage.getItem("domain_" + acct_id); @@ -28,9 +32,9 @@ function tl(data) { var templete = parse([json[0]], '', acct_id, tlid); $("#timeline_nano").html(templete); jQuery("time.timeago").timeago(); + $("#menu").addClass("hide"); }); //Streaming接続 - var websocket = []; var tlid = 0; if (type == "home") { var start = "wss://" + domain + @@ -45,29 +49,26 @@ function tl(data) { var start = "wss://" + domain + "/api/v1/streaming/?stream=hashtag&tag=" + data + "&access_token=" + at; } - var wsid = websocket.length; - websocket[wsid] = new WebSocket(start); - websocket[wsid].onopen = function (mess) { + websocket = new WebSocket(start); + websocket.onopen = function (mess) { $("#notice_icon_" + tlid).removeClass("red-text"); } - websocket[wsid].onmessage = function (mess) { + websocket.onmessage = function (mess) { var typeA = JSON.parse(mess.data).event; - if (typeA == "delete") { - var obj = JSON.parse(mess.data).payload; - $("[toot-id=" + JSON.parse(mess.data).payload + "]").hide(); - $("[toot-id=" + JSON.parse(mess.data).payload + "]").remove(); - } else if (typeA == "update") { + if (typeA == "update") { var obj = JSON.parse(JSON.parse(mess.data).payload); var templete = parse([obj], '', acct_id, tlid); + jQuery("time.timeago").timeago(); $("#timeline_nano").html(templete); } - websocket[wsid].onclose = function (mess) { - console.error("Close Streaming API:" + type); - } + } - websocket[wsid].onerror = function (error) { + websocket.onerror = function (error) { console.error('WebSocket Error ' + error); }; + websocket.onclose = function (mess) { + console.error("Close Streaming API:" + type); + } } //TLのタイトル function cap(type, data) { @@ -134,3 +135,122 @@ $(function ($) { } }); }); +function set() { + $("#menu").toggleClass("hide"); + if($("#menu").hasClass("hide")){ + $("#setting").text("Setting") + }else{ + $("#setting").text("Close") + } +} + +var multi = localStorage.getItem("multi"); +if (!multi) { + var obj = [ + { + at: localStorage.getItem(localStorage.getItem("domain_" + acct_id) + "_at"), + name: localStorage.getItem("name_" + acct_id), + domain: localStorage.getItem("domain_" + acct_id), + user: localStorage.getItem("user_" + acct_id), + prof: localStorage.getItem("prof_" + acct_id) + } + ]; + var json = JSON.stringify(obj); + localStorage.setItem("multi", json); +} else { + var obj = JSON.parse(multi); +} +var templete; +var last = localStorage.getItem("last-use"); +var sel; +Object.keys(obj).forEach(function(key) { + var acct = obj[key]; + var list = key * 1 + 1; + if (key == last) { + sel = "selected"; + } else { + sel = ""; + } + templete = '"; + $("#post-acct-sel").append(templete); +}); +function mov() { + return false; +} +function resetmv() { + return false; +} +function post() { + var acct_id = $("#post-acct-sel").val(); + var domain = localStorage.getItem("domain_" + acct_id); + var at = localStorage.getItem("acct_" + acct_id + "_at"); + var start = "https://" + domain + "/api/v1/statuses"; + var str = $("#textarea").val(); + var toot = { + status: str + }; + var vis = loadVis(acct_id); + toot.visibility = vis; + var httpreq = new XMLHttpRequest(); + httpreq.open("POST", start, true); + httpreq.setRequestHeader("Content-Type", "application/json"); + httpreq.setRequestHeader("Authorization", "Bearer " + at); + httpreq.responseType = "json"; + httpreq.send(JSON.stringify(toot)); + httpreq.onreadystatechange = function() { + if (httpreq.readyState === 4) { + $("#textarea").val(""); + } + }; +} +function loadVis(acct_id) { + var vist = localStorage.getItem("vis"); + if (!vist) { + return "public"; + } else { + if (vist == "memory") { + var memory = localStorage.getItem("vis-memory-" + acct_id); + if (!memory) { + memory = "public"; + } + return memory; + } else if (vist == "server" || vist == "useapi") { + var multi = localStorage.getItem("multi"); + var obj = JSON.parse(multi); + var memory = obj[acct_id]["vis"]; + if (!memory) { + memory = "public"; + } + return memory; + } else { + return vist; + } + } +} +function loader(){ + var acct_id = $("#post-acct-sel").val() + console.log(loadVis(acct_id)) + $("#vis-sel").val(loadVis(acct_id)); +} +loader() +$("textarea").height(15); //init +$("textarea").css("lineHeight", "1rem"); //init + +$("textarea").on("input", function(evt) { + if (evt.target.scrollHeight > evt.target.offsetHeight) { + $(evt.target).height(evt.target.scrollHeight); + } else { + var lineHeight = Number( + $(evt.target) + .css("lineHeight") + .split("px")[0] + ); + while (true) { + $(evt.target).height($(evt.target).height() - lineHeight); + if (evt.target.scrollHeight > evt.target.offsetHeight) { + $(evt.target).height(evt.target.scrollHeight); + break; + } + } + } +}); \ No newline at end of file diff --git a/app/main/system.js b/app/main/system.js index f59a2f7b..739d6423 100644 --- a/app/main/system.js +++ b/app/main/system.js @@ -13,34 +13,6 @@ function system(mainWindow, dir, lang, dirname) { const dialog = electron.dialog; const os = require('os') const language = require("../main/language.js"); - ipc.on('native-notf', function (e, args) { - - var platform = process.platform; - var bit = process.arch; - if (platform == "win32") { - const notifier = require('node-notifier') - var tmp_imge = tmp_img; - Jimp.read(args[2], function (err, lenna) { - if (!err && lenna) { - lenna.write(tmp_img); - var tmp_imge = tmp_img; - } else { - var tmp_imge = ""; - } - notifier.notify({ - appID: "top.thedesk", - message: args[1], - title: args[0], - icon: tmp_imge, - sound: false, - wait: true, - }, - function (err, response) { - console.log(err, response) - }); - }); - } - }); //プラットフォーム ipc.on('getPlatform', function (e, arg) { try { @@ -162,14 +134,14 @@ function system(mainWindow, dir, lang, dirname) { preload: join(dirname, "js", "platform", "preload.js") }, width: 350, - height: 200, + height: 140, "transparent": false, // ウィンドウの背景を透過 "frame": false, // 枠の無いウィンドウ "resizable": false }); nanowindow.loadURL(dir + '/nano.html'); nanowindow.setAlwaysOnTop(true); - + //nanowindow.toggleDevTools() nanowindow.setPosition(window_pos[0], window_pos[1]); nanowindow.on('close', function () { fs.writeFileSync(nano_info_path, JSON.stringify(nanowindow.getPosition())); diff --git a/app/nano.html b/app/nano.html index 979579e0..a0d2252c 100644 --- a/app/nano.html +++ b/app/nano.html @@ -1,240 +1,155 @@ - - - - - - - TheDesk Nano - - - - - - - - -
-
-
-
- - - - - - - - - - - - - + \ No newline at end of file + + + + + + +
+
Click "settings" to show TL
+
+ + + + + + + + + + + + + +