2019-06-15 19:52:28 +10:00
|
|
|
function system(mainWindow, dir, lang, dirname) {
|
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");
|
2019-08-29 02:20:47 +10:00
|
|
|
var JSON5 = require('json5');
|
2019-04-03 14:59:29 +11:00
|
|
|
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-06-15 00:25:27 +10:00
|
|
|
//プラットフォーム
|
|
|
|
ipc.on('getPlatform', function (e, arg) {
|
2019-08-26 01:09:01 +10:00
|
|
|
try {
|
|
|
|
var gitHash = fs.readFileSync("git", 'utf8')
|
|
|
|
} catch{
|
|
|
|
var gitHash = null
|
|
|
|
}
|
|
|
|
e.sender.webContents.send('platform', [process.platform, process.arch, process.version, process.versions.chrome, process.versions.electron, gitHash]);
|
2019-06-15 00:25:27 +10:00
|
|
|
})
|
2019-04-03 14:59:29 +11:00
|
|
|
//言語
|
2019-05-19 17:39:30 +10:00
|
|
|
ipc.on('lang', function (e, arg) {
|
|
|
|
|
|
|
|
console.log("set:" + arg);
|
|
|
|
fs.writeFileSync(lang_path, arg);
|
2019-08-07 10:24:52 +10:00
|
|
|
e.sender.webContents.send('langres', arg);
|
2019-05-19 17:39:30 +10:00
|
|
|
})
|
2019-06-15 03:01:38 +10:00
|
|
|
//エクスポートのダイアログ
|
|
|
|
ipc.on('exportSettings', function (e, args) {
|
|
|
|
dialog.showSaveDialog(null, {
|
|
|
|
title: 'Export',
|
|
|
|
properties: ['openFile', 'createDirectory'],
|
2019-08-29 02:20:47 +10:00
|
|
|
defaultPath: "export.thedeskconfig.json5"
|
2019-06-15 03:01:38 +10:00
|
|
|
}, (savedFiles) => {
|
|
|
|
if (!savedFiles) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
e.sender.webContents.send('exportSettingsFile', savedFiles);
|
|
|
|
})
|
|
|
|
})
|
|
|
|
//インポートのダイアログ
|
|
|
|
ipc.on('importSettings', function (e, args) {
|
|
|
|
dialog.showOpenDialog(null, {
|
|
|
|
title: 'Import',
|
|
|
|
properties: ['openFile'],
|
|
|
|
filters: [
|
2019-08-29 02:20:47 +10:00
|
|
|
{ name: 'TheDesk Config', extensions: ['thedeskconfig', 'thedeskconfigv2', 'json5'] },
|
2019-06-15 03:01:38 +10:00
|
|
|
]
|
|
|
|
}, (fileNames) => {
|
|
|
|
if (!fileNames) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-08-29 02:20:47 +10:00
|
|
|
e.sender.webContents.send('config', JSON5.parse(fs.readFileSync(fileNames[0], 'utf8')));
|
2019-06-15 03:01:38 +10:00
|
|
|
})
|
|
|
|
})
|
|
|
|
//保存フォルダのダイアログ
|
|
|
|
ipc.on('savefolder', function (e, args) {
|
|
|
|
dialog.showOpenDialog(null, {
|
|
|
|
title: 'Save folder',
|
|
|
|
properties: ['openDirectory'],
|
|
|
|
}, (fileNames) => {
|
|
|
|
e.sender.webContents.send('savefolder', fileNames[0]);
|
|
|
|
});
|
|
|
|
})
|
|
|
|
//カスタムサウンドのダイアログ
|
|
|
|
ipc.on('customSound', function (e, arg) {
|
|
|
|
dialog.showOpenDialog(null, {
|
|
|
|
title: 'Custom sound',
|
|
|
|
properties: ['openFile'],
|
|
|
|
filters: [
|
|
|
|
{ name: 'Audio', extensions: ['mp3', 'aac', 'wav', 'flac', 'm4a'] },
|
|
|
|
{ name: 'All', extensions: ['*'] },
|
|
|
|
]
|
|
|
|
}, (fileNames) => {
|
2019-06-16 00:07:18 +10:00
|
|
|
e.sender.webContents.send('customSoundRender', [arg, fileNames[0]]);
|
2019-06-15 03:01:38 +10:00
|
|
|
});
|
|
|
|
})
|
2019-06-15 02:32:59 +10:00
|
|
|
|
2019-05-19 17:39:30 +10:00
|
|
|
//ハードウェアアクセラレーションの無効化
|
|
|
|
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) => {
|
|
|
|
app.quit();
|
|
|
|
});
|
|
|
|
ipc.on('about', (e, args) => {
|
|
|
|
about();
|
|
|
|
});
|
|
|
|
function about() {
|
|
|
|
var ver = app.getVersion()
|
|
|
|
var window = new BrowserWindow({
|
2019-05-19 20:24:27 +10:00
|
|
|
webPreferences: {
|
2019-06-15 19:52:28 +10:00
|
|
|
webviewTag: false,
|
2019-08-26 22:06:07 +10:00
|
|
|
nodeIntegration: false,
|
|
|
|
contextIsolation: true,
|
|
|
|
preload: join(dirname, "js", "platform", "preload.js")
|
2019-05-19 20:24:27 +10:00
|
|
|
},
|
2019-04-03 14:59:29 +11:00
|
|
|
width: 300,
|
2019-08-26 22:06:07 +10:00
|
|
|
height: 500,
|
2019-04-03 14:59:29 +11:00
|
|
|
"transparent": false, // ウィンドウの背景を透過
|
2019-06-16 02:08:10 +10:00
|
|
|
"frame": false, // 枠の無いウィンドウ
|
|
|
|
"resizable": false
|
2019-04-03 14:59:29 +11:00
|
|
|
});
|
|
|
|
window.loadURL(dir + '/about.html?ver=' + ver);
|
|
|
|
return "true"
|
|
|
|
}
|
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: {
|
2019-06-15 19:52:28 +10:00
|
|
|
webviewTag: false,
|
|
|
|
nodeIntegration: false,
|
|
|
|
contextIsolation: true,
|
2019-08-26 22:06:07 +10:00
|
|
|
preload: join(dirname, "js", "platform", "preload.js")
|
2019-05-19 20:24:27 +10:00
|
|
|
},
|
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) => {
|
2019-06-16 02:34:49 +10:00
|
|
|
event = e.sender
|
|
|
|
cbTimer1 = setInterval(mems, 1000);
|
2019-04-03 14:59:29 +11:00
|
|
|
});
|
2019-06-16 02:34:49 +10:00
|
|
|
function mems() {
|
|
|
|
var mem = os.totalmem() - os.freemem();
|
|
|
|
if (mainWindow) {
|
|
|
|
event.webContents.send('memory', [mem, os.cpus()[0].model, os.totalmem()]);
|
|
|
|
}
|
|
|
|
}
|
2019-04-03 14:59:29 +11:00
|
|
|
ipc.on('endmem', (e, arg) => {
|
|
|
|
if (cbTimer1) {
|
|
|
|
clearInterval(cbTimer1);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-06-15 02:32:59 +10:00
|
|
|
|
2019-04-03 14:59:29 +11:00
|
|
|
ipc.on('export', (e, args) => {
|
2019-08-29 02:20:47 +10:00
|
|
|
fs.writeFileSync(args[0], JSON5.stringify(args[1]));
|
2019-08-29 02:33:06 +10:00
|
|
|
e.sender.webContents.send('exportAllComplete', "");
|
2019-04-03 14:59:29 +11:00
|
|
|
});
|
|
|
|
//フォント
|
|
|
|
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-06-15 01:51:41 +10:00
|
|
|
e.sender.webContents.send('font-list', fonts_sorted);
|
2019-04-03 14:59:29 +11:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
exports.system = system;
|