Change: mainWindow to event.sender on IPC #86
This commit is contained in:
		@@ -46,7 +46,6 @@ function verck(ver) {
 | 
			
		||||
				});
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	var dialog = remote.dialog;
 | 
			
		||||
	var platform = localStorage.getItem("platform");
 | 
			
		||||
	console.log("Your platform:" + platform)
 | 
			
		||||
	if (platform == "win32") {
 | 
			
		||||
@@ -57,14 +56,7 @@ function verck(ver) {
 | 
			
		||||
			buttons: [lang.lang_no, lang.lang_yesno]
 | 
			
		||||
		}
 | 
			
		||||
		if (!localStorage.getItem("winstore")) {
 | 
			
		||||
 | 
			
		||||
			dialog.showMessageBox(options, function (arg) {
 | 
			
		||||
				if (arg == 1) {
 | 
			
		||||
					localStorage.setItem("winstore", "winstore")
 | 
			
		||||
				} else {
 | 
			
		||||
					localStorage.setItem("winstore", "localinstall")
 | 
			
		||||
				}
 | 
			
		||||
			});
 | 
			
		||||
			postMessage(["dialogStore", options], "*")
 | 
			
		||||
		}
 | 
			
		||||
	} else if (platform == "linux") {
 | 
			
		||||
		if (localStorage.getItem("winstore") == "unix") {
 | 
			
		||||
@@ -77,13 +69,9 @@ function verck(ver) {
 | 
			
		||||
				message: lang.lang_version_platform_linux,
 | 
			
		||||
				buttons: [lang.lang_no, lang.lang_yesno]
 | 
			
		||||
			}
 | 
			
		||||
			dialog.showMessageBox(options, function (arg) {
 | 
			
		||||
				if (arg == 1) {
 | 
			
		||||
					localStorage.setItem("winstore", "snapcraft")
 | 
			
		||||
				} else {
 | 
			
		||||
					localStorage.setItem("winstore", "localinstall")
 | 
			
		||||
			if (!localStorage.getItem("winstore")) {
 | 
			
		||||
				postMessage(["dialogStore", options], "*")
 | 
			
		||||
			}
 | 
			
		||||
			});
 | 
			
		||||
		}
 | 
			
		||||
	} else if (platform == "darwin") {
 | 
			
		||||
		if (localStorage.getItem("winstore") == "unix") {
 | 
			
		||||
@@ -96,13 +84,9 @@ function verck(ver) {
 | 
			
		||||
				message: lang.lang_version_platform_mac,
 | 
			
		||||
				buttons: [lang.lang_no, lang.lang_yesno]
 | 
			
		||||
			}
 | 
			
		||||
			dialog.showMessageBox(options, function (arg) {
 | 
			
		||||
				if (arg == 1) {
 | 
			
		||||
					localStorage.setItem("winstore", "brewcask")
 | 
			
		||||
				} else {
 | 
			
		||||
					localStorage.setItem("winstore", "localinstall")
 | 
			
		||||
			if (!localStorage.getItem("winstore")) {
 | 
			
		||||
				postMessage(["dialogStore", options], "*")
 | 
			
		||||
			}
 | 
			
		||||
			});
 | 
			
		||||
		}
 | 
			
		||||
	} else {
 | 
			
		||||
		localStorage.setItem("winstore", "unix")
 | 
			
		||||
 
 | 
			
		||||
@@ -8,10 +8,15 @@ onmessage = function (e) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
//version.js
 | 
			
		||||
ipc.send("getPlatform", "")
 | 
			
		||||
ipc.on('platform', function (event, arg) {
 | 
			
		||||
    localStorage.setItem("platform",arg)
 | 
			
		||||
})
 | 
			
		||||
ipc.on('winstore', function (event, arg) {
 | 
			
		||||
    localStorage.setItem("winstore",arg)
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
ipc.on('reload', function (event, arg) {
 | 
			
		||||
    location.reload();
 | 
			
		||||
})
 | 
			
		||||
@@ -36,7 +41,7 @@ ipc.on('shownotf', function (event, args) {
 | 
			
		||||
function nano() {
 | 
			
		||||
    ipc.send('nano', "");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
var webviewDom = document.getElementById('webview');
 | 
			
		||||
const {
 | 
			
		||||
    shell
 | 
			
		||||
@@ -44,3 +49,4 @@ const {
 | 
			
		||||
webviewDom.addEventListener('new-window', function (e) {
 | 
			
		||||
    shell.openExternal(e.url);
 | 
			
		||||
});
 | 
			
		||||
*/
 | 
			
		||||
@@ -10,7 +10,7 @@ function css(mainWindow) {
 | 
			
		||||
 | 
			
		||||
	ipc.on('custom-css-create', function (e, arg) {
 | 
			
		||||
		fs.writeFileSync(customcss, arg);
 | 
			
		||||
		mainWindow.webContents.send('custom-css-create-complete', "");
 | 
			
		||||
		e.sender.webContents.send('custom-css-create-complete', "");
 | 
			
		||||
	})
 | 
			
		||||
	ipc.on('custom-css-request', function (e, arg) {
 | 
			
		||||
		try {
 | 
			
		||||
@@ -18,29 +18,29 @@ function css(mainWindow) {
 | 
			
		||||
		} catch (e) {
 | 
			
		||||
			var css = "";
 | 
			
		||||
		}
 | 
			
		||||
		mainWindow.webContents.send('custom-css-response', css);
 | 
			
		||||
		e.sender.webContents.send('custom-css-response', css);
 | 
			
		||||
	})
 | 
			
		||||
	ipc.on('theme-json-create', function (e, arg) {
 | 
			
		||||
		var themecss = join(app.getPath("userData"), JSON5.parse(arg)["id"] +
 | 
			
		||||
			".thedesktheme");
 | 
			
		||||
		fs.writeFileSync(themecss, JSON.stringify(JSON5.parse(arg)));
 | 
			
		||||
		if (JSON5.parse(arg)["id"]) {
 | 
			
		||||
			mainWindow.webContents.send('theme-json-create-complete', "");
 | 
			
		||||
			e.sender.webContents.send('theme-json-create-complete', "");
 | 
			
		||||
		} else {
 | 
			
		||||
			mainWindow.webContents.send('theme-json-create-complete', "error");
 | 
			
		||||
			e.sender.webContents.send('theme-json-create-complete', "error");
 | 
			
		||||
		}
 | 
			
		||||
	})
 | 
			
		||||
	ipc.on('theme-json-delete', function (e, arg) {
 | 
			
		||||
		var themecss = join(app.getPath("userData"), arg + ".thedesktheme");
 | 
			
		||||
		console.log(themecss);
 | 
			
		||||
		fs.unlink(themecss, function (err) {
 | 
			
		||||
			mainWindow.webContents.send('theme-json-delete-complete', "");
 | 
			
		||||
			e.sender.webContents.send('theme-json-delete-complete', "");
 | 
			
		||||
		});
 | 
			
		||||
	})
 | 
			
		||||
	ipc.on('theme-json-request', function (e, arg) {
 | 
			
		||||
		var themecss = join(app.getPath("userData"), arg + ".thedesktheme");
 | 
			
		||||
		var json = JSON.parse(fs.readFileSync(themecss, 'utf8'));
 | 
			
		||||
		mainWindow.webContents.send('theme-json-response', json);
 | 
			
		||||
		e.sender.webContents.send('theme-json-response', json);
 | 
			
		||||
	})
 | 
			
		||||
	ipc.on('theme-css-request', function (e, arg) {
 | 
			
		||||
		var themecss = join(app.getPath("userData"), arg + ".thedesktheme");
 | 
			
		||||
@@ -76,7 +76,7 @@ function css(mainWindow) {
 | 
			
		||||
				";--active:" + primary + ";--postbox:" + primary + ";--modalfooter:" +
 | 
			
		||||
				primary +
 | 
			
		||||
				";}.blacktheme #imagemodal{background: url(\"../img/pixel.svg\");}";
 | 
			
		||||
			mainWindow.webContents.send('theme-css-response', css);
 | 
			
		||||
			e.sender.webContents.send('theme-css-response', css);
 | 
			
		||||
		} catch (e) {
 | 
			
		||||
			var css = "";
 | 
			
		||||
		}
 | 
			
		||||
@@ -98,7 +98,7 @@ function css(mainWindow) {
 | 
			
		||||
					id: json.id
 | 
			
		||||
				})
 | 
			
		||||
			}
 | 
			
		||||
			mainWindow.webContents.send('theme-json-list-response', themes);
 | 
			
		||||
			e.sender.webContents.send('theme-json-list-response', themes);
 | 
			
		||||
		});
 | 
			
		||||
	})
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -35,7 +35,26 @@ function dl(mainWindow, lang_path, base) {
 | 
			
		||||
	})
 | 
			
		||||
	//アプデDL
 | 
			
		||||
	ipc.on('download-btn', (e, args) => {
 | 
			
		||||
		function dl(url, file, dir,e) {
 | 
			
		||||
 | 
			
		||||
			e.sender.webContents.send('mess', "ダウンロードを開始します。");
 | 
			
		||||
			const opts = {
 | 
			
		||||
				directory: dir,
 | 
			
		||||
				openFolderWhenDone: true,
 | 
			
		||||
				onProgress: function (e) {
 | 
			
		||||
					e.sender.webContents.send('prog', e);
 | 
			
		||||
				},
 | 
			
		||||
				saveAs: false
 | 
			
		||||
			};
 | 
			
		||||
			download(updatewin,
 | 
			
		||||
				url, opts)
 | 
			
		||||
				.then(dl => {
 | 
			
		||||
					e.sender.webContents.send('mess', "ダウンロードが完了しました。");
 | 
			
		||||
					app.quit();
 | 
			
		||||
 | 
			
		||||
				})
 | 
			
		||||
				.catch(console.error);
 | 
			
		||||
		}
 | 
			
		||||
		var platform = process.platform;
 | 
			
		||||
		var bit = process.arch;
 | 
			
		||||
		dialog.showSaveDialog(null, {
 | 
			
		||||
@@ -55,7 +74,7 @@ function dl(mainWindow, lang_path, base) {
 | 
			
		||||
			if (isExistFile(savedFiles)) {
 | 
			
		||||
				fs.unlinkSync(savedFiles);
 | 
			
		||||
			}
 | 
			
		||||
			dl(args[0], args[1], m[1]);
 | 
			
		||||
			dl(args[0], args[1], m[1], e);
 | 
			
		||||
		});
 | 
			
		||||
	});
 | 
			
		||||
 | 
			
		||||
@@ -68,26 +87,7 @@ function dl(mainWindow, lang_path, base) {
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	function dl(url, file, dir) {
 | 
			
		||||
 | 
			
		||||
		updatewin.webContents.send('mess', "ダウンロードを開始します。");
 | 
			
		||||
		const opts = {
 | 
			
		||||
			directory: dir,
 | 
			
		||||
			openFolderWhenDone: true,
 | 
			
		||||
			onProgress: function (e) {
 | 
			
		||||
				updatewin.webContents.send('prog', e);
 | 
			
		||||
			},
 | 
			
		||||
			saveAs: false
 | 
			
		||||
		};
 | 
			
		||||
		download(updatewin,
 | 
			
		||||
			url, opts)
 | 
			
		||||
			.then(dl => {
 | 
			
		||||
				updatewin.webContents.send('mess', "ダウンロードが完了しました。");
 | 
			
		||||
				app.quit();
 | 
			
		||||
 | 
			
		||||
			})
 | 
			
		||||
			.catch(console.error);
 | 
			
		||||
	}
 | 
			
		||||
	ipc.on('general-dl', (e, args) => {
 | 
			
		||||
 | 
			
		||||
		var name = "";
 | 
			
		||||
@@ -107,14 +107,14 @@ function dl(mainWindow, lang_path, base) {
 | 
			
		||||
			filename: name,
 | 
			
		||||
			openFolderWhenDone: false,
 | 
			
		||||
			onProgress: function (e) {
 | 
			
		||||
				mainWindow.webContents.send('general-dl-prog', e);
 | 
			
		||||
				e.sender.webContents.send('general-dl-prog', e);
 | 
			
		||||
			},
 | 
			
		||||
			saveAs: false
 | 
			
		||||
		};
 | 
			
		||||
		download(BrowserWindow.getFocusedWindow(),
 | 
			
		||||
			args[0], opts)
 | 
			
		||||
			.then(dl => {
 | 
			
		||||
				mainWindow.webContents.send('general-dl-message', dir);
 | 
			
		||||
				e.sender.webContents.send('general-dl-message', dir);
 | 
			
		||||
			})
 | 
			
		||||
			.catch(console.error);
 | 
			
		||||
	});
 | 
			
		||||
 
 | 
			
		||||
@@ -24,7 +24,7 @@ function img(mainWindow, dir) {
 | 
			
		||||
            for (var i = 0; i < fileNames.length; i++) {
 | 
			
		||||
                var path = fileNames[i];
 | 
			
		||||
                var bin = fs.readFileSync(path, 'base64');
 | 
			
		||||
                mainWindow.webContents.send('bmp-img-comp', [bin, 'new']);
 | 
			
		||||
                e.sender.webContents.send('bmp-img-comp', [bin, 'new']);
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
    });
 | 
			
		||||
@@ -39,7 +39,7 @@ function img(mainWindow, dir) {
 | 
			
		||||
            }
 | 
			
		||||
            dialog.showMessageBox(options, function (index) {
 | 
			
		||||
                if (index === 2) {
 | 
			
		||||
                    mainWindow.webContents.send('adobeagree', "true");
 | 
			
		||||
                    e.sender.webContents.send('adobeagree', "true");
 | 
			
		||||
                }
 | 
			
		||||
                if (index > 0) {
 | 
			
		||||
                    adobeWindow();
 | 
			
		||||
@@ -65,7 +65,7 @@ function img(mainWindow, dir) {
 | 
			
		||||
        Jimp.read(args[0], function (err, lenna) {
 | 
			
		||||
            if (err) throw err;
 | 
			
		||||
            lenna.getBase64(Jimp.MIME_PNG, function (err, src) {
 | 
			
		||||
                mainWindow.webContents.send('bmp-img-comp', [src, args[1]]);
 | 
			
		||||
                e.sender.webContents.send('bmp-img-comp', [src, args[1]]);
 | 
			
		||||
            });
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -28,11 +28,11 @@ function np(mainWindow) {
 | 
			
		||||
                try {
 | 
			
		||||
                    const nowplaying = require("itunes-nowplaying-mac");
 | 
			
		||||
                    const value = await nowplaying.getRawData();
 | 
			
		||||
                    mainWindow.webContents.send('itunes-np', value);
 | 
			
		||||
                    e.sender.webContents.send('itunes-np', value);
 | 
			
		||||
                } catch (error) {
 | 
			
		||||
                    // エラーを返す
 | 
			
		||||
                    console.error(error);
 | 
			
		||||
                    mainWindow.webContents.send('itunes-np', error);
 | 
			
		||||
                    e.sender.webContents.send('itunes-np', error);
 | 
			
		||||
                }
 | 
			
		||||
            } else {
 | 
			
		||||
                var { NowPlaying, PlayerName } = require("nowplaying-node");
 | 
			
		||||
@@ -62,7 +62,7 @@ function np(mainWindow) {
 | 
			
		||||
                    album: myAIMP.getAlbum(),
 | 
			
		||||
                    path: bin
 | 
			
		||||
                }
 | 
			
		||||
                mainWindow.webContents.send('itunes-np', value);
 | 
			
		||||
                e.sender.webContents.send('itunes-np', value);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -42,15 +42,26 @@ function system(mainWindow, dir, lang) {
 | 
			
		||||
	});
 | 
			
		||||
	//プラットフォーム
 | 
			
		||||
	ipc.on('getPlatform', function (e, arg) {
 | 
			
		||||
		mainWindow.webContents.send('platform', process.platform);
 | 
			
		||||
		e.sender.webContents.send('platform', process.platform);
 | 
			
		||||
	})
 | 
			
		||||
	//言語
 | 
			
		||||
	ipc.on('lang', function (e, arg) {
 | 
			
		||||
 | 
			
		||||
		console.log("set:" + arg);
 | 
			
		||||
		fs.writeFileSync(lang_path, arg);
 | 
			
		||||
		mainWindow.webContents.send('langres', "");
 | 
			
		||||
		e.sender.webContents.send('langres', "");
 | 
			
		||||
	})
 | 
			
		||||
	//ストアから入れたかダイアログ
 | 
			
		||||
	ipc.on('dialogStore', function (e, args) {
 | 
			
		||||
		dialog.showMessageBox(args, function (arg) {
 | 
			
		||||
			if (arg == 1) {
 | 
			
		||||
				e.sender.webContents.send('winstore', "winstore");
 | 
			
		||||
			} else {
 | 
			
		||||
				e.sender.webContents.send('winstore', "localinstall");
 | 
			
		||||
			}
 | 
			
		||||
		});
 | 
			
		||||
	})
 | 
			
		||||
	
 | 
			
		||||
	//ハードウェアアクセラレーションの無効化
 | 
			
		||||
	ipc.on('ha', function (e, arg) {
 | 
			
		||||
 | 
			
		||||
@@ -93,7 +104,7 @@ function system(mainWindow, dir, lang) {
 | 
			
		||||
		console.log(lang);
 | 
			
		||||
		var options = language.delsel(lang)
 | 
			
		||||
		dialog.showMessageBox(options, function (index) {
 | 
			
		||||
			mainWindow.webContents.send('column-del-reply', index);
 | 
			
		||||
			e.sender.webContents.send('column-del-reply', index);
 | 
			
		||||
		})
 | 
			
		||||
	});
 | 
			
		||||
	ipc.on('nano', function (e, x, y) {
 | 
			
		||||
@@ -128,7 +139,13 @@ function system(mainWindow, dir, lang) {
 | 
			
		||||
 | 
			
		||||
	var cbTimer1;
 | 
			
		||||
	ipc.on('startmem', (e, arg) => {
 | 
			
		||||
		cbTimer1 = setInterval(mems, 1000);
 | 
			
		||||
		cbTimer1 = setInterval(mems(e), 1000);
 | 
			
		||||
		function mems(e) {
 | 
			
		||||
			var mem = os.totalmem() - os.freemem();
 | 
			
		||||
			if (mainWindow) {
 | 
			
		||||
				e.sender.webContents.send('memory', [mem, os.cpus()[0].model, os.totalmem()]);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	});
 | 
			
		||||
	ipc.on('endmem', (e, arg) => {
 | 
			
		||||
		if (cbTimer1) {
 | 
			
		||||
@@ -136,17 +153,12 @@ function system(mainWindow, dir, lang) {
 | 
			
		||||
		}
 | 
			
		||||
	});
 | 
			
		||||
 | 
			
		||||
	function mems() {
 | 
			
		||||
		var mem = os.totalmem() - os.freemem();
 | 
			
		||||
		if (mainWindow) {
 | 
			
		||||
			mainWindow.webContents.send('memory', [mem, os.cpus()[0].model, os.totalmem()]);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	ipc.on('export', (e, args) => {
 | 
			
		||||
		fs.writeFileSync(args[0], args[1]);
 | 
			
		||||
	});
 | 
			
		||||
	ipc.on('import', (e, arg) => {
 | 
			
		||||
		mainWindow.webContents.send('config', fs.readFileSync(arg, 'utf8'));
 | 
			
		||||
		e.sender.webContents.send('config', fs.readFileSync(arg, 'utf8'));
 | 
			
		||||
	});
 | 
			
		||||
	//フォント
 | 
			
		||||
	function object_array_sort(data, key, order, fn) {
 | 
			
		||||
@@ -184,7 +196,7 @@ function system(mainWindow, dir, lang) {
 | 
			
		||||
		const fm = require('font-manager');
 | 
			
		||||
		var fonts = fm.getAvailableFontsSync();
 | 
			
		||||
		object_array_sort(fonts, 'family', 'asc', function (fonts_sorted) {
 | 
			
		||||
			mainWindow.webContents.send('font-list', fonts_sorted);
 | 
			
		||||
			e.sender.webContents.send('font-list', fonts_sorted);
 | 
			
		||||
		});
 | 
			
		||||
	});
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user