Change: mainWindow to event.sender on IPC #86

This commit is contained in:
Cutls 2019-06-15 00:51:41 +09:00
parent 367f2f656e
commit 56cca8b529
7 changed files with 76 additions and 74 deletions

View File

@ -46,7 +46,6 @@ function verck(ver) {
}); });
} }
} }
var dialog = remote.dialog;
var platform = localStorage.getItem("platform"); var platform = localStorage.getItem("platform");
console.log("Your platform:" + platform) console.log("Your platform:" + platform)
if (platform == "win32") { if (platform == "win32") {
@ -57,14 +56,7 @@ function verck(ver) {
buttons: [lang.lang_no, lang.lang_yesno] buttons: [lang.lang_no, lang.lang_yesno]
} }
if (!localStorage.getItem("winstore")) { if (!localStorage.getItem("winstore")) {
postMessage(["dialogStore", options], "*")
dialog.showMessageBox(options, function (arg) {
if (arg == 1) {
localStorage.setItem("winstore", "winstore")
} else {
localStorage.setItem("winstore", "localinstall")
}
});
} }
} else if (platform == "linux") { } else if (platform == "linux") {
if (localStorage.getItem("winstore") == "unix") { if (localStorage.getItem("winstore") == "unix") {
@ -77,13 +69,9 @@ function verck(ver) {
message: lang.lang_version_platform_linux, message: lang.lang_version_platform_linux,
buttons: [lang.lang_no, lang.lang_yesno] buttons: [lang.lang_no, lang.lang_yesno]
} }
dialog.showMessageBox(options, function (arg) { if (!localStorage.getItem("winstore")) {
if (arg == 1) { postMessage(["dialogStore", options], "*")
localStorage.setItem("winstore", "snapcraft") }
} else {
localStorage.setItem("winstore", "localinstall")
}
});
} }
} else if (platform == "darwin") { } else if (platform == "darwin") {
if (localStorage.getItem("winstore") == "unix") { if (localStorage.getItem("winstore") == "unix") {
@ -96,13 +84,9 @@ function verck(ver) {
message: lang.lang_version_platform_mac, message: lang.lang_version_platform_mac,
buttons: [lang.lang_no, lang.lang_yesno] buttons: [lang.lang_no, lang.lang_yesno]
} }
dialog.showMessageBox(options, function (arg) { if (!localStorage.getItem("winstore")) {
if (arg == 1) { postMessage(["dialogStore", options], "*")
localStorage.setItem("winstore", "brewcask") }
} else {
localStorage.setItem("winstore", "localinstall")
}
});
} }
} else { } else {
localStorage.setItem("winstore", "unix") localStorage.setItem("winstore", "unix")

View File

@ -8,10 +8,15 @@ onmessage = function (e) {
} }
} }
//version.js
ipc.send("getPlatform", "") ipc.send("getPlatform", "")
ipc.on('platform', function (event, arg) { ipc.on('platform', function (event, arg) {
localStorage.setItem("platform",arg) localStorage.setItem("platform",arg)
}) })
ipc.on('winstore', function (event, arg) {
localStorage.setItem("winstore",arg)
})
ipc.on('reload', function (event, arg) { ipc.on('reload', function (event, arg) {
location.reload(); location.reload();
}) })
@ -36,11 +41,12 @@ ipc.on('shownotf', function (event, args) {
function nano() { function nano() {
ipc.send('nano', ""); ipc.send('nano', "");
} }
/*
var webviewDom = document.getElementById('webview'); var webviewDom = document.getElementById('webview');
const { const {
shell shell
} = require('electron'); } = require('electron');
webviewDom.addEventListener('new-window', function (e) { webviewDom.addEventListener('new-window', function (e) {
shell.openExternal(e.url); shell.openExternal(e.url);
}); });
*/

View File

@ -10,7 +10,7 @@ function css(mainWindow) {
ipc.on('custom-css-create', function (e, arg) { ipc.on('custom-css-create', function (e, arg) {
fs.writeFileSync(customcss, 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) { ipc.on('custom-css-request', function (e, arg) {
try { try {
@ -18,29 +18,29 @@ function css(mainWindow) {
} catch (e) { } catch (e) {
var css = ""; 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) { ipc.on('theme-json-create', function (e, arg) {
var themecss = join(app.getPath("userData"), JSON5.parse(arg)["id"] + var themecss = join(app.getPath("userData"), JSON5.parse(arg)["id"] +
".thedesktheme"); ".thedesktheme");
fs.writeFileSync(themecss, JSON.stringify(JSON5.parse(arg))); fs.writeFileSync(themecss, JSON.stringify(JSON5.parse(arg)));
if (JSON5.parse(arg)["id"]) { if (JSON5.parse(arg)["id"]) {
mainWindow.webContents.send('theme-json-create-complete', ""); e.sender.webContents.send('theme-json-create-complete', "");
} else { } 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) { ipc.on('theme-json-delete', function (e, arg) {
var themecss = join(app.getPath("userData"), arg + ".thedesktheme"); var themecss = join(app.getPath("userData"), arg + ".thedesktheme");
console.log(themecss); console.log(themecss);
fs.unlink(themecss, function (err) { 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) { ipc.on('theme-json-request', function (e, arg) {
var themecss = join(app.getPath("userData"), arg + ".thedesktheme"); var themecss = join(app.getPath("userData"), arg + ".thedesktheme");
var json = JSON.parse(fs.readFileSync(themecss, 'utf8')); 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) { ipc.on('theme-css-request', function (e, arg) {
var themecss = join(app.getPath("userData"), arg + ".thedesktheme"); var themecss = join(app.getPath("userData"), arg + ".thedesktheme");
@ -76,7 +76,7 @@ function css(mainWindow) {
";--active:" + primary + ";--postbox:" + primary + ";--modalfooter:" + ";--active:" + primary + ";--postbox:" + primary + ";--modalfooter:" +
primary + primary +
";}.blacktheme #imagemodal{background: url(\"../img/pixel.svg\");}"; ";}.blacktheme #imagemodal{background: url(\"../img/pixel.svg\");}";
mainWindow.webContents.send('theme-css-response', css); e.sender.webContents.send('theme-css-response', css);
} catch (e) { } catch (e) {
var css = ""; var css = "";
} }
@ -98,7 +98,7 @@ function css(mainWindow) {
id: json.id id: json.id
}) })
} }
mainWindow.webContents.send('theme-json-list-response', themes); e.sender.webContents.send('theme-json-list-response', themes);
}); });
}) })
} }

View File

@ -16,7 +16,7 @@ function dl(mainWindow, lang_path, base) {
if (platform != "others") { if (platform != "others") {
updatewin = new BrowserWindow({ updatewin = new BrowserWindow({
webPreferences: { webPreferences: {
nodeIntegration:true nodeIntegration: true
}, },
width: 600, width: 600,
height: 400, height: 400,
@ -35,7 +35,26 @@ function dl(mainWindow, lang_path, base) {
}) })
//アプデDL //アプデDL
ipc.on('download-btn', (e, args) => { 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 platform = process.platform;
var bit = process.arch; var bit = process.arch;
dialog.showSaveDialog(null, { dialog.showSaveDialog(null, {
@ -55,7 +74,7 @@ function dl(mainWindow, lang_path, base) {
if (isExistFile(savedFiles)) { if (isExistFile(savedFiles)) {
fs.unlinkSync(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) => { ipc.on('general-dl', (e, args) => {
var name = ""; var name = "";
@ -107,14 +107,14 @@ function dl(mainWindow, lang_path, base) {
filename: name, filename: name,
openFolderWhenDone: false, openFolderWhenDone: false,
onProgress: function (e) { onProgress: function (e) {
mainWindow.webContents.send('general-dl-prog', e); e.sender.webContents.send('general-dl-prog', e);
}, },
saveAs: false saveAs: false
}; };
download(BrowserWindow.getFocusedWindow(), download(BrowserWindow.getFocusedWindow(),
args[0], opts) args[0], opts)
.then(dl => { .then(dl => {
mainWindow.webContents.send('general-dl-message', dir); e.sender.webContents.send('general-dl-message', dir);
}) })
.catch(console.error); .catch(console.error);
}); });

View File

@ -24,7 +24,7 @@ function img(mainWindow, dir) {
for (var i = 0; i < fileNames.length; i++) { for (var i = 0; i < fileNames.length; i++) {
var path = fileNames[i]; var path = fileNames[i];
var bin = fs.readFileSync(path, 'base64'); 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) { dialog.showMessageBox(options, function (index) {
if (index === 2) { if (index === 2) {
mainWindow.webContents.send('adobeagree', "true"); e.sender.webContents.send('adobeagree', "true");
} }
if (index > 0) { if (index > 0) {
adobeWindow(); adobeWindow();
@ -65,7 +65,7 @@ function img(mainWindow, dir) {
Jimp.read(args[0], function (err, lenna) { Jimp.read(args[0], function (err, lenna) {
if (err) throw err; if (err) throw err;
lenna.getBase64(Jimp.MIME_PNG, function (err, src) { 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]]);
}); });
}); });

View File

@ -28,11 +28,11 @@ function np(mainWindow) {
try { try {
const nowplaying = require("itunes-nowplaying-mac"); const nowplaying = require("itunes-nowplaying-mac");
const value = await nowplaying.getRawData(); const value = await nowplaying.getRawData();
mainWindow.webContents.send('itunes-np', value); e.sender.webContents.send('itunes-np', value);
} catch (error) { } catch (error) {
// エラーを返す // エラーを返す
console.error(error); console.error(error);
mainWindow.webContents.send('itunes-np', error); e.sender.webContents.send('itunes-np', error);
} }
} else { } else {
var { NowPlaying, PlayerName } = require("nowplaying-node"); var { NowPlaying, PlayerName } = require("nowplaying-node");
@ -62,7 +62,7 @@ function np(mainWindow) {
album: myAIMP.getAlbum(), album: myAIMP.getAlbum(),
path: bin path: bin
} }
mainWindow.webContents.send('itunes-np', value); e.sender.webContents.send('itunes-np', value);
} }
} }

View File

@ -42,15 +42,26 @@ function system(mainWindow, dir, lang) {
}); });
//プラットフォーム //プラットフォーム
ipc.on('getPlatform', function (e, arg) { 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) { ipc.on('lang', function (e, arg) {
console.log("set:" + arg); console.log("set:" + arg);
fs.writeFileSync(lang_path, 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) { ipc.on('ha', function (e, arg) {
@ -93,7 +104,7 @@ function system(mainWindow, dir, lang) {
console.log(lang); console.log(lang);
var options = language.delsel(lang) var options = language.delsel(lang)
dialog.showMessageBox(options, function (index) { 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) { ipc.on('nano', function (e, x, y) {
@ -128,7 +139,13 @@ function system(mainWindow, dir, lang) {
var cbTimer1; var cbTimer1;
ipc.on('startmem', (e, arg) => { 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) => { ipc.on('endmem', (e, arg) => {
if (cbTimer1) { 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) => { ipc.on('export', (e, args) => {
fs.writeFileSync(args[0], args[1]); fs.writeFileSync(args[0], args[1]);
}); });
ipc.on('import', (e, arg) => { 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) { function object_array_sort(data, key, order, fn) {
@ -184,7 +196,7 @@ function system(mainWindow, dir, lang) {
const fm = require('font-manager'); const fm = require('font-manager');
var fonts = fm.getAvailableFontsSync(); var fonts = fm.getAvailableFontsSync();
object_array_sort(fonts, 'family', 'asc', function (fonts_sorted) { object_array_sort(fonts, 'family', 'asc', function (fonts_sorted) {
mainWindow.webContents.send('font-list', fonts_sorted); e.sender.webContents.send('font-list', fonts_sorted);
}); });
}); });
} }