From a70444e3c721ea0aa5524b2ac8ebb0e49d6d82a9 Mon Sep 17 00:00:00 2001 From: Cutls Date: Fri, 14 Jun 2019 23:17:16 +0900 Subject: [PATCH] Introduce: preload and postMessage #86 --- app/js/platform/end.js | 42 ++------------------------------------ app/js/platform/preload.js | 39 +++++++++++++++++++++++++++++++++++ app/main.js | 31 +++++++++++++++++++++++++--- 3 files changed, 69 insertions(+), 43 deletions(-) create mode 100644 app/js/platform/preload.js diff --git a/app/js/platform/end.js b/app/js/platform/end.js index f9b70220..a5477036 100644 --- a/app/js/platform/end.js +++ b/app/js/platform/end.js @@ -60,12 +60,12 @@ $(document).on('click', 'a', e => { //hrefがhttp/httpsならブラウザで if (urls) { if (urls[0]) { - const { shell } = require('electron'); if (~url.indexOf("thedeks.top")) { //alert("If you recieve this alert, let the developer(Cutls@kirishima.cloud) know it with a screenshot."); url = "https://thedesk.top"; } - shell.openExternal(url); + //shell.openExternal(url); + postMessage(["openUrl", url], "*") } else { location.href = url; @@ -88,12 +88,6 @@ function execCopy(string) { var result = document.execCommand('copy'); return result; } -//Nano -function nano() { - var electron = require("electron"); - var ipc = electron.ipcRenderer; - ipc.send('nano', ""); -} function progshow(e) { if (e.lengthComputable) { var percent = e.loaded / e.total; @@ -106,30 +100,6 @@ function progshow(e) { } } } - -var electron = require("electron"); -var ipc = electron.ipcRenderer; -ipc.on('reload', function (event, arg) { - location.reload(); -}) -ipc.on('mess', function (event, arg) { - if (arg == "unzip") { - if (lang == "ja") { - $("body").text("アップデートを展開中です。"); - } else { - $("body").text("Unzipping..."); - } - - } -}) -//Native Notf -ipc.on('shownotf', function (event, args) { - if (args["type"] == "toot") { - details(id, acct_id) - } else if (args["type"] == "userdata") { - udg(user, acct_id) - } -}) function opendev() { var webview = document.getElementById("webview"); webview.openDevTools(); @@ -139,14 +109,6 @@ function opendev() { }); */ } - -var webviewDom = document.getElementById('webview'); -const { - shell -} = require('electron'); -webviewDom.addEventListener('new-window', function (e) { - shell.openExternal(e.url); -}); function playSound() { window.AudioContext = window.AudioContext || window.webkitAudioContext; context = new AudioContext(); diff --git a/app/js/platform/preload.js b/app/js/platform/preload.js new file mode 100644 index 00000000..75f563d0 --- /dev/null +++ b/app/js/platform/preload.js @@ -0,0 +1,39 @@ +var electron = require("electron"); +var ipc = electron.ipcRenderer; +onmessage = function (e) { + if (e.data[0] == "openUrl") { + shell.openExternal(e.data[1]); + } +} +ipc.on('reload', function (event, arg) { + location.reload(); +}) +ipc.on('mess', function (event, arg) { + if (arg == "unzip") { + if (lang == "ja") { + $("body").text("アップデートを展開中です。"); + } else { + $("body").text("Unzipping..."); + } + + } +}) +//Native Notf +ipc.on('shownotf', function (event, args) { + if (args["type"] == "toot") { + details(id, acct_id) + } else if (args["type"] == "userdata") { + udg(user, acct_id) + } +}) +function nano() { + ipc.send('nano', ""); +} + +var webviewDom = document.getElementById('webview'); +const { + shell +} = require('electron'); +webviewDom.addEventListener('new-window', function (e) { + shell.openExternal(e.url); +}); \ No newline at end of file diff --git a/app/main.js b/app/main.js index 42ab82ad..2b47c5b3 100644 --- a/app/main.js +++ b/app/main.js @@ -94,11 +94,36 @@ function createWindow() { var platform = process.platform; var bit = process.arch; if (platform == "linux") { - var arg = { webPreferences: { webviewTag: true, nodeIntegration: true }, width: window_size.width, height: window_size.height, x: window_size.x, y: window_size.y, icon: __dirname + '/desk.png' } + var arg = { + webPreferences: { + webviewTag: false, + nodeIntegration: false, + contextIsolation: true, + preload: dir + "/js/platform/preload.js" + }, + width: window_size.width, height: window_size.height, x: window_size.x, y: window_size.y, icon: __dirname + '/desk.png' + } } else if (platform == "win32") { - var arg = {webPreferences: { webviewTag: true, nodeIntegration: true }, width: window_size.width, height: window_size.height, x: window_size.x, y: window_size.y, simpleFullscreen: true } + console.log(join(__dirname,"js", "platform", "preload.js")) + var arg = { + webPreferences: { + webviewTag: false, + nodeIntegration: false, + contextIsolation: true, + 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 + } } else if (platform == "darwin") { - var arg = { webPreferences: { webviewTag: true, nodeIntegration: true }, width: window_size.width, height: window_size.height, x: window_size.x, y: window_size.y, simpleFullscreen: true } + var arg = { + webPreferences: { + webviewTag: false, + nodeIntegration: false, + contextIsolation: true, + preload: dir + "/js/platform/preload.js" + }, + width: window_size.width, height: window_size.height, x: window_size.x, y: window_size.y, simpleFullscreen: true + } } mainWindow = new BrowserWindow(arg); electron.session.defaultSession.clearCache(() => { })