WIP: useragent

This commit is contained in:
cutls 2019-10-26 01:16:33 +09:00
parent bb08ec2435
commit 3e2d40d248
7 changed files with 315 additions and 265 deletions

View File

@ -1,182 +1,188 @@
var electron = require("electron"); var electron = require("electron");
const shell = electron.shell; const shell = electron.shell;
var ipc = electron.ipcRenderer; var ipc = electron.ipcRenderer;
onmessage = function (e) { onmessage = function(e) {
if (e.data[0] == "openUrl") { if (e.data[0] == "openUrl") {
urls = e.data[1].match(/https?:\/\/(.+)/); urls = e.data[1].match(/https?:\/\/(.+)/);
if (urls) { if (urls) {
shell.openExternal(e.data[1]); shell.openExternal(e.data[1]);
} }
} else if (e.data[0] == "sendSinmpleIpc") { } else if (e.data[0] == "sendSinmpleIpc") {
ipc.send(e.data[1], "") ipc.send(e.data[1], "");
} else if (e.data[0] == "dialogStore") { } else if (e.data[0] == "dialogStore") {
ipc.send("dialogStore", e.data[1]) ipc.send("dialogStore", e.data[1]);
} else if (e.data[0] == "bmpImage") { } else if (e.data[0] == "bmpImage") {
ipc.send('bmp-image', e.data[1]); ipc.send("bmp-image", e.data[1]);
} else if (e.data[0] == "dialogCW") { } else if (e.data[0] == "dialogCW") {
ipc.send("dialogCW", e.data[1]) ipc.send("dialogCW", e.data[1]);
} else if (e.data[0] == "nativeNotf") { } else if (e.data[0] == "nativeNotf") {
console.log(e.data[1]) console.log(e.data[1]);
ipc.send('native-notf', e.data[1]); ipc.send("native-notf", e.data[1]);
} else if (e.data[0] == "dialogClient") { } else if (e.data[0] == "dialogClient") {
ipc.send("dialogClient", e.data[1]) ipc.send("dialogClient", e.data[1]);
} else if (e.data[0] == "generalDL") { } else if (e.data[0] == "generalDL") {
ipc.send('general-dl', e.data[1]); ipc.send("general-dl", e.data[1]);
} else if (e.data[0] == "openFinder") { } else if (e.data[0] == "openFinder") {
ipc.send('open-finder', e.data[1]); ipc.send("open-finder", e.data[1]);
} else if (e.data[0] == "columnDel") { } else if (e.data[0] == "columnDel") {
ipc.send('column-del', e.data[1]); ipc.send("column-del", e.data[1]);
} else if (e.data[0] == "lang") { } else if (e.data[0] == "lang") {
ipc.send('lang', e.data[1]); ipc.send("lang", e.data[1]);
} else if (e.data[0] == "exportSettings") { } else if (e.data[0] == "exportSettings") {
ipc.send('exportSettings', e.data[1]); ipc.send("exportSettings", e.data[1]);
} else if (e.data[0] == "exportSettingsCoreComplete") { } else if (e.data[0] == "exportSettingsCoreComplete") {
ipc.send('export', e.data[1]); ipc.send("export", e.data[1]);
} else if (e.data[0] == "importSettings") { } else if (e.data[0] == "importSettings") {
ipc.send('importSettings', e.data[1]); ipc.send("importSettings", e.data[1]);
} else if (e.data[0] == "customSound") { } else if (e.data[0] == "customSound") {
ipc.send('customSound', e.data[1]); ipc.send("customSound", e.data[1]);
} else if (e.data[0] == "themeJsonDelete") { } else if (e.data[0] == "themeJsonDelete") {
ipc.send('theme-json-delete', e.data[1]); ipc.send("theme-json-delete", e.data[1]);
} else if (e.data[0] == "themeJsonCreate") { } else if (e.data[0] == "themeJsonCreate") {
ipc.send('theme-json-create', e.data[1]); ipc.send("theme-json-create", e.data[1]);
} else if (e.data[0] == "themeJsonRequest") { } else if (e.data[0] == "themeJsonRequest") {
ipc.send('theme-json-request', e.data[1]); ipc.send("theme-json-request", e.data[1]);
} else if (e.data[0] == "ha") { } else if (e.data[0] == "ha") {
ipc.send('ha', e.data[1]); ipc.send("ha", e.data[1]);
} else if (e.data[0] == "aboutData") { } else if (e.data[0] == "ua") {
ipc.send('aboutData', ""); ipc.send("ua", e.data[1]);
} else if (e.data[0] == "itunes") { } else if (e.data[0] == "aboutData") {
console.log("NowPlaying") ipc.send("aboutData", "");
ipc.send("itunes", e.data[1]) } else if (e.data[0] == "itunes") {
} else if (e.data[0] == "themeCSSRequest") { console.log("NowPlaying");
ipc.send('theme-css-request', e.data[1]); ipc.send("itunes", e.data[1]);
} else if (e.data[0] == "customCSSRequest") { } else if (e.data[0] == "themeCSSRequest") {
ipc.send('custom-css-request', e.data[1]); ipc.send("theme-css-request", e.data[1]);
} else if (e.data[0] == "downloadButton") { } else if (e.data[0] == "customCSSRequest") {
ipc.send('download-btn', e.data[1]); ipc.send("custom-css-request", e.data[1]);
} else if (e.data[0] == "nano") { } else if (e.data[0] == "downloadButton") {
ipc.send('nano', null); ipc.send("download-btn", e.data[1]);
} else if (e.data[0] == "asReadComp") { } else if (e.data[0] == "nano") {
ipc.send('sendMarkersComplete', null); ipc.send("nano", null);
} else if (e.data[0] == "copy") { } else if (e.data[0] == "asReadComp") {
ipc.send('copy', e.data[1]); ipc.send("sendMarkersComplete", null);
} } else if (e.data[0] == "copy") {
} ipc.send("copy", e.data[1]);
}
};
//version.js //version.js
ipc.send("getPlatform", "") ipc.send("getPlatform", "");
ipc.on('platform', function (event, args) { ipc.on("platform", function(event, args) {
localStorage.setItem("platform", args[0]) localStorage.setItem("platform", args[0]);
localStorage.setItem("bit", args[1]) localStorage.setItem("bit", args[1]);
localStorage.setItem("about", JSON.stringify([args[2], args[3], args[4], args[5]])) localStorage.setItem("about", JSON.stringify([args[2], args[3], args[4], args[5]]));
}) });
ipc.on('reload', function (event, arg) { ipc.on("reload", function(event, arg) {
location.reload(); location.reload();
}) });
//Native Notf //Native Notf
ipc.on('shownotf', function (event, args) { ipc.on("shownotf", function(event, args) {
if (args["type"] == "toot") { if (args["type"] == "toot") {
postMessage(["details", [id, acct_id]], "*") postMessage(["details", [id, acct_id]], "*");
} else if (args["type"] == "userdata") { } else if (args["type"] == "userdata") {
postMessage(["udg", [user, acct_id]], "*") postMessage(["udg", [user, acct_id]], "*");
} }
}) });
//first.js //first.js
ipc.on('custom-css-response', function (event, arg) { ipc.on("custom-css-response", function(event, arg) {
if (arg == "") { return false; } if (arg == "") {
var styleNode = document.createElement("style"); return false;
styleNode.setAttribute("type", "text/css") }
var styleNode = document.createElement("style");
styleNode.setAttribute("type", "text/css");
var content = document.createTextNode(arg) var content = document.createTextNode(arg);
styleNode.append(content) styleNode.append(content);
document.getElementsByTagName("head")[0].append(styleNode) document.getElementsByTagName("head")[0].append(styleNode);
}) });
ipc.on('theme-css-response', function (event, arg) { ipc.on("theme-css-response", function(event, arg) {
if (arg == "") { return false; } if (arg == "") {
var styleNode = document.createElement("style"); return false;
styleNode.setAttribute("type", "text/css") }
var styleNode = document.createElement("style");
styleNode.setAttribute("type", "text/css");
var content = document.createTextNode(arg) var content = document.createTextNode(arg);
styleNode.append(content) styleNode.append(content);
document.getElementsByTagName("head")[0].append(styleNode) document.getElementsByTagName("head")[0].append(styleNode);
}) });
//img.js //img.js
ipc.on('bmp-img-comp', function (event, b64) { ipc.on("bmp-img-comp", function(event, b64) {
postMessage(["media", [b64[0], "image/png", b64[1]]], "*") postMessage(["media", [b64[0], "image/png", b64[1]]], "*");
}); });
//ui,img.js //ui,img.js
ipc.on('general-dl-prog', function (event, arg) { ipc.on("general-dl-prog", function(event, arg) {
console.log("Progress: " + arg); console.log("Progress: " + arg);
}) });
ipc.on('general-dl-message', function (event, arg) { ipc.on("general-dl-message", function(event, arg) {
var argC = arg.replace(/\\/g, "\\\\") + "\\\\."; var argC = arg.replace(/\\/g, "\\\\") + "\\\\.";
console.log("saved") console.log("saved");
postMessage(["toastSaved", [arg, argC]], "*") postMessage(["toastSaved", [arg, argC]], "*");
}) });
//setting.js //setting.js
ipc.on('langres', function (event, arg) { ipc.on("langres", function(event, arg) {
location.href = "../" + arg + "/setting.html" location.href = "../" + arg + "/setting.html";
}); });
ipc.on('exportSettingsFile', function (event, arg) { ipc.on("exportSettingsFile", function(event, arg) {
postMessage(["exportSettingsCore", arg], "*") postMessage(["exportSettingsCore", arg], "*");
}); });
ipc.on('exportAllComplete', function (event, arg) { ipc.on("exportAllComplete", function(event, arg) {
postMessage(["alert", "Complete"], "*") postMessage(["alert", "Complete"], "*");
}); });
ipc.on('config', function (event, arg) { ipc.on("config", function(event, arg) {
postMessage(["importSettingsCore", arg], "*") postMessage(["importSettingsCore", arg], "*");
}); });
ipc.on('savefolder', function (event, arg) { ipc.on("savefolder", function(event, arg) {
localStorage.setItem("savefolder", arg); localStorage.setItem("savefolder", arg);
}); });
ipc.on('font-list', function (event, arg) { ipc.on("font-list", function(event, arg) {
postMessage(["fontList", arg], "*") postMessage(["fontList", arg], "*");
}); });
ipc.on('customSoundRender', function (event, args) { ipc.on("customSoundRender", function(event, args) {
postMessage(["customSoundSave", [args[0], args[1]]], "*") postMessage(["customSoundSave", [args[0], args[1]]], "*");
}); });
ipc.on('theme-json-list-response', function (event, args) { ipc.on("theme-json-list-response", function(event, args) {
postMessage(["ctLoadCore", args], "*") postMessage(["ctLoadCore", args], "*");
}); });
ipc.on('theme-json-delete-complete', function (event, args) { ipc.on("theme-json-delete-complete", function(event, args) {
postMessage(["ctLoad", ""], "*") postMessage(["ctLoad", ""], "*");
}); });
ipc.on('theme-json-response', function (event, args) { ipc.on("theme-json-response", function(event, args) {
postMessage(["customConnect", args], "*") postMessage(["customConnect", args], "*");
}); });
ipc.on('theme-json-create-complete', function (event, args) { ipc.on("theme-json-create-complete", function(event, args) {
postMessage(["clearCustomImport", ""], "*") postMessage(["clearCustomImport", ""], "*");
postMessage(["ctLoad", ""], "*") postMessage(["ctLoad", ""], "*");
}); });
//spotify.js //spotify.js
ipc.on('itunes-np', function (event, arg) { ipc.on("itunes-np", function(event, arg) {
postMessage(["npCore", arg], "*") postMessage(["npCore", arg], "*");
}) });
//tips.js //tips.js
ipc.on('memory', function (event, arg) { ipc.on("memory", function(event, arg) {
var use = arg[0]; var use = arg[0];
var cpu = arg[1]; var cpu = arg[1];
var total = arg[2] var total = arg[2];
postMessage(["renderMem", [use, cpu, total]], "*") postMessage(["renderMem", [use, cpu, total]], "*");
}) });
//update.html //update.html
ipc.on('prog', function (event, arg) { ipc.on("prog", function(event, arg) {
postMessage(["updateProg", arg], "*") postMessage(["updateProg", arg], "*");
}) });
ipc.on('mess', function (event, arg) { ipc.on("mess", function(event, arg) {
postMessage(["updateMess", arg], "*") postMessage(["updateMess", arg], "*");
}) });
ipc.on('asRead', function (event, arg) { ipc.on("asRead", function(event, arg) {
postMessage(["asRead", ""], "*") postMessage(["asRead", ""], "*");
}) });
ipc.on('asReadEnd', function (event, arg) { ipc.on("asReadEnd", function(event, arg) {
postMessage(["asReadEnd", ""], "*") postMessage(["asReadEnd", ""], "*");
}) });
var webviewDom = document.getElementById('webview'); var webviewDom = document.getElementById("webview");
if (webviewDom) { if (webviewDom) {
webviewDom.addEventListener('new-window', function (e) { webviewDom.addEventListener("new-window", function(e) {
shell.openExternal(e.url); shell.openExternal(e.url);
}); });
} }

