2019-04-03 14:59:29 +11:00
|
|
|
function system(mainWindow, dir, lang) {
|
2019-05-19 17:39:30 +10:00
|
|
|
const electron = require("electron");
|
|
|
|
const app = electron.app;
|
2019-04-03 14:59:29 +11:00
|
|
|
const join = require('path').join;
|
|
|
|
var Jimp = require("jimp");
|
|
|
|
const fs = require("fs");
|
|
|
|
var ipc = electron.ipcMain;
|
|
|
|
var tmp_img = join(app.getPath("userData"), "tmp.png");
|
|
|
|
var ha_path = join(app.getPath("userData"), "hardwareAcceleration");
|
|
|
|
var lang_path = join(app.getPath("userData"), "language");
|
|
|
|
const BrowserWindow = electron.BrowserWindow;
|
|
|
|
const dialog = electron.dialog;
|
|
|
|
const os = require('os')
|
2019-05-19 17:39:30 +10:00
|
|
|
const language = require("../main/language.js");
|
|
|
|
ipc.on('native-notf', function (e, args) {
|
|
|
|
|
2019-04-03 14:59:29 +11:00
|
|
|
var platform = process.platform;
|
|
|
|
var bit = process.arch;
|
|
|
|
if (platform == "win32") {
|
|
|
|
const notifier = require('node-notifier')
|
|
|
|
var tmp_imge = tmp_img;
|
2019-05-19 17:39:30 +10:00
|
|
|
Jimp.read(args[2], function (err, lenna) {
|
2019-04-03 14:59:29 +11:00
|
|
|
if (!err && lenna) {
|
|
|
|
lenna.write(tmp_img);
|
|
|
|
var tmp_imge = tmp_img;
|
|
|
|
} else {
|
|
|
|
var tmp_imge = "";
|
|
|
|
}
|
|
|
|
notifier.notify({
|
2019-05-19 17:39:30 +10:00
|
|
|
appID: "top.thedesk",
|
|
|
|
message: args[1],
|
|
|
|
title: args[0],
|
|
|
|
icon: tmp_imge,
|
|
|
|
sound: false,
|
|
|
|
wait: true,
|
|
|
|
},
|
|
|
|
function (err, response) {
|
2019-04-03 14:59:29 +11:00
|
|
|
console.log(err, response)
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
//言語
|
2019-05-19 17:39:30 +10:00
|
|
|
ipc.on('lang', function (e, arg) {
|
|
|
|
|
|
|
|
console.log("set:" + arg);
|
|
|
|
fs.writeFileSync(lang_path, arg);
|
|
|
|
mainWindow.webContents.send('langres', "");
|
|
|
|
})
|
|
|
|
//ハードウェアアクセラレーションの無効化
|
|
|
|
ipc.on('ha', function (e, arg) {
|
|
|
|
|
2019-04-03 14:59:29 +11:00
|
|
|
if (arg == "true") {
|
|
|
|
fs.writeFileSync(ha_path, arg);
|
|
|
|
} else {
|
2019-05-19 17:39:30 +10:00
|
|
|
fs.unlink(ha_path, function (err) { });
|
2019-04-03 14:59:29 +11:00
|
|
|
}
|
|
|
|
app.relaunch()
|
|
|
|
app.exit()
|
|
|
|
})
|
|
|
|
|
|
|
|
ipc.on('quit', (e, args) => {
|
2019-05-19 17:39:30 +10:00
|
|
|
|
2019-04-03 14:59:29 +11:00
|
|
|
app.quit();
|
|
|
|
});
|
|
|
|
ipc.on('about', (e, args) => {
|
2019-05-19 17:39:30 +10:00
|
|
|
|
2019-04-03 14:59:29 +11:00
|
|
|
about();
|
|
|
|
});
|
|
|
|
|
|
|
|
function about() {
|
2019-05-19 17:39:30 +10:00
|
|
|
|
2019-04-03 14:59:29 +11:00
|
|
|
var ver = app.getVersion()
|
|
|
|
var window = new BrowserWindow({
|
2019-05-19 20:24:27 +10:00
|
|
|
webPreferences: {
|
|
|
|
nodeIntegration:true
|
|
|
|
},
|
2019-04-03 14:59:29 +11:00
|
|
|
width: 300,
|
2019-05-11 02:31:15 +10:00
|
|
|
height: 480,
|
2019-04-03 14:59:29 +11:00
|
|
|
"transparent": false, // ウィンドウの背景を透過
|
|
|
|
"frame": false, // 枠の無いウィンドウ
|
|
|
|
"resizable": false
|
|
|
|
});
|
|
|
|
window.loadURL(dir + '/about.html?ver=' + ver);
|
|
|
|
return "true"
|
|
|
|
}
|
|
|
|
ipc.on('column-del', (e, args) => {
|
2019-05-19 17:39:30 +10:00
|
|
|
|
2019-04-03 14:59:29 +11:00
|
|
|
console.log(lang);
|
|
|
|
var options = language.delsel(lang)
|
2019-05-19 17:39:30 +10:00
|
|
|
dialog.showMessageBox(options, function (index) {
|
2019-04-03 14:59:29 +11:00
|
|
|
mainWindow.webContents.send('column-del-reply', index);
|
|
|
|
})
|
|
|
|
});
|
2019-05-19 17:39:30 +10:00
|
|
|
ipc.on('nano', function (e, x, y) {
|
|
|
|
|
2019-04-03 14:59:29 +11:00
|
|
|
var nano_info_path = join(app.getPath("userData"),
|
|
|
|
"nano-window-position.json");
|
|
|
|
var window_pos;
|
|
|
|
try {
|
|
|
|
window_pos = JSON.parse(fs.readFileSync(nano_info_path, 'utf8'));
|
|
|
|
} catch (e) {
|
|
|
|
window_pos = [0, 0]; // デフォルトバリュー
|
|
|
|
}
|
|
|
|
var nanowindow = new BrowserWindow({
|
2019-05-19 20:24:27 +10:00
|
|
|
webPreferences: {
|
|
|
|
nodeIntegration:true
|
|
|
|
},
|
2019-04-03 14:59:29 +11:00
|
|
|
width: 350,
|
|
|
|
height: 200,
|
|
|
|
"transparent": false, // ウィンドウの背景を透過
|
|
|
|
"frame": false, // 枠の無いウィンドウ
|
|
|
|
"resizable": false
|
|
|
|
});
|
|
|
|
nanowindow.loadURL(dir + '/nano.html');
|
|
|
|
nanowindow.setAlwaysOnTop(true);
|
|
|
|
|
|
|
|
nanowindow.setPosition(window_pos[0], window_pos[1]);
|
2019-05-19 17:39:30 +10:00
|
|
|
nanowindow.on('close', function () {
|
2019-04-03 14:59:29 +11:00
|
|
|
fs.writeFileSync(nano_info_path, JSON.stringify(nanowindow.getPosition()));
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
})
|
|
|
|
|
|
|
|
var cbTimer1;
|
|
|
|
ipc.on('startmem', (e, arg) => {
|
|
|
|
cbTimer1 = setInterval(mems, 1000);
|
|
|
|
});
|
|
|
|
ipc.on('endmem', (e, arg) => {
|
|
|
|
if (cbTimer1) {
|
|
|
|
clearInterval(cbTimer1);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
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'));
|
|
|
|
});
|
|
|
|
//フォント
|
|
|
|
function object_array_sort(data, key, order, fn) {
|
|
|
|
//デフォは降順(DESC)
|
|
|
|
var num_a = -1;
|
|
|
|
var num_b = 1;
|
|
|
|
|
|
|
|
if (order === 'asc') { //指定があれば昇順(ASC)
|
|
|
|
num_a = 1;
|
|
|
|
num_b = -1;
|
|
|
|
}
|
|
|
|
|
2019-05-19 17:39:30 +10:00
|
|
|
data = data.sort(function (a, b) {
|
2019-04-03 14:59:29 +11:00
|
|
|
var x = a[key];
|
|
|
|
var y = b[key];
|
|
|
|
if (x > y) return num_a;
|
|
|
|
if (x < y) return num_b;
|
|
|
|
return 0;
|
|
|
|
});
|
|
|
|
|
|
|
|
//重複排除
|
|
|
|
var arrObj = {};
|
|
|
|
for (var i = 0; i < data.length; i++) {
|
|
|
|
arrObj[data[i]['family']] = data[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
data = [];
|
|
|
|
for (var key in arrObj) {
|
|
|
|
data.push(arrObj[key]);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn(data); // ソート後の配列を返す
|
|
|
|
}
|
|
|
|
ipc.on('fonts', (e, arg) => {
|
2019-04-13 03:31:07 +10:00
|
|
|
const fm = require('font-manager');
|
2019-04-03 14:59:29 +11:00
|
|
|
var fonts = fm.getAvailableFontsSync();
|
2019-05-19 17:39:30 +10:00
|
|
|
object_array_sort(fonts, 'family', 'asc', function (fonts_sorted) {
|
2019-04-03 14:59:29 +11:00
|
|
|
mainWindow.webContents.send('font-list', fonts_sorted);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
exports.system = system;
|