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-03-27 13:39:35 +11:00
|
|
|
const Menu=electron.Menu
|
2018-01-28 23:22:43 +11:00
|
|
|
// アプリケーションをコントロールするモジュール
|
|
|
|
const app = electron.app;
|
|
|
|
|
|
|
|
// ウィンドウを作成するモジュール
|
|
|
|
const BrowserWindow = electron.BrowserWindow;
|
|
|
|
const {
|
|
|
|
download
|
|
|
|
} = require('electron-dl');
|
|
|
|
const openAboutWindow = require('about-window').default;
|
|
|
|
const join = require('path').join;
|
|
|
|
// メインウィンドウはGCされないようにグローバル宣言
|
|
|
|
let mainWindow;
|
|
|
|
var info_path = join(app.getPath("userData"), "window-size.json");
|
|
|
|
var window_size;
|
|
|
|
try {
|
|
|
|
window_size = JSON.parse(fs.readFileSync(info_path, 'utf8'));
|
|
|
|
} catch (e) {
|
|
|
|
window_size = {
|
|
|
|
width: 1000,
|
|
|
|
height: 750
|
|
|
|
}; // デフォルトバリュー
|
|
|
|
}
|
|
|
|
|
|
|
|
// 全てのウィンドウが閉じたら終了
|
|
|
|
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() {
|
|
|
|
// メイン画面の表示。ウィンドウの幅、高さを指定できる
|
|
|
|
mainWindow = new BrowserWindow(window_size);
|
|
|
|
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];
|
|
|
|
mainWindow.loadURL('file://' + __dirname + '/index.html?mode='+mode+'&code='+code);
|
|
|
|
}else{
|
2018-02-26 02:32:10 +11:00
|
|
|
//mainWindow.loadURL('file://' + __dirname + '/index.html?mode=share&code=日本語');
|
2018-02-18 16:43:11 +11:00
|
|
|
mainWindow.loadURL('file://' + __dirname + '/index.html');
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
mainWindow.loadURL('file://' + __dirname + '/index.html');
|
|
|
|
}
|
|
|
|
|
|
|
|
}else{
|
|
|
|
mainWindow.loadURL('file://' + __dirname + '/index.html');
|
|
|
|
}
|
2018-01-28 23:22:43 +11:00
|
|
|
// ウィンドウが閉じられたらアプリも終了
|
|
|
|
mainWindow.on('closed', function() {
|
|
|
|
mainWindow = null;
|
|
|
|
});
|
|
|
|
mainWindow.on('close', function() {
|
|
|
|
fs.writeFileSync(info_path, JSON.stringify(mainWindow.getBounds()));
|
|
|
|
});
|
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" },
|
|
|
|
{ label: "終了", accelerator: "Command+Q", click: function() { app.quit(); }}
|
|
|
|
]}, {
|
|
|
|
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:" }
|
|
|
|
]}
|
|
|
|
];
|
|
|
|
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);
|
|
|
|
var ipc = electron.ipcMain;
|
|
|
|
ipc.on('update', function(e, x, y) {
|
2018-03-18 02:00:53 +11:00
|
|
|
var platform=process.platform;
|
|
|
|
var bit=process.arch;
|
|
|
|
if(platform!="darwin"){
|
2018-01-28 23:22:43 +11:00
|
|
|
var window = new BrowserWindow({
|
|
|
|
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
|
|
|
|
});
|
|
|
|
window.loadURL('file://' + __dirname + '/update.html');
|
|
|
|
|
|
|
|
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
|
|
|
ipc.on('screen', function(e, args) {
|
2018-01-28 23:22:43 +11:00
|
|
|
var window = new BrowserWindow({
|
2018-03-11 01:22:59 +11:00
|
|
|
width: args[0],
|
|
|
|
height: args[1],
|
|
|
|
"transparent": false, // ウィンドウの背景を透過
|
2018-01-28 23:22:43 +11:00
|
|
|
"frame": false, // 枠の無いウィンドウ
|
2018-03-11 01:22:59 +11:00
|
|
|
"resizable": true
|
2018-01-28 23:22:43 +11:00
|
|
|
});
|
2018-03-11 01:22:59 +11:00
|
|
|
window.loadURL('file://' + __dirname + '/screenshot.html?id='+args[2]);
|
2018-01-28 23:22:43 +11:00
|
|
|
window.setAlwaysOnTop(true);
|
|
|
|
window.setPosition(0, 0);
|
|
|
|
return "true"
|
|
|
|
})
|
2018-03-11 01:22:59 +11:00
|
|
|
//Web魚拓
|
|
|
|
ipc.on('shot', function(e, args) {
|
|
|
|
console.log(args[0]);
|
2018-03-18 02:00:53 +11:00
|
|
|
var platform=process.platform;
|
|
|
|
var bit=process.arch;
|
|
|
|
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/";
|
|
|
|
}
|
2018-03-11 01:22:59 +11:00
|
|
|
Jimp.read(Buffer.from( args[3],'base64'), function (err, lenna) {
|
|
|
|
if (err) throw err;
|
2018-03-18 02:00:53 +11:00
|
|
|
lenna.crop( 0, 0, 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-03-18 02:00:53 +11:00
|
|
|
lenna.write(folder+args[1]);
|
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;
|
|
|
|
if(platform=="win32"){
|
|
|
|
if(bit=="x64"){
|
|
|
|
var zip="TheDesk-win32-x64.zip";
|
|
|
|
}else if(bit=="ia32"){
|
|
|
|
var zip="TheDesk-win32-ia32.zip";
|
|
|
|
}
|
2018-03-18 02:00:53 +11:00
|
|
|
}else if(platform=="linux" || platform=="darwin" ){
|
2018-03-15 06:42:48 +11:00
|
|
|
const options = {
|
|
|
|
type: 'info',
|
|
|
|
title: 'Linux Supporting System',
|
|
|
|
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];
|
|
|
|
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-02-18 18:29:06 +11:00
|
|
|
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-03-13 04:41:38 +11:00
|
|
|
dl(ver,m[1],savedFiles);
|
2018-02-18 05:44:20 +11:00
|
|
|
});
|
2018-02-17 00:08:43 +11:00
|
|
|
}else{
|
2018-03-13 04:41:38 +11:00
|
|
|
dl(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-03-13 04:41:38 +11:00
|
|
|
function dl(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"){
|
|
|
|
var zip="TheDesk-win32-x64.zip";
|
|
|
|
}else if(bit=="ia32"){
|
|
|
|
var zip="TheDesk-win32-ia32.zip";
|
|
|
|
}
|
|
|
|
}else if(platform=="linux"){
|
|
|
|
if(bit=="x64"){
|
|
|
|
var zip="TheDesk-linux-x64.zip";
|
|
|
|
}else if(bit=="ia32"){
|
|
|
|
var zip="TheDesk-linux-ia32.zip";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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)];
|
|
|
|
}
|
|
|
|
zip=zip+r;
|
2018-01-28 23:22:43 +11:00
|
|
|
mainWindow.webContents.send('comp', "ダウンロードを開始します。");
|
|
|
|
const opts = {
|
2018-02-17 00:08:43 +11:00
|
|
|
directory:files,
|
2018-01-28 23:22:43 +11:00
|
|
|
openFolderWhenDone: true,
|
|
|
|
onProgress: function(e) {
|
|
|
|
mainWindow.webContents.send('prog', e);
|
|
|
|
},
|
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 => {
|
|
|
|
mainWindow.webContents.send('comp', "ダウンロードが完了しました。");
|
|
|
|
app.quit();
|
|
|
|
})
|
|
|
|
.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;
|
|
|
|
if(platform=="win32"){
|
|
|
|
var dir=app.getPath('home')+"\\Pictures\\TheDesk";
|
|
|
|
}else if(platform=="linux" || platform=="darwin" ){
|
|
|
|
var dir=app.getPath('home')+"/Pictures/TheDesk";
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
"transparent": false, // ウィンドウの背景を透過
|
|
|
|
"frame": false, // 枠の無いウィンドウ
|
|
|
|
"resizable": false });
|
|
|
|
window.loadURL('file://' + __dirname + '/about.html?ver='+ver);
|
|
|
|
return "true"
|
2018-03-27 13:39:35 +11:00
|
|
|
}
|
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');
|
|
|
|
mainWindow.webContents.send('bmp-img-comp', bin);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
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: 'カラム削除',
|
|
|
|
message: "カラムを削除しますか?",
|
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) => {
|
|
|
|
var m = args.match(/(.+)\\(.+)\.(.+)$/);
|
|
|
|
Jimp.read(args, function (err, lenna) {
|
|
|
|
if (err) throw err;
|
|
|
|
lenna.getBase64(Jimp.MIME_PNG, function (err, src) {
|
|
|
|
mainWindow.webContents.send('bmp-img-comp', src);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
2018-03-11 01:22:59 +11:00
|
|
|
ipc.on('nano', function (e, x, y) {
|
|
|
|
var window = new BrowserWindow({width: 300, height: 200,
|
|
|
|
"transparent": false, // ウィンドウの背景を透過
|
|
|
|
"frame": false, // 枠の無いウィンドウ
|
|
|
|
"resizable": false });
|
|
|
|
window.loadURL('file://' + __dirname + '/nano.html');
|
|
|
|
window.setAlwaysOnTop(true);
|
|
|
|
window.setPosition(0, 0);
|
|
|
|
return "true"
|
|
|
|
})
|
2018-03-20 15:55:25 +11:00
|
|
|
|
|
|
|
ipc.on('fool', function(e, x, y) {
|
|
|
|
var window = new BrowserWindow({
|
|
|
|
width: 400,
|
|
|
|
height: 800,
|
|
|
|
"transparent": false, // ウィンドウの背景を透過
|
|
|
|
"frame": true, // 枠の無いウィンドウ
|
|
|
|
"resizable": true
|
|
|
|
});
|
|
|
|
window.loadURL('file://' + __dirname + '/cro.html');
|
|
|
|
|
|
|
|
return "true"
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2018-03-27 13:39:35 +11:00
|
|
|
app.setAsDefaultProtocolClient('thedesk')
|