Introduce: preload and postMessage #86

This commit is contained in:
Cutls 2019-06-14 23:17:16 +09:00
parent 1a72033571
commit a70444e3c7
3 changed files with 69 additions and 43 deletions

View File

@ -60,12 +60,12 @@ $(document).on('click', 'a', e => {
//hrefがhttp/httpsならブラウザで //hrefがhttp/httpsならブラウザで
if (urls) { if (urls) {
if (urls[0]) { if (urls[0]) {
const { shell } = require('electron');
if (~url.indexOf("thedeks.top")) { if (~url.indexOf("thedeks.top")) {
//alert("If you recieve this alert, let the developer(Cutls@kirishima.cloud) know it with a screenshot."); //alert("If you recieve this alert, let the developer(Cutls@kirishima.cloud) know it with a screenshot.");
url = "https://thedesk.top"; url = "https://thedesk.top";
} }
shell.openExternal(url); //shell.openExternal(url);
postMessage(["openUrl", url], "*")
} else { } else {
location.href = url; location.href = url;
@ -88,12 +88,6 @@ function execCopy(string) {
var result = document.execCommand('copy'); var result = document.execCommand('copy');
return result; return result;
} }
//Nano
function nano() {
var electron = require("electron");
var ipc = electron.ipcRenderer;
ipc.send('nano', "");
}
function progshow(e) { function progshow(e) {
if (e.lengthComputable) { if (e.lengthComputable) {
var percent = e.loaded / e.total; 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() { function opendev() {
var webview = document.getElementById("webview"); var webview = document.getElementById("webview");
webview.openDevTools(); 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() { function playSound() {
window.AudioContext = window.AudioContext || window.webkitAudioContext; window.AudioContext = window.AudioContext || window.webkitAudioContext;
context = new AudioContext(); context = new AudioContext();

View File

@ -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);
});

View File

@ -94,11 +94,36 @@ function createWindow() {
var platform = process.platform; var platform = process.platform;
var bit = process.arch; var bit = process.arch;
if (platform == "linux") { 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") { } 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") { } 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); mainWindow = new BrowserWindow(arg);
electron.session.defaultSession.clearCache(() => { }) electron.session.defaultSession.clearCache(() => { })