View File

@ -14,6 +14,9 @@ var envView = new Vue({
if (ls == "ha") { if (ls == "ha") {
hardwareAcceleration(val) hardwareAcceleration(val)
} }
if (ls == "ua_setting") {
useragent(val)
}
return true return true
} }
} }
@ -693,6 +696,9 @@ function clearCustomImport() {
function hardwareAcceleration(had) { function hardwareAcceleration(had) {
postMessage(["ha", had], "*") postMessage(["ha", had], "*")
} }
function useragent(val){
postMessage(["ua", val], "*")
}
function customSound(key) { function customSound(key) {
postMessage(["customSound", key], "*") postMessage(["customSound", key], "*")
} }

View File

@ -1,17 +1,17 @@
var dirname = __dirname; var dirname = __dirname;
var dir = 'file://' + __dirname; var dir = "file://" + __dirname;
var base = dir + '/view/'; var base = dir + "/view/";
// Electronのモジュール // Electronのモジュール
const electron = require("electron"); const electron = require("electron");
const fs = require("fs"); const fs = require("fs");
const language = require('./main/language.js'); const language = require("./main/language.js");
const css = require('./main/css.js'); const css = require("./main/css.js");
const dl = require('./main/dl.js'); const dl = require("./main/dl.js");
const img = require('./main/img.js'); const img = require("./main/img.js");
const np = require('./main/np.js'); const np = require("./main/np.js");
const systemFunc = require('./main/system.js'); const systemFunc = require("./main/system.js");
const Menu = electron.Menu const Menu = electron.Menu;
const join = require('path').join; const join = require("path").join;
// アプリケーションをコントロールするモジュール // アプリケーションをコントロールするモジュール
const app = electron.app; const app = electron.app;
@ -21,56 +21,43 @@ const BrowserWindow = electron.BrowserWindow;
let mainWindow; let mainWindow;
// アプリが多重起動しないようにする // アプリが多重起動しないようにする
const gotTheLock = app.requestSingleInstanceLock() const gotTheLock = app.requestSingleInstanceLock();
if (!gotTheLock) { if (!gotTheLock) {
app.quit() app.quit();
} else { } else {
app.on('second-instance', () => { app.on("second-instance", () => {
// 多重起動を試みた場合、既に存在するウィンドウにフォーカスを移す // 多重起動を試みた場合、既に存在するウィンドウにフォーカスを移す
// Someone tried to run a second instance, we should focus our window. // Someone tried to run a second instance, we should focus our window.
if (mainWindow) { if (mainWindow) {
if (mainWindow.isMinimized()) mainWindow.restore() if (mainWindow.isMinimized()) mainWindow.restore();
mainWindow.focus() mainWindow.focus();
} }
}) });
} }
if (process.argv.indexOf("--dev") === -1) { if (process.argv.indexOf("--dev") === -1) {
var packaged = true; var packaged = true;
} else { } else {
var packaged = false; var packaged = false;
console.log( console.log("||\\\\\\ \n" + "|||| \\\\\\\\ \n" + "|||| \\\\\\\\ \n" + "|||| Am I a \\\\\\\\ \n" + "|||| cat? ^ ^ \\\\\\\\\\ _____ _ ____ _ \n" + "|||| (.-.) \\\\\\\\\\ |_ _| |__ ___| _ \\ ___ ___| | __\n" + "|||| ___> ) ||||| | | | '_ \\ / _ \\ | | |/ _ \\/ __| |/ /\n" + "|||| < _ _) ////// | | | | | | __/ |_| | __/__ \\ < \n" + "|||| |_||_| ///// |_| |_| |_|\\___|____/ \\___||___/_|\\_\\ \n" + "|||| ///// \n" + "|||| /////\n" + "|||| /////\n" + "||||//////");
"||\\\\\\ \n" + console.log("Welcome!");
"|||| \\\\\\\\ \n" +
"|||| \\\\\\\\ \n" +
"|||| Am I a \\\\\\\\ \n" +
"|||| cat? ^ ^ \\\\\\\\\\ _____ _ ____ _ \n" +
"|||| (.-.) \\\\\\\\\\ |_ _| |__ ___| _ \\ ___ ___| | __\n" +
"|||| ___> ) ||||| | | | '_ \\ / _ \\ | | |/ _ \\/ __| |/ /\n" +
"|||| < _ _) ////// | | | | | | __/ |_| | __/\__ \\ < \n" +
"|||| |_||_| ///// |_| |_| |_|\\___|____/ \\___||___/_|\\_\\ \n" +
"|||| ///// \n" +
"|||| /////\n" +
"|||| /////\n" +
"||||//////"
)
console.log("Welcome!")
} }
var info_path = join(app.getPath("userData"), "window-size.json"); var info_path = join(app.getPath("userData"), "window-size.json");
var max_info_path = join(app.getPath("userData"), "max-window-size.json"); var max_info_path = join(app.getPath("userData"), "max-window-size.json");
var lang_path = join(app.getPath("userData"), "language"); var lang_path = join(app.getPath("userData"), "language");
var ha_path = join(app.getPath("userData"), "hardwareAcceleration"); var ha_path = join(app.getPath("userData"), "hardwareAcceleration");
var ua_path = join(app.getPath("userData"), "useragent");
try { try {
fs.readFileSync(ha_path, 'utf8'); fs.readFileSync(ha_path, "utf8");
app.disableHardwareAcceleration() app.disableHardwareAcceleration();
if (!packaged) console.log("disabled: Hardware Acceleration"); if (!packaged) console.log("disabled: Hardware Acceleration");
} catch{ } catch {
if (!packaged) console.log("enabled: Hardware Acceleration"); if (!packaged) console.log("enabled: Hardware Acceleration");
} }
var window_size; var window_size;
try { try {
window_size = JSON.parse(fs.readFileSync(info_path, 'utf8')); window_size = JSON.parse(fs.readFileSync(info_path, "utf8"));
} catch (e) { } catch (e) {
window_size = { window_size = {
width: 1000, width: 1000,
@ -79,33 +66,32 @@ try {
} }
var max_window_size; var max_window_size;
try { try {
max_window_size = JSON.parse(fs.readFileSync(max_info_path, 'utf8')); max_window_size = JSON.parse(fs.readFileSync(max_info_path, "utf8"));
} catch (e) { } catch (e) {
max_window_size = { max_window_size = {
width: "string", width: "string",
height: "string", height: "string",
x: "string", x: "string",
y: "string" y: "string"
}; // デフォルトバリュー }; // デフォルトバリュー
} }
function isFile(file) { function isFile(file) {
try { try {
fs.statSync(file); fs.statSync(file);
return true return true;
} catch (err) { } catch (err) {
if (err.code === 'ENOENT') return false if (err.code === "ENOENT") return false;
} }
} }
// 全てのウィンドウが閉じたら終了 // 全てのウィンドウが閉じたら終了
app.on('window-all-closed', function () { app.on("window-all-closed", function() {
electron.session.defaultSession.clearCache(() => { }) electron.session.defaultSession.clearCache(() => {});
app.quit(); app.quit();
}); });
function createWindow() { function createWindow() {
if (isFile(lang_path)) { if (isFile(lang_path)) {
var lang = fs.readFileSync(lang_path, 'utf8'); var lang = fs.readFileSync(lang_path, "utf8");
} else { } else {
var langs = app.getLocale(); var langs = app.getLocale();
console.log(langs); console.log(langs);
@ -120,7 +106,7 @@ function createWindow() {
} else { } else {
lang = "en"; lang = "en";
} }
fs.mkdir(app.getPath("userData"), function (err) { fs.mkdir(app.getPath("userData"), function(err) {
fs.writeFileSync(lang_path, lang); fs.writeFileSync(lang_path, lang);
}); });
} }
@ -137,8 +123,13 @@ function createWindow() {
contextIsolation: true, contextIsolation: true,
preload: join(__dirname, "js", "platform", "preload.js") preload: join(__dirname, "js", "platform", "preload.js")
}, },
width: window_size.width, height: window_size.height, x: window_size.x, y: window_size.y, icon: __dirname + '/desk.png', show: false width: window_size.width,
} height: window_size.height,
x: window_size.x,
y: window_size.y,
icon: __dirname + "/desk.png",
show: false
};
} else if (platform == "win32") { } else if (platform == "win32") {
var arg = { var arg = {
webPreferences: { webPreferences: {
@ -147,8 +138,13 @@ function createWindow() {
contextIsolation: true, contextIsolation: true,
preload: join(__dirname, "js", "platform", "preload.js") preload: join(__dirname, "js", "platform", "preload.js")
}, },
width: window_size.width, height: window_size.height, x: window_size.x, y: window_size.y, simpleFullscreen: true, show: false width: window_size.width,
} height: window_size.height,
x: window_size.x,
y: window_size.y,
simpleFullscreen: true,
show: false
};
} else if (platform == "darwin") { } else if (platform == "darwin") {
var arg = { var arg = {
webPreferences: { webPreferences: {
@ -157,25 +153,30 @@ function createWindow() {
contextIsolation: true, contextIsolation: true,
preload: join(__dirname, "js", "platform", "preload.js") preload: join(__dirname, "js", "platform", "preload.js")
}, },
width: window_size.width, height: window_size.height, x: window_size.x, y: window_size.y, simpleFullscreen: true, show: false width: window_size.width,
} height: window_size.height,
x: window_size.x,
y: window_size.y,
simpleFullscreen: true,
show: false
};
} }
mainWindow = new BrowserWindow(arg); mainWindow = new BrowserWindow(arg);
mainWindow.once('page-title-updated', () => { mainWindow.once("page-title-updated", () => {
mainWindow.show() mainWindow.show();
if (window_size.max) { if (window_size.max) {
mainWindow.maximize(); mainWindow.maximize();
} }
}) });
if (!packaged) mainWindow.toggleDevTools(); if (!packaged) mainWindow.toggleDevTools();
electron.session.defaultSession.clearCache(() => { }) electron.session.defaultSession.clearCache(() => {});
if (process.argv) { if (process.argv) {
if (process.argv[1]) { if (process.argv[1]) {
var m = process.argv[1].match(/([a-zA-Z0-9]+)\/\?[a-zA-Z-0-9]+=(.+)/); var m = process.argv[1].match(/([a-zA-Z0-9]+)\/\?[a-zA-Z-0-9]+=(.+)/);
if (m) { if (m) {
var mode = m[1]; var mode = m[1];
var code = m[2]; var code = m[2];
var plus = '?mode=' + mode + '&code=' + code; var plus = "?mode=" + mode + "&code=" + code;
} else { } else {
var plus = ""; var plus = "";
} }
@ -185,56 +186,65 @@ function createWindow() {
} else { } else {
var plus = ""; var plus = "";
} }
mainWindow.loadURL(base + lang + '/index.html' + plus); var ua;
try {
ua = fs.readFileSync(ua_path, "utf8");
} catch (e) {
//default UA Example:
// Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) thedesk/18.11.3 Chrome/76.0.3809.146 Electron/6.0.12 Safari/537.36
const crypto = require("crypto");
const N = 100;
var ua = "Mastodon client: "+crypto
.randomBytes(N)
.toString("base64")
.substring(0, N);
}
mainWindow.loadURL(base + lang + "/index.html" + plus, { userAgent: ua });
if (!window_size.x && !window_size.y) { if (!window_size.x && !window_size.y) {
mainWindow.center(); mainWindow.center();
} }
// ウィンドウが閉じられたらアプリも終了 // ウィンドウが閉じられたらアプリも終了
mainWindow.on('closed', function () { mainWindow.on("closed", function() {
electron.ipcMain.removeAllListeners(); electron.ipcMain.removeAllListeners();
mainWindow = null; mainWindow = null;
}); });
closeArg = false closeArg = false;
mainWindow.on('close', function (e, arg) { mainWindow.on("close", function(e, arg) {
writePos(mainWindow) writePos(mainWindow);
if(!closeArg){ if (!closeArg) {
e.preventDefault() e.preventDefault();
}
const promise = new Promise(function (resolve) {
mainWindow.webContents.send('asReadEnd', "")
setTimeout(function () { resolve() }, 3000)
})
promise.then((function (response) {
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 &&
max_window_size.x == mainWindow.getBounds().x &&
max_window_size.y == mainWindow.getBounds().y
) {
var size = { width: mainWindow.getBounds().width, height: mainWindow.getBounds().height, x: mainWindow.getBounds().x, y: mainWindow.getBounds().y, max: true }
} 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)) const promise = new Promise(function(resolve) {
mainWindow.webContents.send("asReadEnd", "");
setTimeout(function() {
resolve();
}, 3000);
});
promise.then(function(response) {
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 && max_window_size.x == mainWindow.getBounds().x && max_window_size.y == mainWindow.getBounds().y) {
var size = { width: mainWindow.getBounds().width, height: mainWindow.getBounds().height, x: mainWindow.getBounds().x, y: mainWindow.getBounds().y, max: true };
} 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));
} }
mainWindow.on('maximize', function () { mainWindow.on("maximize", function() {
writePos(mainWindow) writePos(mainWindow);
fs.writeFileSync(max_info_path, JSON.stringify(mainWindow.getBounds())); fs.writeFileSync(max_info_path, JSON.stringify(mainWindow.getBounds()));
}); });
mainWindow.on('minimize', function () { mainWindow.on("minimize", function() {
writePos(mainWindow) writePos(mainWindow);
mainWindow.webContents.send('asRead', "") mainWindow.webContents.send("asRead", "");
}) });
var platform = process.platform; var platform = process.platform;
var bit = process.arch; var bit = process.arch;
@ -249,34 +259,36 @@ function createWindow() {
np.TheDeskNowPlaying(mainWindow); np.TheDeskNowPlaying(mainWindow);
//その他system //その他system
systemFunc.system(mainWindow, dir, lang, dirname); systemFunc.system(mainWindow, dir, lang, dirname);
setInterval(function () { mouseTrack(mainWindow) }, 1000); setInterval(function() {
mouseTrack(mainWindow);
}, 1000);
} }
var x = 0 var x = 0;
var y = 0 var y = 0;
var unchanged = 0 var unchanged = 0;
var locked = false var locked = false;
function mouseTrack(mainWindow) { function mouseTrack(mainWindow) {
let mousePos = electron.screen.getCursorScreenPoint() let mousePos = electron.screen.getCursorScreenPoint();
let xNow = mousePos.x let xNow = mousePos.x;
let yNow = mousePos.x let yNow = mousePos.x;
if (x != xNow || y != yNow) { if (x != xNow || y != yNow) {
unchanged = 0 unchanged = 0;
locked = false locked = false;
} else { } else {
unchanged++ unchanged++;
if (unchanged > 60 && !locked) { if (unchanged > 60 && !locked) {
unchanged = 0 unchanged = 0;
locked = true locked = true;
mainWindow.webContents.send('asRead', "") mainWindow.webContents.send("asRead", "");
} }
} }
x = xNow x = xNow;
y = yNow y = yNow;
} }
// Electronの初期化完了後に実行 // Electronの初期化完了後に実行
app.on('ready', createWindow); app.on("ready", createWindow);
var onError = function (err, response) { var onError = function(err, response) {
console.error(err, response); console.error(err, response);
}; };
app.setAsDefaultProtocolClient('thedesk') app.setAsDefaultProtocolClient("thedesk");

View File

@ -9,6 +9,7 @@ function system(mainWindow, dir, lang, dirname) {
const clipboard = electron.clipboard; const clipboard = electron.clipboard;
var tmp_img = join(app.getPath("userData"), "tmp.png"); var tmp_img = join(app.getPath("userData"), "tmp.png");
var ha_path = join(app.getPath("userData"), "hardwareAcceleration"); var ha_path = join(app.getPath("userData"), "hardwareAcceleration");
var ua_path = join(app.getPath("userData"), "useragent");
var lang_path = join(app.getPath("userData"), "language"); var lang_path = join(app.getPath("userData"), "language");
const BrowserWindow = electron.BrowserWindow; const BrowserWindow = electron.BrowserWindow;
const dialog = electron.dialog; const dialog = electron.dialog;
@ -92,6 +93,15 @@ function system(mainWindow, dir, lang, dirname) {
app.relaunch() app.relaunch()
app.exit() app.exit()
}) })
ipc.on('ua', function (e, arg) {
if (arg == "") {
fs.unlink(ua_path, function (err) { });
} else {
fs.writeFileSync(ua_path, arg);
}
app.relaunch()
app.exit()
})
ipc.on('quit', (e, args) => { ipc.on('quit', (e, args) => {
app.quit(); app.quit();

View File

@ -31,6 +31,8 @@
"fontsize": "Font size", "fontsize": "Font size",
"savefolder": "Folder to save", "savefolder": "Folder to save",
"savefolderwarn": "TheDesk uses this value when it try to save pictures or take screenshots.", "savefolderwarn": "TheDesk uses this value when it try to save pictures or take screenshots.",
"useragent":"User agent",
"useragentWarn":"Restart when changed",
"absolute": "absolute value", "absolute": "absolute value",
"themeSel": "Select theme", "themeSel": "Select theme",
"customtheme": "Edit and add custom themes", "customtheme": "Edit and add custom themes",

View File

@ -31,6 +31,8 @@
"fontsize": "フォントサイズ", "fontsize": "フォントサイズ",
"savefolder": "デフォルトの保存先", "savefolder": "デフォルトの保存先",
"savefolderwarn": "画像ダウンロードやスクリーンショットに影響します。", "savefolderwarn": "画像ダウンロードやスクリーンショットに影響します。",
"useragent":"ユーザーエージェント",
"useragentWarn":"再起動します。",
"absolute": "絶対指定", "absolute": "絶対指定",
"themeSel": "テーマの選択", "themeSel": "テーマの選択",
"customtheme": "カスタムテーマの作成・編集", "customtheme": "カスタムテーマの作成・編集",

View File

@ -105,6 +105,18 @@ var envConstruction = [
} }
] ]
} }
},
{
id: "ua",
storage: "ua_setting",
checkbox: false,
doubleText: false,
setValue: "",
width: 200,
text: {
head: "@@useragent@@",
desc: "@@useragentWarn@@"
}
} }
]; ];
var tlConstruction = [ var tlConstruction = [