From 2bb5169f08ee80f657a2edb114be015a68800412 Mon Sep 17 00:00:00 2001 From: Yuya Ochiai Date: Sat, 24 Oct 2015 01:44:10 +0900 Subject: [PATCH] =?UTF-8?q?gulp=20prettify=E3=82=92=E5=AE=9F=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app-menu.js | 167 ++++++++++++++++++-------------------- index.html | 19 +++-- index.js | 27 +++--- main.js | 185 +++++++++++++++++++++--------------------- settings.html | 17 ++-- webview/mattermost.js | 2 +- 6 files changed, 209 insertions(+), 208 deletions(-) diff --git a/app-menu.js b/app-menu.js index 258e5ff8..f26ba22f 100644 --- a/app-menu.js +++ b/app-menu.js @@ -2,113 +2,102 @@ var Menu = require('menu'); -var createTemplate = function(mainWindow){ +var createTemplate = function(mainWindow) { var first_menu_name = (process.platform === 'darwin') ? require('app').getName() : 'File'; var template = []; template.push({ label: first_menu_name, - submenu: [ - { - label: 'Settings', - click: function(item, focusedWindow){ - mainWindow.loadUrl('file://' + __dirname + '/settings.html'); - } - }, - { - label: 'Quit', - accelerator: 'CmdOrCtrl+Q', - click: function(item, focusedWindow){ - require('app').quit(); - } + submenu: [{ + label: 'Settings', + click: function(item, focusedWindow) { + mainWindow.loadUrl('file://' + __dirname + '/settings.html'); } - ] + }, { + label: 'Quit', + accelerator: 'CmdOrCtrl+Q', + click: function(item, focusedWindow) { + require('app').quit(); + } + }] }); template.push({ label: 'Edit', - submenu: [ - { - label: 'Undo', - accelerator: 'CmdOrCtrl+Z', - role: 'undo' - }, - { - label: 'Redo', - accelerator: 'Shift+CmdOrCtrl+Z', - role: 'redo' - }, - { - type: 'separator' - }, - { - label: 'Cut', - accelerator: 'CmdOrCtrl+X', - role: 'cut' - }, - { - label: 'Copy', - accelerator: 'CmdOrCtrl+C', - role: 'copy' - }, - { - label: 'Paste', - accelerator: 'CmdOrCtrl+V', - role: 'paste' - }, - { - label: 'Select All', - accelerator: 'CmdOrCtrl+A', - role: 'selectall' - }, - ] + submenu: [{ + label: 'Undo', + accelerator: 'CmdOrCtrl+Z', + role: 'undo' + }, { + label: 'Redo', + accelerator: 'Shift+CmdOrCtrl+Z', + role: 'redo' + }, { + type: 'separator' + }, { + label: 'Cut', + accelerator: 'CmdOrCtrl+X', + role: 'cut' + }, { + label: 'Copy', + accelerator: 'CmdOrCtrl+C', + role: 'copy' + }, { + label: 'Paste', + accelerator: 'CmdOrCtrl+V', + role: 'paste' + }, { + label: 'Select All', + accelerator: 'CmdOrCtrl+A', + role: 'selectall' + }, ] }); template.push({ label: 'View', - submenu: [ - { - label: 'Reload', - accelerator: 'CmdOrCtrl+R', - click: function(item, focusedWindow) { - if (focusedWindow) - focusedWindow.reload(); + submenu: [{ + label: 'Reload', + accelerator: 'CmdOrCtrl+R', + click: function(item, focusedWindow) { + if (focusedWindow) + focusedWindow.reload(); + } + }, { + label: 'Toggle Full Screen', + accelerator: (function() { + if (process.platform === 'darwin') { + return 'Ctrl+Command+F'; } - }, - { - label: 'Toggle Full Screen', - accelerator: (function() { - if (process.platform === 'darwin'){ - return 'Ctrl+Command+F'; - } else { - return 'F11'; - } - })(), - click: function(item, focusedWindow) { - if (focusedWindow) { - focusedWindow.setFullScreen(!focusedWindow.isFullScreen()); - } + else { + return 'F11'; } - }, - { - label: 'Toggle Developer Tools', - accelerator: (function() { - if (process.platform === 'darwin') { - return 'Alt+Command+I'; - } else { - return 'Ctrl+Shift+I'; - } - })(), - click: function(item, focusedWindow) { - if (focusedWindow) { - focusedWindow.toggleDevTools(); - } + })(), + click: function(item, focusedWindow) { + if (focusedWindow) { + focusedWindow.setFullScreen(!focusedWindow.isFullScreen()); } - }, - ] + } + }, { + label: 'Toggle Developer Tools', + accelerator: (function() { + if (process.platform === 'darwin') { + return 'Alt+Command+I'; + } + else { + return 'Ctrl+Shift+I'; + } + })(), + click: function(item, focusedWindow) { + if (focusedWindow) { + focusedWindow.toggleDevTools(); + } + } + }, ] }); return template; }; -var createMenu = function(mainWindow){ +var createMenu = function(mainWindow) { return Menu.buildFromTemplate(createTemplate(mainWindow)); }; -module.exports = { createMenu: createMenu }; +module.exports = { + createMenu: createMenu +}; diff --git a/index.html b/index.html index 4f0d9a3c..6f3db41a 100644 --- a/index.html +++ b/index.html @@ -1,21 +1,24 @@ + Mattermost + - + + \ No newline at end of file diff --git a/index.js b/index.js index d0a3458a..80fe0566 100644 --- a/index.js +++ b/index.js @@ -5,20 +5,21 @@ var url = require('url'); var webView = document.getElementById('mainWebview'); -try{ +try { var configFile = remote.require('app').getPath('userData') + '/config.json'; var config = require(configFile); - if(config.url){ + if (config.url) { webView.setAttribute('src', config.url); } - else{ + else { throw 'URL is not configured'; } -}catch(e){ +} +catch (e) { window.location.href = './settings.html'; } -webView.addEventListener('page-title-set', function(e){ +webView.addEventListener('page-title-set', function(e) { document.title = e.title; }); @@ -27,10 +28,10 @@ webView.addEventListener('new-window', function(e) { var currentUrl = url.parse(webView.getUrl()); var destUrl = url.parse(e.url); // Open in browserWindow. for exmaple, attached files. - if(currentUrl.host === destUrl.host){ + if (currentUrl.host === destUrl.host) { window.open(e.url, 'Mattermost'); } - else{ + else { require('shell').openExternal(e.url); } }); @@ -40,23 +41,23 @@ var timer = setInterval(function() { webView.send('retrieveUnreadCount'); }, 1000); -var showUnreadBadge = function(unreadCount){ +var showUnreadBadge = function(unreadCount) { switch (process.platform) { case 'win32': var window = remote.getCurrentWindow(); - if(unreadCount > 0){ + if (unreadCount > 0) { window.setOverlayIcon(__dirname + '/badge.png', 'You have unread channels.'); } - else{ + else { window.setOverlayIcon(null, ''); } break; case 'darwin': var app = remote.require('app'); - if(unreadCount > 0){ + if (unreadCount > 0) { app.dock.setBadge(unreadCount.toString()); } - else{ + else { app.dock.setBadge(''); } break; @@ -64,7 +65,7 @@ var showUnreadBadge = function(unreadCount){ } } -webView.addEventListener('ipc-message', function(event){ +webView.addEventListener('ipc-message', function(event) { switch (event.channel) { case 'retrieveUnreadCount': var unreadCount = event.args[0]; diff --git a/main.js b/main.js index 16f0ab60..17322a32 100644 --- a/main.js +++ b/main.js @@ -1,91 +1,94 @@ -"use strict"; - -var app = require('app'); // Module to control application life. -var BrowserWindow = require('browser-window'); // Module to create native browser window. -var Menu = require('menu'); -var appMenu = require('./app-menu'); - -// Keep a global reference of the window object, if you don't, the window will -// be closed automatically when the JavaScript object is garbage collected. -var mainWindow = null; -var willAppQuit = false; - -// Quit when all windows are closed. -app.on('window-all-closed', function() { - // On OS X it is common for applications and their menu bar - // to stay active until the user quits explicitly with Cmd + Q - if (process.platform !== 'darwin') { - app.quit(); - } -}); - -// For win32, auto-hide menu bar. -app.on('browser-window-created', function(event, window){ - if(process.platform === 'win32'){ - window.setAutoHideMenuBar(true); - window.setMenuBarVisibility(false); - } -}); - -// For OSX, show hidden mainWindow when clicking dock icon. -app.on('activate', function(event){ - mainWindow.show(); -}); - -app.on('before-quit', function(){ - willAppQuit = true; -}); - -// This method will be called when Electron has finished -// initialization and is ready to create browser windows. -app.on('ready', function() { - // Create the browser window. - mainWindow = new BrowserWindow({width: 800, height: 600}); - - // and load the index.html of the app. - mainWindow.loadUrl('file://' + __dirname + '/index.html'); - - // Open the DevTools. - // mainWindow.openDevTools(); - - mainWindow.on('close', function(event){ - // Minimize or hide the window for close button. - if(!willAppQuit){ // avoid [Ctrl|Cmd]+Q - event.preventDefault(); - switch (process.platform) { - case 'win32': - mainWindow.minimize(); - break; - case 'darwin': - mainWindow.hide(); - break; - default: - } - } - }); - - var menu = appMenu.createMenu(mainWindow); - Menu.setApplicationMenu(menu); - - // Emitted when the window is closed. - mainWindow.on('closed', function() { - // Dereference the window object, usually you would store windows - // in an array if your app supports multi windows, this is the time - // when you should delete the corresponding element. - mainWindow = null; - }); - - // Deny drag&drop navigation in mainWindow. - // Drag&drop is allowed in webview of index.html. - mainWindow.webContents.on('will-navigate', function(event, url){ - var dirname = __dirname; - if (process.platform === 'win32'){ - dirname = '/' + dirname.replace(/\\/g, '/'); - } - - var index = url.indexOf('file://' + dirname); - if(index !== 0){ - event.preventDefault(); - } - }); -}); +"use strict"; + +var app = require('app'); // Module to control application life. +var BrowserWindow = require('browser-window'); // Module to create native browser window. +var Menu = require('menu'); +var appMenu = require('./app-menu'); + +// Keep a global reference of the window object, if you don't, the window will +// be closed automatically when the JavaScript object is garbage collected. +var mainWindow = null; +var willAppQuit = false; + +// Quit when all windows are closed. +app.on('window-all-closed', function() { + // On OS X it is common for applications and their menu bar + // to stay active until the user quits explicitly with Cmd + Q + if (process.platform !== 'darwin') { + app.quit(); + } +}); + +// For win32, auto-hide menu bar. +app.on('browser-window-created', function(event, window) { + if (process.platform === 'win32') { + window.setAutoHideMenuBar(true); + window.setMenuBarVisibility(false); + } +}); + +// For OSX, show hidden mainWindow when clicking dock icon. +app.on('activate', function(event) { + mainWindow.show(); +}); + +app.on('before-quit', function() { + willAppQuit = true; +}); + +// This method will be called when Electron has finished +// initialization and is ready to create browser windows. +app.on('ready', function() { + // Create the browser window. + mainWindow = new BrowserWindow({ + width: 800, + height: 600 + }); + + // and load the index.html of the app. + mainWindow.loadUrl('file://' + __dirname + '/index.html'); + + // Open the DevTools. + // mainWindow.openDevTools(); + + mainWindow.on('close', function(event) { + // Minimize or hide the window for close button. + if (!willAppQuit) { // avoid [Ctrl|Cmd]+Q + event.preventDefault(); + switch (process.platform) { + case 'win32': + mainWindow.minimize(); + break; + case 'darwin': + mainWindow.hide(); + break; + default: + } + } + }); + + var menu = appMenu.createMenu(mainWindow); + Menu.setApplicationMenu(menu); + + // Emitted when the window is closed. + mainWindow.on('closed', function() { + // Dereference the window object, usually you would store windows + // in an array if your app supports multi windows, this is the time + // when you should delete the corresponding element. + mainWindow = null; + }); + + // Deny drag&drop navigation in mainWindow. + // Drag&drop is allowed in webview of index.html. + mainWindow.webContents.on('will-navigate', function(event, url) { + var dirname = __dirname; + if (process.platform === 'win32') { + dirname = '/' + dirname.replace(/\\/g, '/'); + } + + var index = url.indexOf('file://' + dirname); + if (index !== 0) { + event.preventDefault(); + } + }); +}); diff --git a/settings.html b/settings.html index f3594e05..453b221c 100644 --- a/settings.html +++ b/settings.html @@ -1,12 +1,16 @@ + Settings +

Settings

-

URL:

+

URL: + +

@@ -14,21 +18,22 @@ var remote = require('remote'); var fs = require('fs'); - var saveSettings = function(){ + var saveSettings = function() { var configFile = remote.require('app').getPath('userData') + '/config.json'; var urlInput = document.getElementById('url'); var config = { url: urlInput.value }; - fs.writeFile(configFile, JSON.stringify(config, null, ' '), function(err){ - if(err) throw err; + fs.writeFile(configFile, JSON.stringify(config, null, ' '), function(err) { + if (err) throw err; window.location.href = './index.html'; }); } - var goBack = function(){ + var goBack = function() { remote.getCurrentWindow().webContents.goBack(); } - + + \ No newline at end of file diff --git a/webview/mattermost.js b/webview/mattermost.js index 782ee49f..22316560 100644 --- a/webview/mattermost.js +++ b/webview/mattermost.js @@ -2,7 +2,7 @@ var ipc = require('ipc'); -ipc.on('retrieveUnreadCount', function(){ +ipc.on('retrieveUnreadCount', function() { var unreadCount = document.getElementsByClassName('unread-title').length; ipc.sendToHost('retrieveUnreadCount', unreadCount); });