From db7c471ec51c082db26596b17ff5cc97246bf59e Mon Sep 17 00:00:00 2001 From: cutls Date: Fri, 6 Mar 2020 01:51:06 +0900 Subject: [PATCH] WIP: introduce new titlebar(ofcouce, it is optional opt-in; now it is as opt-out) --- app/css/master.css | 10 +- app/js/platform/preload.js | 17 ++++ app/main.js | 5 +- app/main/dl.js | 151 +++++++++++++++--------------- app/package.json | 1 + app/view/make/setting.sample.html | 2 +- app/yarn.lock | 5 + 7 files changed, 111 insertions(+), 80 deletions(-) diff --git a/app/css/master.css b/app/css/master.css index 4568487a..2e37af9a 100644 --- a/app/css/master.css +++ b/app/css/master.css @@ -9,6 +9,14 @@ body { height: 100vh; color: var(--color); } +.titlebar, .menubar-menu-container, .action-menu-item { + background-color: var(--notfbox) !important; + filter: brightness(110%) !important; + color: var(--color) !important; +} +.action-menu-item:hover { + filter: brightness(80%) !important; +} .btn { margin: 5px; text-transform: none; @@ -494,7 +502,7 @@ textarea { background-color: var(--emphasized); } #pageSrc { - position: fixed; + position: absolute; top: 0; left: calc(50vw - 150px); width: 300px; diff --git a/app/js/platform/preload.js b/app/js/platform/preload.js index b8afa588..e39178a6 100644 --- a/app/js/platform/preload.js +++ b/app/js/platform/preload.js @@ -1,6 +1,23 @@ var electron = require('electron') const shell = electron.shell var ipc = electron.ipcRenderer +//title bar +const customTitlebar = require('custom-electron-titlebar') +window.addEventListener('DOMContentLoaded', () => { + const file = location.href.substr(-10) + if ( + file == 'index.html' || + file == '/acct.html' || + file == 'tting.html' + ) { + new customTitlebar.Titlebar({ + backgroundColor: customTitlebar.Color.fromHex('#000'), + titleHorizontalAlignment: 'right', + icon: '../../img/desk.png' + }) + } +}) + onmessage = function(e) { if (e.data[0] == 'openUrl') { urls = e.data[1].match(/https?:\/\/(.+)/) diff --git a/app/main.js b/app/main.js index 17756c89..af143831 100644 --- a/app/main.js +++ b/app/main.js @@ -141,7 +141,9 @@ function createWindow() { x: window_size.x, y: window_size.y, icon: __dirname + '/desk.png', - show: false + show: false, + frame: false, + resizable: true } } else if (platform == 'win32') { var arg = { @@ -282,6 +284,7 @@ function createWindow() { Menu.setApplicationMenu( Menu.buildFromTemplate(language.template(lang, mainWindow, packaged, dir, dirname)) ) + mainWindow.setMenu(null) //CSS css.css(mainWindow) //アップデータとダウンロード diff --git a/app/main/dl.js b/app/main/dl.js index 95bd49f9..affae9f1 100644 --- a/app/main/dl.js +++ b/app/main/dl.js @@ -1,126 +1,123 @@ function dl(mainWindow, lang_path, base, dirname) { - const electron = require("electron"); - const shell = electron.shell; - const fs = require("fs"); - const { download } = require('electron-dl'); - const BrowserWindow = electron.BrowserWindow; - const dialog = electron.dialog; - var updatewin = null; - var ipc = electron.ipcMain; - const app = electron.app; - const join = require('path').join; - ipc.on('update', function (e, x, y) { - - var platform = process.platform; - var bit = process.arch; - if (platform != "others") { + const electron = require('electron') + const shell = electron.shell + const fs = require('fs') + const { download } = require('electron-dl') + const BrowserWindow = electron.BrowserWindow + const dialog = electron.dialog + var updatewin = null + var ipc = electron.ipcMain + const app = electron.app + const join = require('path').join + ipc.on('update', function(e, x, y) { + var platform = process.platform + var bit = process.arch + if (platform != 'others') { updatewin = new BrowserWindow({ webPreferences: { webviewTag: false, nodeIntegration: false, contextIsolation: true, - preload: join(dirname,"js", "platform", "preload.js") + preload: join(dirname, 'js', 'platform', 'preload.js') }, width: 600, height: 400, - "transparent": false, // ウィンドウの背景を透過 - "frame": false, // 枠の無いウィンドウ - "resizable": false + transparent: false, // ウィンドウの背景を透過 + frame: false, // 枠の無いウィンドウ + resizable: false }) - var lang = fs.readFileSync(lang_path, 'utf8'); - updatewin.loadURL(base + lang + '/update.html'); - return "true" + var lang = fs.readFileSync(lang_path, 'utf8') + updatewin.loadURL(base + lang + '/update.html') + return 'true' } else { - return false; + return false } }) //アプデDL ipc.on('download-btn', (e, args) => { function dl(url, file, dir, e) { - - e.sender.webContents.send('mess', "ダウンロードを開始します。"); + e.sender.webContents.send('mess', 'ダウンロードを開始します。') const opts = { directory: dir, openFolderWhenDone: true, - onProgress: function (event) { - e.sender.webContents.send('prog', event); + onProgress: function(event) { + e.sender.webContents.send('prog', event) }, saveAs: false - }; - download(updatewin, - url, opts) + } + download(updatewin, url, opts) .then(dl => { - e.sender.webContents.send('mess', "ダウンロードが完了しました。"); - app.quit(); + e.sender.webContents.send('mess', 'ダウンロードが完了しました。') + app.quit() }) - .catch(console.error); + .catch(console.error) } - var platform = process.platform; - var bit = process.arch; - dialog.showSaveDialog(null, { - title: 'Save', - defaultPath: app.getPath('home') + "/" + args[1] - }, (savedFiles) => { - console.log(savedFiles); - if (!savedFiles) { - return false; + var platform = process.platform + var bit = process.arch + dialog.showSaveDialog( + null, + { + title: 'Save', + defaultPath: app.getPath('home') + '/' + args[1] + }, + savedFiles => { + console.log(savedFiles) + if (!savedFiles) { + return false + } + if (platform == 'win32') { + var m = savedFiles.match(/(.+)\\(.+)$/) + } else { + var m = savedFiles.match(/(.+)\/(.+)$/) + } + //console.log(m); + if (isExistFile(savedFiles)) { + fs.unlinkSync(savedFiles) + } + dl(args[0], args[1], m[1], e) } - if (platform == "win32") { - var m = savedFiles.match(/(.+)\\(.+)$/); - } else { - var m = savedFiles.match(/(.+)\/(.+)$/); - } - //console.log(m); - if (isExistFile(savedFiles)) { - fs.unlinkSync(savedFiles); - } - dl(args[0], args[1], m[1], e); - }); - }); + ) + }) function isExistFile(file) { try { - fs.statSync(file); + fs.statSync(file) return true } catch (err) { if (err.code === 'ENOENT') return false } } - ipc.on('general-dl', (event, args) => { - - var name = ""; - var platform = process.platform; - var bit = process.arch; - 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"; + var name = '' + var platform = process.platform + var bit = process.arch + 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]; + var dir = args[1] } const opts = { directory: dir, filename: name, openFolderWhenDone: false, - onProgress: function (e) { - event.sender.webContents.send('general-dl-prog', e); + onProgress: function(e) { + event.sender.webContents.send('general-dl-prog', e) }, saveAs: false - }; - download(BrowserWindow.getFocusedWindow(), - args[0], opts) + } + download(BrowserWindow.getFocusedWindow(), args[0], opts) .then(dl => { - event.sender.webContents.send('general-dl-message', dir); + event.sender.webContents.send('general-dl-message', dir) }) - .catch(console.error); - }); + .catch(console.error) + }) ipc.on('open-finder', (e, folder) => { - shell.showItemInFolder(folder) - }); + }) } -exports.dl = dl; +exports.dl = dl diff --git a/app/package.json b/app/package.json index d25416e1..cf877659 100644 --- a/app/package.json +++ b/app/package.json @@ -52,6 +52,7 @@ "license": "GPL-3.0", "dependencies": { "@fortawesome/fontawesome-free": "^5.12.1", + "custom-electron-titlebar": "^3.2.2-hotfix62", "electron-dl": "^3.0.0", "jimp": "^0.9.3", "jquery": "^3.4.1", diff --git a/app/view/make/setting.sample.html b/app/view/make/setting.sample.html index faa1339a..65b4ceec 100644 --- a/app/view/make/setting.sample.html +++ b/app/view/make/setting.sample.html @@ -1,5 +1,5 @@ - + Settings - TheDesk diff --git a/app/yarn.lock b/app/yarn.lock index 9a8a6476..65135c66 100644 --- a/app/yarn.lock +++ b/app/yarn.lock @@ -861,6 +861,11 @@ crypto-random-string@^1.0.0: resolved "https://registry.yarnpkg.com/crypto-random-string/-/crypto-random-string-1.0.0.tgz#a230f64f568310e1498009940790ec99545bca7e" integrity sha1-ojD2T1aDEOFJgAmUB5DsmVRbyn4= +custom-electron-titlebar@^3.2.2-hotfix62: + version "3.2.2-hotfix62" + resolved "https://registry.yarnpkg.com/custom-electron-titlebar/-/custom-electron-titlebar-3.2.2-hotfix62.tgz#94b908f0f2bf812e4f65447a26b93b88f7a76088" + integrity sha512-Kh86xAolkCpqj4AD/H4HcR2pEtxUyIHzMzqwkxqZkSqE7R9tRfN8G3fVpiiNIAJlX8rbN3VwxaoHi1B1sSMn/Q== + dashdash@^1.12.0: version "1.14.1" resolved "https://registry.yarnpkg.com/dashdash/-/dashdash-1.14.1.tgz#853cfa0f7cbe2fed5de20326b8dd581035f6e2f0"