Add: log viewer

This commit is contained in:
cutls 2019-10-31 01:00:06 +09:00
parent 2fd45f9e31
commit 9977c009e0
7 changed files with 48 additions and 13 deletions

View File

@ -184,6 +184,10 @@ onmessage = function (e) {
asRead()
} else if (e.data[0] == "asReadEnd") {
asReadEnd()
} else if (e.data[0] == "logData") {
$("#logs").val(e.data[1])
var obj = document.getElementById("logs");
obj.scrollTop = obj.scrollHeight;
} else if (e.data[0] == "alert") {
Swal.fire({
type: 'info',

View File

@ -169,6 +169,10 @@ ipc.on("memory", function(event, arg) {
var total = arg[2];
postMessage(["renderMem", [use, cpu, total]], "*");
});
//log
ipc.on("logData", function(event, args) {
postMessage(["logData", args], "*");
});
//update.html
ipc.on("prog", function(event, arg) {
postMessage(["updateProg", arg], "*");

View File

@ -69,5 +69,9 @@ $(function () {
});
});
function help() {
postMessage(["openUrl", "https://docs.thedesk.top"], "*")
$("#left-menu div").removeClass("active");
$("#helpMenu").addClass("active");
$(".menu-content").addClass("hide");
$("#help-box").removeClass("hide");
postMessage(["sendSinmpleIpc", "getLogs"], "*")
}

View File

@ -12,6 +12,17 @@ function system(mainWindow, dir, lang, dirname) {
var ua_path = join(app.getPath("userData"), "useragent");
var lang_path = join(app.getPath("userData"), "language");
var log_dir_path = join(app.getPath("userData"), "logs");
//ログ
var today = new Date();
//今日のやつ
var todayStr = today.getFullYear() + "" + (today.getMonth() + 1) + "" + today.getDate() + ".log";
//昨日のやつ
today.setDate(today.getDate() - 1);
var yestStr = today.getFullYear() + "" + (today.getMonth() + 1) + "" + today.getDate() + ".log";
//一昨日のやつ
today.setDate(today.getDate() - 1);
var yest2Str = today.getFullYear() + "" + (today.getMonth() + 1) + "" + today.getDate() + ".log";
const BrowserWindow = electron.BrowserWindow;
const dialog = electron.dialog;
const os = require("os");
@ -243,17 +254,20 @@ function system(mainWindow, dir, lang, dirname) {
}
});
});
ipc.on("getLogs", (e, arg) => {
var logs=""
fs.readdir(log_dir_path, function(err, files) {
if (err) throw err;
files.filter(function(file) {
if (file == todayStr || file == yestStr || file == yest2Str) {
logs=logs+fs.readFileSync(join(log_dir_path, file), "utf8")
}
});
e.sender.webContents.send("logData", logs);
});
});
//起動時ログディレクトリ存在確認と作成、古ログ削除
fs.access(log_dir_path, fs.constants.R_OK | fs.constants.W_OK, error => {
var today = new Date();
//今日のやつ
var todayStr = today.getFullYear() + "" + (today.getMonth() + 1) + "" + today.getDate() + ".log";
//昨日のやつ
today.setDate(today.getDate() - 1);
var yestStr = today.getFullYear() + "" + (today.getMonth() + 1) + "" + today.getDate() + ".log";
//一昨日のやつ
today.setDate(today.getDate() - 1);
var yest2Str = today.getFullYear() + "" + (today.getMonth() + 1) + "" + today.getDate() + ".log";
if (error) {
if (error.code === "ENOENT") {
fs.mkdirSync(log_dir_path);
@ -265,7 +279,6 @@ function system(mainWindow, dir, lang, dirname) {
if (err) throw err;
files.filter(function(file) {
if (file != todayStr && file != yestStr && file != yest2Str) {
console.log(file, todayStr, yest2Str, yest2Str);
fs.unlinkSync(join(log_dir_path, file));
}
});

View File

@ -842,8 +842,8 @@
class="material-icons">recent_actors</i><span>@@directory@@</span></div>
<div class="waves-effect" onclick="filterMenu()" id="filterMenu"><i
class="material-icons">filter_list</i><span>@@filter@@</span></div>
<div class="waves-effect" onclick="help()"><i
class="material-icons">help_outline</i><span>@@help@@</span></div>
<div class="waves-effect" onclick="help()" id="helpMenu"><i
class="material-icons">help_outline</i><span>@@helpAndLogs@@</span></div>
<div class="waves-effect" onclick="location.href='index.html'"><i
class="material-icons">refresh</i><span>@@f5@@</span></div>
</div>
@ -1042,6 +1042,12 @@
id="add-filter-btn">@@add@@</button><br>
<span class="sml">@@warnOnIntegratedTL@@</span>
</div>
<!--ヘルプとログ-->
<div id="help-box" class="hide menu-content">
<a href="https://docs.thedesk.top" class="btn waves-effect" style="width:97.5%;">@@help@@</a><br>
@@contactwithlog@@<br>
<textarea id="logs" style="height:250px;"></textarea><br>
</div>
</div>
</div>
<a onclick="about()" class="nex waves-effect">

View File

@ -162,7 +162,9 @@
"clockTips":"Clock",
"ramTips":"RAM status",
"changeTips":"Change Tips",
"helpAndLogs":"Help & Log",
"help":"Help",
"contactwithlog":"If you tell me bugs(not working or something) with this log, I can detect what is wrong more easily.",
"about":"About TheDesk",
"hereAddColumns":"<- Add TL",
"show": "Show",

View File

@ -162,7 +162,9 @@
"clockTips":"時計",
"ramTips":"システムメモリ容量",
"changeTips":"Tips変更",
"helpAndLogs":"ヘルプとログ",
"help":"ヘルプ",
"contactwithlog":"不具合等のお問合わせは以下のログから発生時刻付近のものを集めてご連絡いただけるとスムーズになるかもしれません。また、このメニューウィンドウ全体を横に引き伸ばすとログが見やすくなります。",
"about":"このソフトについて",
"hereAddColumns":"←ここからTL追加",
"show": "表示",