thedesk/app/main.js

648 lines
17 KiB
JavaScript
Raw Normal View History

2018-01-28 23:22:43 +11:00
'use strict';
// Electronのモジュール
const electron = require("electron");
const fs = require("fs");
2018-02-19 04:41:25 +11:00
const dialog = require('electron').dialog;
var Jimp = require("jimp");
2018-03-11 01:22:59 +11:00
const shell = electron.shell;
const os = require('os')
const path = require('path')
2018-12-09 05:46:01 +11:00
const fm = require('font-manager');
2018-03-27 13:39:35 +11:00
const Menu=electron.Menu
2018-04-09 00:17:33 +10:00
var updatewin=null;
2018-01-28 23:22:43 +11:00
// アプリケーションをコントロールするモジュール
const app = electron.app;
// ウィンドウを作成するモジュール
const BrowserWindow = electron.BrowserWindow;
const {
download
} = require('electron-dl');
const join = require('path').join;
// メインウィンドウはGCされないようにグローバル宣言
let mainWindow;
var info_path = join(app.getPath("userData"), "window-size.json");
2018-06-12 01:44:28 +10:00
var max_info_path = join(app.getPath("userData"), "max-window-size.json");
2018-09-12 02:49:41 +10:00
var lang_path=join(app.getPath("userData"), "language");
2018-03-31 13:39:06 +11:00
var tmp_img = join(app.getPath("userData"), "tmp.png");
2018-01-28 23:22:43 +11:00
var window_size;
try {
window_size = JSON.parse(fs.readFileSync(info_path, 'utf8'));
} catch (e) {
window_size = {
width: 1000,
height: 750
}; // デフォルトバリュー
}
2018-06-12 01:44:28 +10:00
var max_window_size;
try {
max_window_size = JSON.parse(fs.readFileSync(max_info_path, 'utf8'));
} catch (e) {
max_window_size = {
width: "string",
height: "string",
x: "string",
y: "string"
}; // デフォルトバリュー
}
2018-05-20 16:17:10 +10:00
2018-01-28 23:22:43 +11:00
// 全てのウィンドウが閉じたら終了
app.on('window-all-closed', function() {
if (process.platform != 'darwin') {
2018-03-18 02:00:53 +11:00
electron.session.defaultSession.clearCache(() => {})
2018-01-28 23:22:43 +11:00
app.quit();
}
});
function createWindow() {
// メイン画面の表示。ウィンドウの幅、高さを指定できる
2018-04-16 23:58:14 +10:00
var platform=process.platform;
var bit=process.arch;
if(platform=="linux"){
2019-01-22 03:24:37 +11:00
var arg={width:window_size.width,height:window_size.height,x:window_size.x,y:window_size.y,icon: __dirname + '/desk.png'}
2018-04-16 23:58:14 +10:00
}else{
2018-06-12 01:44:28 +10:00
var arg={width:window_size.width,height:window_size.height,x:window_size.x,y:window_size.y,simpleFullscreen:true}
2018-04-16 23:58:14 +10:00
}
mainWindow = new BrowserWindow(arg);
2018-09-12 02:49:41 +10:00
try {
var lang = fs.readFileSync(lang_path, 'utf8');
} catch (e) {
var lang=app.getLocale();
if(~lang.indexOf("ja")){
lang="ja";
}else{
lang="en";
}
fs.writeFileSync(lang_path,lang);
}
2018-01-28 23:22:43 +11:00
electron.session.defaultSession.clearCache(() => {})
2018-02-18 16:43:11 +11:00
if(process.argv){
if(process.argv[1]){
2018-03-11 01:22:59 +11:00
var m = process.argv[1].match(/([a-zA-Z0-9]+)\/\?[a-zA-Z-0-9]+=(.+)/);
2018-02-18 16:43:11 +11:00
if(m){
var mode=m[1];
var code=m[2];
2018-09-12 02:49:41 +10:00
var plus='?mode='+mode+'&code='+code;
2018-02-18 16:43:11 +11:00
}else{
2018-09-12 02:49:41 +10:00
var plus="";
2018-02-18 16:43:11 +11:00
}
}else{
2018-09-12 02:49:41 +10:00
var plus="";
2018-02-18 16:43:11 +11:00
}
}else{
2018-09-12 02:49:41 +10:00
var plus="";
2018-02-18 16:43:11 +11:00
}
2018-09-12 02:49:41 +10:00
mainWindow.loadURL('file://' + __dirname + '/view/'+lang+'/index.html'+plus);
2018-06-12 01:44:28 +10:00
if(!window_size.x && !window_size.y){
mainWindow.center();
}
if(window_size.max){
mainWindow.maximize();
}
2018-01-28 23:22:43 +11:00
// ウィンドウが閉じられたらアプリも終了
mainWindow.on('closed', function() {
mainWindow = null;
});
mainWindow.on('close', function() {
2018-06-12 01:44:28 +10:00
if(
max_window_size.width==mainWindow.getBounds().width &&
max_window_size.height==mainWindow.getBounds().height &&
max_window_size.x==mainWindow.getBounds().x &&
max_window_size.y==mainWindow.getBounds().y
){
var size={width:mainWindow.getBounds().width,height:mainWindow.getBounds().height,x:mainWindow.getBounds().x,y:mainWindow.getBounds().y,max:true}
}else{
var size={width:mainWindow.getBounds().width,height:mainWindow.getBounds().height,x:mainWindow.getBounds().x,y:mainWindow.getBounds().y}
}
fs.writeFileSync(info_path, JSON.stringify(size));
});
mainWindow.on('maximize', function() {
fs.writeFileSync(max_info_path, JSON.stringify(mainWindow.getBounds()));
2018-01-28 23:22:43 +11:00
});
2018-03-27 13:39:35 +11:00
// Create the Application's main menu
var template = [{
label: "アプリケーション",
submenu: [
{ label: "TheDeskについて", click: function() { about(); } },
{ type: "separator" },
2018-08-23 03:29:39 +10:00
{ label: "終了", accelerator: "Command+Q", click: function() { app.quit(); }}
2018-03-27 13:39:35 +11:00
]}, {
label: "編集",
submenu: [
{ label: "元に戻す", accelerator: "CmdOrCtrl+Z", selector: "undo:" },
{ label: "やり直し", accelerator: "Shift+CmdOrCtrl+Z", selector: "redo:" },
{ type: "separator" },
{ label: "切り取り", accelerator: "CmdOrCtrl+X", selector: "cut:" },
{ label: "コピー", accelerator: "CmdOrCtrl+C", selector: "copy:" },
{ label: "貼り付け", accelerator: "CmdOrCtrl+V", selector: "paste:" },
{ label: "すべて選択", accelerator: "CmdOrCtrl+A", selector: "selectAll:" }
2018-05-26 22:48:13 +10:00
]},{
label: "表示",
submenu: [
{
label: 'Toggle Developer Tools',
accelerator: 'Alt+Command+I',
click: function() { mainWindow.toggleDevTools(); }
},
2018-06-18 00:48:33 +10:00
{
label: '再読み込み',
accelerator: 'CmdOrCtrl+R',
2018-06-18 01:07:16 +10:00
click: function() { mainWindow.webContents.send('reload', " "); }
2018-06-18 00:48:33 +10:00
}
2018-05-26 22:48:13 +10:00
]
2018-08-23 03:29:39 +10:00
},
{
label: 'ウィンドウ',
role: 'window',
submenu: [
{
label: '最小化',
accelerator: 'CmdOrCtrl+M',
role: 'minimize'
},
{
label: '閉じる',
accelerator: 'CmdOrCtrl+W',
role: 'close'
},
]
}
2018-03-27 13:39:35 +11:00
];
var platform=process.platform;
var bit=process.arch;
if(platform=="darwin"){
Menu.setApplicationMenu(Menu.buildFromTemplate(template));
}
2018-01-28 23:22:43 +11:00
}
// Electronの初期化完了後に実行
app.on('ready', createWindow);
2018-03-31 13:39:06 +11:00
var onError = function(err,response){
console.error(err,response);
};
2018-01-28 23:22:43 +11:00
var ipc = electron.ipcMain;
2018-03-31 13:39:06 +11:00
ipc.on('native-notf', function(e, args) {
2018-04-01 00:55:47 +11:00
var platform=process.platform;
var bit=process.arch;
if(platform=="win32"){
2018-09-10 03:06:00 +10:00
const notifier = require('node-notifier')
var tmp_imge=tmp_img;
2018-03-31 13:39:06 +11:00
Jimp.read(args[2], function (err, lenna) {
2018-05-20 16:17:10 +10:00
if(!err && lenna){
lenna.write(tmp_img);
var tmp_imge=tmp_img;
}else{
var tmp_imge="";
}
2018-03-31 13:39:06 +11:00
notifier.notify({
2018-09-10 03:06:00 +10:00
appID: "top.thedesk",
2018-06-12 01:44:28 +10:00
message: args[1],
2018-03-31 13:39:06 +11:00
title: args[0],
2018-05-20 16:17:10 +10:00
icon : tmp_imge,
2018-06-12 01:44:28 +10:00
sound: false,
2018-09-10 03:06:00 +10:00
wait: true,
},
function(err, response) {
console.log(err, response)
});
2018-03-31 13:39:06 +11:00
});
2018-05-26 05:00:04 +10:00
}
2018-03-31 13:39:06 +11:00
});
//言語
ipc.on('lang', function(e, arg) {
2018-09-12 02:49:41 +10:00
fs.writeFileSync(lang_path,arg);
mainWindow.webContents.send('langres', "");
})
2018-04-09 00:17:33 +10:00
2018-01-28 23:22:43 +11:00
ipc.on('update', function(e, x, y) {
2018-03-18 02:00:53 +11:00
var platform=process.platform;
var bit=process.arch;
2018-05-20 17:04:30 +10:00
if(platform!="others"){
2018-04-09 00:17:33 +10:00
updatewin = new BrowserWindow({
2018-01-28 23:22:43 +11:00
width: 600,
2018-02-18 16:43:11 +11:00
height: 400,
2018-01-28 23:22:43 +11:00
"transparent": false, // ウィンドウの背景を透過
"frame": false, // 枠の無いウィンドウ
"resizable": false
});
2018-09-12 02:49:41 +10:00
var lang = fs.readFileSync(lang_path, 'utf8');
updatewin.loadURL('file://' + __dirname + '/view/'+lang+'/update.html');
2018-01-28 23:22:43 +11:00
return "true"
2018-03-18 02:00:53 +11:00
}else{
return false;
}
2018-01-28 23:22:43 +11:00
})
2018-03-11 01:22:59 +11:00
//Web魚拓
ipc.on('shot', function(e, args) {
2018-06-18 00:26:45 +10:00
console.log("link:"+args[0]+" width:"+args[1]+" height:"+args[2]+" title:"+args[4]+" top:"+args[5]+" left:"+args[6]);
2018-03-18 02:00:53 +11:00
var platform=process.platform;
var bit=process.arch;
2018-09-06 02:47:27 +10:00
if(args[7]==""){
if(platform=="win32"){
var dir=app.getPath('home')+"\\Pictures\\TheDesk\\Screenshots\\"+args[4]+"-toot.png";
var folder=app.getPath('home')+"\\Pictures\\TheDesk\\Screenshots\\";
}else if(platform=="linux" || platform=="darwin" ){
var dir=app.getPath('home')+"/Pictures/TheDesk/Screenshots/"+args[4]+"-toot.png";
var folder=app.getPath('home')+"/Pictures/TheDesk/Screenshots/";
}
}else{
var folder=args[7];
var dir=folder+args[4]+"-toot.png";
2018-03-18 02:00:53 +11:00
}
2018-09-06 02:47:27 +10:00
2018-03-11 01:22:59 +11:00
Jimp.read(Buffer.from( args[3],'base64'), function (err, lenna) {
if (err) throw err;
2018-06-18 00:26:45 +10:00
lenna.crop( args[6], args[5], args[1], args[2] ).write(dir);
2018-03-11 01:22:59 +11:00
});
2018-03-18 02:00:53 +11:00
shell.showItemInFolder(folder);
2018-03-11 01:22:59 +11:00
})
ipc.on('shot-img-dl', (e, args) => {
Jimp.read(args[0], function (err, lenna) {
if (err) throw err;
2018-09-06 02:47:27 +10:00
if(args[1]==""){
if(process.platform=="win32"){
var folder=app.getPath('home')+"\\Pictures\\TheDesk\\Screenshots\\";
}else if(process.platform=="linux" || process.platform=="darwin" ){
var folder=app.getPath('home')+"/Pictures/TheDesk/Screenshots/";
}
}else{
var folder=args[2];
2018-06-18 00:26:45 +10:00
}
2018-09-06 02:47:27 +10:00
2018-03-18 02:00:53 +11:00
lenna.write(folder+args[1]);
2018-03-11 01:22:59 +11:00
});
2018-06-18 00:26:45 +10:00
})
2018-03-11 01:22:59 +11:00
//アプデDL
2018-01-28 23:22:43 +11:00
ipc.on('download-btn', (e, args) => {
2018-03-13 04:41:38 +11:00
var platform=process.platform;
var bit=process.arch;
2018-08-24 01:15:57 +10:00
var versioning=args[3];
2018-09-12 02:49:41 +10:00
var portable=args[2];
2018-05-20 17:04:30 +10:00
if(platform=="win32" || platform=="linux" || platform=="darwin" ){
2018-09-12 02:49:41 +10:00
var exe=false;
2018-05-26 22:48:13 +10:00
if(platform=="win32" && bit=="x64"){
2018-09-12 02:49:41 +10:00
if(portable){
var zip="TheDesk.exe";
}else{
var zip="TheDesk-setup.exe";
}
exe=true;
2018-05-26 22:48:13 +10:00
}else if(platform=="win32" && bit=="ia32"){
2018-09-12 02:49:41 +10:00
if(portable){
var zip="TheDesk-ia32.exe";
}else{
var zip="TheDesk-setup-ia32.exe";
}
exe=true;
2018-05-26 22:48:13 +10:00
}else if(platform=="linux" && bit=="x64"){
2018-05-20 17:04:30 +10:00
var zip="TheDesk-linux-x64.zip";
2018-05-26 22:48:13 +10:00
}else if(platform=="linux" && bit=="ia32"){
2018-05-20 17:04:30 +10:00
var zip="TheDesk-linux-ia32.zip";
}else if(platform=="darwin"){
var zip="TheDesk-darwin-x64.zip";
2018-05-26 22:48:13 +10:00
}else{
2018-08-24 01:15:57 +10:00
return;
}
2018-09-12 02:49:41 +10:00
if(versioning && !exe){
2018-08-24 01:15:57 +10:00
zip=zip.replace(".zip","."+args[1]+".zip");
2018-09-12 02:49:41 +10:00
}else if(versioning){
zip=zip.replace(".exe","."+args[1]+".exe");
2018-03-13 04:41:38 +11:00
}
2018-05-20 17:04:30 +10:00
}else{
2018-03-15 06:42:48 +11:00
const options = {
type: 'info',
2018-05-20 17:04:30 +10:00
title: 'Other OS Supporting System',
2018-03-15 06:42:48 +11:00
message: "thedesk.topをブラウザで開きます。",
buttons: ['OK']
}
dialog.showMessageBox(options, function(index) {
shell.openExternal("https://thedesk.top");
})
return;
2018-03-13 04:41:38 +11:00
if(bit=="x64"){
var zip="TheDesk-linux-x64.zip";
}else if(bit=="ia32"){
var zip="TheDesk-linux-ia32.zip";
}
}
var ver=args[1];
2018-08-24 01:15:57 +10:00
2018-05-26 22:48:13 +10:00
console.log(zip);
2018-03-13 04:41:38 +11:00
if(args[0]=="true"){
2018-02-18 05:44:20 +11:00
dialog.showSaveDialog(null, {
title: '保存',
properties: ['openFile', 'createDirectory'],
2018-03-13 04:41:38 +11:00
defaultPath: zip
2018-02-18 05:44:20 +11:00
}, (savedFiles) => {
2018-02-24 03:02:44 +11:00
console.log(savedFiles);
2018-03-18 02:00:53 +11:00
if(!savedFiles){
return false;
}
2018-05-20 17:04:30 +10:00
if(platform=="win32"){
var m = savedFiles.match(/(.+)\\(.+)$/);
}else{
var m = savedFiles.match(/(.+)\/(.+)$/);
}
2018-02-24 03:02:44 +11:00
if(isExistFile(savedFiles)){
2018-02-18 18:29:06 +11:00
fs.statSync(savedFiles);
fs.unlink(savedFiles);
}
2018-02-24 03:02:44 +11:00
console.log(m[1]+":"+savedFiles)
2018-09-12 02:49:41 +10:00
dl(portable,ver,m[1],savedFiles);
2018-02-18 05:44:20 +11:00
});
2018-02-17 00:08:43 +11:00
}else{
2018-09-12 02:49:41 +10:00
dl(portable,ver);
2018-02-17 00:08:43 +11:00
}
});
2018-02-24 03:02:44 +11:00
function isExistFile(file) {
try {
fs.statSync(file);
return true
} catch(err) {
if(err.code === 'ENOENT') return false
}
}
2018-09-12 02:49:41 +10:00
function dl(portable,ver,files,fullname){
2018-02-18 05:44:20 +11:00
console.log(files);
2018-03-13 04:41:38 +11:00
var platform=process.platform;
var bit=process.arch;
if(platform=="win32"){
if(bit=="x64"){
2018-09-12 02:49:41 +10:00
if(portable){
var zip="TheDesk.exe";
}else{
var zip="TheDesk-setup.exe";
}
2018-03-13 04:41:38 +11:00
}else if(bit=="ia32"){
2018-09-12 02:49:41 +10:00
if(portable){
var zip="TheDesk-ia32.exe";
}else{
var zip="TheDesk-setup-ia32.exe";
}
2018-03-13 04:41:38 +11:00
}
}else if(platform=="linux"){
if(bit=="x64"){
var zip="TheDesk-linux-x64.zip";
}else if(bit=="ia32"){
var zip="TheDesk-linux-ia32.zip";
}
2018-05-20 17:04:30 +10:00
}else if(platform=="darwin"){
var zip="TheDesk-darwin-x64.zip";
2018-03-13 04:41:38 +11:00
}
2018-08-05 02:26:34 +10:00
//zip=zip+"?"+ver;
2018-03-18 02:00:53 +11:00
var l = 8;
// 生成する文字列に含める文字セット
var c = "abcdefghijklmnopqrstuvwxyz0123456789";
var cl = c.length;
var r = "";
for(var i=0; i<l; i++){
r += c[Math.floor(Math.random()*cl)];
}
2018-08-05 02:26:34 +10:00
2018-04-09 00:17:33 +10:00
updatewin.webContents.send('mess', "ダウンロードを開始します。");
2018-01-28 23:22:43 +11:00
const opts = {
2018-09-12 02:49:41 +10:00
directory:fullname,
2018-01-28 23:22:43 +11:00
openFolderWhenDone: true,
onProgress: function(e) {
2018-04-09 00:17:33 +10:00
updatewin.webContents.send('prog', e);
2018-01-28 23:22:43 +11:00
},
2018-02-17 00:08:43 +11:00
saveAs: false
2018-01-28 23:22:43 +11:00
};
download(BrowserWindow.getFocusedWindow(),
2018-03-13 04:41:38 +11:00
'https://dl.thedesk.top/'+zip, opts)
2018-01-28 23:22:43 +11:00
.then(dl => {
2018-04-09 00:17:33 +10:00
updatewin.webContents.send('mess', "ダウンロードが完了しました。");
2018-09-12 02:49:41 +10:00
app.quit();
2018-08-05 02:26:34 +10:00
2018-01-28 23:22:43 +11:00
})
.catch(console.error);
2018-02-17 00:08:43 +11:00
}
ipc.on('general-dl', (e, args) => {
2018-03-11 01:22:59 +11:00
var name="";
2018-03-18 02:00:53 +11:00
var platform=process.platform;
var bit=process.arch;
2018-09-06 02:47:27 +10:00
if(args[1]==""){
if(platform=="win32"){
var dir=app.getPath('home')+"\\Pictures\\TheDesk";
}else if(platform=="linux" || platform=="darwin" ){
var dir=app.getPath('home')+"/Pictures/TheDesk";
}
}else{
var dir=args[1];
}
2018-02-17 00:08:43 +11:00
mainWindow.webContents.send('general-dl-message', "ダウンロードを開始します。");
const opts = {
2018-03-11 01:22:59 +11:00
directory: dir,
filename:name,
2018-02-17 00:08:43 +11:00
openFolderWhenDone: true,
onProgress: function(e) {
mainWindow.webContents.send('general-dl-prog', e);
},
saveAs: false
};
download(BrowserWindow.getFocusedWindow(),
2018-03-11 01:22:59 +11:00
args[0], opts)
2018-02-17 00:08:43 +11:00
.then(dl => {
mainWindow.webContents.send('general-dl-message', "ダウンロードが完了しました。");
})
.catch(console.error);
2018-01-28 23:22:43 +11:00
});
ipc.on('quit', (e, args) => {
app.quit();
});
ipc.on('about', (e, args) => {
2018-03-27 13:39:35 +11:00
about();
});
function about(){
2018-03-13 04:41:38 +11:00
var ver=app.getVersion()
var window = new BrowserWindow({width: 300, height: 460,
2018-09-12 02:49:41 +10:00
"transparent": false, // ウィンドウの背景を透過
"frame": false, // 枠の無いウィンドウ
2018-03-13 04:41:38 +11:00
"resizable": false });
window.loadURL('file://' + __dirname + '/about.html?ver='+ver);
return "true"
2018-03-27 13:39:35 +11:00
}
2018-05-20 16:17:10 +10:00
ipc.on('itunes', (e, args) => {
var platform=process.platform;
var bit=process.arch;
if(platform=="darwin"){
const nowplaying = require("itunes-nowplaying-mac")
2018-06-12 02:41:11 +10:00
nowplaying.getRawData().then(function (value) {
2018-05-20 16:17:10 +10:00
mainWindow.webContents.send('itunes-np', value);
}).catch(function (error) {
// 非同期処理失敗。呼ばれない
console.log(error);
});
}
});
2018-03-18 02:00:53 +11:00
ipc.on('file-select', (e, args) => {
dialog.showOpenDialog(null, {
properties: ['openFile', 'multiSelections'],
title: '添付ファイルを選択',
defaultPath: '.',
filters: [
{name: 'メディアファイル', extensions: ['jpg', 'png', 'gif', 'bmp', 'jpeg','mp4','webm']},
{name: '画像', extensions: ['jpg', 'png', 'gif', 'bmp', 'jpeg']},
{name: '動画', extensions: ['mp4','webm']},
{name: '全てのファイル', extensions: ['*']}
]
}, (fileNames) => {
if(!fileNames){
return false;
}
for(var i=0;i<fileNames.length;i++){
var path=fileNames[i];
var bin = fs.readFileSync(path, 'base64');
2018-04-10 02:22:08 +10:00
mainWindow.webContents.send('bmp-img-comp', [bin,'new']);
2018-03-18 02:00:53 +11:00
}
});
});
2018-03-13 04:41:38 +11:00
2018-02-18 16:43:11 +11:00
ipc.on('column-del', (e, args) => {
const options = {
type: 'info',
title: 'カラム削除',
2018-07-05 11:26:07 +10:00
message: "カラムを削除しますか?(すべてのカラムのリンク解析がOFFになります。)",
2018-03-18 02:00:53 +11:00
buttons: ['いいえ', 'はい']
2018-02-18 16:43:11 +11:00
}
dialog.showMessageBox(options, function(index) {
mainWindow.webContents.send('column-del-reply', index);
})
});
2018-02-19 04:41:25 +11:00
ipc.on('bmp-image', (e, args) => {
2018-04-10 02:22:08 +10:00
var m = args[0].match(/(.+)\\(.+)\.(.+)$/);
Jimp.read(args[0], function (err, lenna) {
2018-02-19 04:41:25 +11:00
if (err) throw err;
lenna.getBase64(Jimp.MIME_PNG, function (err, src) {
2018-04-10 02:22:08 +10:00
mainWindow.webContents.send('bmp-img-comp', [src,args[1]]);
2018-02-19 04:41:25 +11:00
});
});
});
2018-03-11 01:22:59 +11:00
ipc.on('nano', function (e, x, y) {
2018-05-20 16:17:10 +10: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({width: 300, height: 200,
2018-03-11 01:22:59 +11:00
"transparent": false, // ウィンドウの背景を透過
"frame": false, // 枠の無いウィンドウ
"resizable": false });
2018-05-20 16:17:10 +10:00
nanowindow.loadURL('file://' + __dirname + '/nano.html');
nanowindow.setAlwaysOnTop(true);
nanowindow.setPosition(window_pos[0], window_pos[1]);
nanowindow.on('close', function() {
fs.writeFileSync(nano_info_path, JSON.stringify(nanowindow.getPosition()));
});
return true;
2018-03-11 01:22:59 +11:00
})
2018-05-02 14:14:03 +10:00
ipc.on('adobe', (e, arg) => {
if(!arg){
const options = {
type: 'info',
title: 'Adobeフォトエディタ',
2018-05-10 01:33:08 +10:00
message: "「許可」または「永続的に許可」をクリックするとTheDeskとAdobeで情報を共有します。\n次のウィンドウを開いている時以外は一切提供しません。",
2018-05-02 14:14:03 +10:00
buttons: ['拒否', '許可','永続的に許可']
}
dialog.showMessageBox(options, function(index) {
if(index==2){
mainWindow.webContents.send('adobeagree', "true");
}
if(index>0){
adobeWindow();
}
})
}else{
adobeWindow();
}
});
function adobeWindow(){
var window = new BrowserWindow({
width: 1000,
height: 750
});
window.loadURL('file://' + __dirname + '/adobe.html');
}
2018-07-28 07:25:12 +10:00
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();
2018-09-10 03:06:00 +10:00
if(mainWindow){
mainWindow.webContents.send('memory', [mem,os.cpus()[0].model,os.totalmem()]);
}
2018-07-28 07:25:12 +10:00
}
2018-07-29 17:37:54 +10:00
ipc.on('mkc', (e, arg) => {
2018-08-11 08:12:41 +10:00
var platform=process.platform;
if(platform=="linux" || platform=="win32" ){
var mkc = fs.readFileSync(__dirname + '/.tkn', 'utf8');
2018-08-11 08:13:26 +10:00
}else{
var mkc = "";
2018-08-11 08:12:41 +10:00
}
2018-08-11 08:13:26 +10:00
mainWindow.webContents.send('mkcr', mkc);
2018-07-29 17:37:54 +10:00
});
2018-08-05 02:26:34 +10:00
ipc.on('export', (e, args) => {
fs.writeFileSync(args[0], args[1]);
});
ipc.on('import', (e, arg) => {
mainWindow.webContents.send('config', fs.readFileSync(arg, 'utf8'));
});
2018-12-09 05:46:01 +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;
}
data = data.sort(function(a, b){
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) => {
var fonts = fm.getAvailableFontsSync();
object_array_sort(fonts, 'family', 'asc', function(fonts_sorted){
mainWindow.webContents.send('font-list', fonts_sorted);
});
});
2018-03-20 15:55:25 +11:00
2018-03-27 13:39:35 +11:00
app.setAsDefaultProtocolClient('thedesk')