gulp prettifyを実行
This commit is contained in:
167
app-menu.js
167
app-menu.js
@@ -2,113 +2,102 @@
|
|||||||
|
|
||||||
var Menu = require('menu');
|
var Menu = require('menu');
|
||||||
|
|
||||||
var createTemplate = function(mainWindow){
|
var createTemplate = function(mainWindow) {
|
||||||
var first_menu_name = (process.platform === 'darwin') ? require('app').getName() : 'File';
|
var first_menu_name = (process.platform === 'darwin') ? require('app').getName() : 'File';
|
||||||
var template = [];
|
var template = [];
|
||||||
template.push({
|
template.push({
|
||||||
label: first_menu_name,
|
label: first_menu_name,
|
||||||
submenu: [
|
submenu: [{
|
||||||
{
|
label: 'Settings',
|
||||||
label: 'Settings',
|
click: function(item, focusedWindow) {
|
||||||
click: function(item, focusedWindow){
|
mainWindow.loadUrl('file://' + __dirname + '/settings.html');
|
||||||
mainWindow.loadUrl('file://' + __dirname + '/settings.html');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Quit',
|
|
||||||
accelerator: 'CmdOrCtrl+Q',
|
|
||||||
click: function(item, focusedWindow){
|
|
||||||
require('app').quit();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
]
|
}, {
|
||||||
|
label: 'Quit',
|
||||||
|
accelerator: 'CmdOrCtrl+Q',
|
||||||
|
click: function(item, focusedWindow) {
|
||||||
|
require('app').quit();
|
||||||
|
}
|
||||||
|
}]
|
||||||
});
|
});
|
||||||
template.push({
|
template.push({
|
||||||
label: 'Edit',
|
label: 'Edit',
|
||||||
submenu: [
|
submenu: [{
|
||||||
{
|
label: 'Undo',
|
||||||
label: 'Undo',
|
accelerator: 'CmdOrCtrl+Z',
|
||||||
accelerator: 'CmdOrCtrl+Z',
|
role: 'undo'
|
||||||
role: 'undo'
|
}, {
|
||||||
},
|
label: 'Redo',
|
||||||
{
|
accelerator: 'Shift+CmdOrCtrl+Z',
|
||||||
label: 'Redo',
|
role: 'redo'
|
||||||
accelerator: 'Shift+CmdOrCtrl+Z',
|
}, {
|
||||||
role: 'redo'
|
type: 'separator'
|
||||||
},
|
}, {
|
||||||
{
|
label: 'Cut',
|
||||||
type: 'separator'
|
accelerator: 'CmdOrCtrl+X',
|
||||||
},
|
role: 'cut'
|
||||||
{
|
}, {
|
||||||
label: 'Cut',
|
label: 'Copy',
|
||||||
accelerator: 'CmdOrCtrl+X',
|
accelerator: 'CmdOrCtrl+C',
|
||||||
role: 'cut'
|
role: 'copy'
|
||||||
},
|
}, {
|
||||||
{
|
label: 'Paste',
|
||||||
label: 'Copy',
|
accelerator: 'CmdOrCtrl+V',
|
||||||
accelerator: 'CmdOrCtrl+C',
|
role: 'paste'
|
||||||
role: 'copy'
|
}, {
|
||||||
},
|
label: 'Select All',
|
||||||
{
|
accelerator: 'CmdOrCtrl+A',
|
||||||
label: 'Paste',
|
role: 'selectall'
|
||||||
accelerator: 'CmdOrCtrl+V',
|
}, ]
|
||||||
role: 'paste'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Select All',
|
|
||||||
accelerator: 'CmdOrCtrl+A',
|
|
||||||
role: 'selectall'
|
|
||||||
},
|
|
||||||
]
|
|
||||||
});
|
});
|
||||||
template.push({
|
template.push({
|
||||||
label: 'View',
|
label: 'View',
|
||||||
submenu: [
|
submenu: [{
|
||||||
{
|
label: 'Reload',
|
||||||
label: 'Reload',
|
accelerator: 'CmdOrCtrl+R',
|
||||||
accelerator: 'CmdOrCtrl+R',
|
click: function(item, focusedWindow) {
|
||||||
click: function(item, focusedWindow) {
|
if (focusedWindow)
|
||||||
if (focusedWindow)
|
focusedWindow.reload();
|
||||||
focusedWindow.reload();
|
}
|
||||||
|
}, {
|
||||||
|
label: 'Toggle Full Screen',
|
||||||
|
accelerator: (function() {
|
||||||
|
if (process.platform === 'darwin') {
|
||||||
|
return 'Ctrl+Command+F';
|
||||||
}
|
}
|
||||||
},
|
else {
|
||||||
{
|
return 'F11';
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
})(),
|
||||||
{
|
click: function(item, focusedWindow) {
|
||||||
label: 'Toggle Developer Tools',
|
if (focusedWindow) {
|
||||||
accelerator: (function() {
|
focusedWindow.setFullScreen(!focusedWindow.isFullScreen());
|
||||||
if (process.platform === 'darwin') {
|
|
||||||
return 'Alt+Command+I';
|
|
||||||
} else {
|
|
||||||
return 'Ctrl+Shift+I';
|
|
||||||
}
|
|
||||||
})(),
|
|
||||||
click: function(item, focusedWindow) {
|
|
||||||
if (focusedWindow) {
|
|
||||||
focusedWindow.toggleDevTools();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
]
|
}, {
|
||||||
|
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;
|
return template;
|
||||||
};
|
};
|
||||||
|
|
||||||
var createMenu = function(mainWindow){
|
var createMenu = function(mainWindow) {
|
||||||
return Menu.buildFromTemplate(createTemplate(mainWindow));
|
return Menu.buildFromTemplate(createTemplate(mainWindow));
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = { createMenu: createMenu };
|
module.exports = {
|
||||||
|
createMenu: createMenu
|
||||||
|
};
|
||||||
|
19
index.html
19
index.html
@@ -1,21 +1,24 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>Mattermost</title>
|
<title>Mattermost</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<!-- Modify src to your Mattermost url -->
|
<!-- Modify src to your Mattermost url -->
|
||||||
<webview id="mainWebview" autosize="on" preload="webview/mattermost.js"></webview>
|
<webview id="mainWebview" autosize="on" preload="webview/mattermost.js"></webview>
|
||||||
<style>
|
<style>
|
||||||
webview {
|
webview {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: 0;
|
||||||
right: 0;
|
right: 0;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<script src="./index.js"></script>
|
<script src="./index.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
|
||||||
|
</html>
|
27
index.js
27
index.js
@@ -5,20 +5,21 @@ var url = require('url');
|
|||||||
|
|
||||||
var webView = document.getElementById('mainWebview');
|
var webView = document.getElementById('mainWebview');
|
||||||
|
|
||||||
try{
|
try {
|
||||||
var configFile = remote.require('app').getPath('userData') + '/config.json';
|
var configFile = remote.require('app').getPath('userData') + '/config.json';
|
||||||
var config = require(configFile);
|
var config = require(configFile);
|
||||||
if(config.url){
|
if (config.url) {
|
||||||
webView.setAttribute('src', config.url);
|
webView.setAttribute('src', config.url);
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
throw 'URL is not configured';
|
throw 'URL is not configured';
|
||||||
}
|
}
|
||||||
}catch(e){
|
}
|
||||||
|
catch (e) {
|
||||||
window.location.href = './settings.html';
|
window.location.href = './settings.html';
|
||||||
}
|
}
|
||||||
|
|
||||||
webView.addEventListener('page-title-set', function(e){
|
webView.addEventListener('page-title-set', function(e) {
|
||||||
document.title = e.title;
|
document.title = e.title;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -27,10 +28,10 @@ webView.addEventListener('new-window', function(e) {
|
|||||||
var currentUrl = url.parse(webView.getUrl());
|
var currentUrl = url.parse(webView.getUrl());
|
||||||
var destUrl = url.parse(e.url);
|
var destUrl = url.parse(e.url);
|
||||||
// Open in browserWindow. for exmaple, attached files.
|
// Open in browserWindow. for exmaple, attached files.
|
||||||
if(currentUrl.host === destUrl.host){
|
if (currentUrl.host === destUrl.host) {
|
||||||
window.open(e.url, 'Mattermost');
|
window.open(e.url, 'Mattermost');
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
require('shell').openExternal(e.url);
|
require('shell').openExternal(e.url);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -40,23 +41,23 @@ var timer = setInterval(function() {
|
|||||||
webView.send('retrieveUnreadCount');
|
webView.send('retrieveUnreadCount');
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
||||||
var showUnreadBadge = function(unreadCount){
|
var showUnreadBadge = function(unreadCount) {
|
||||||
switch (process.platform) {
|
switch (process.platform) {
|
||||||
case 'win32':
|
case 'win32':
|
||||||
var window = remote.getCurrentWindow();
|
var window = remote.getCurrentWindow();
|
||||||
if(unreadCount > 0){
|
if (unreadCount > 0) {
|
||||||
window.setOverlayIcon(__dirname + '/badge.png', 'You have unread channels.');
|
window.setOverlayIcon(__dirname + '/badge.png', 'You have unread channels.');
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
window.setOverlayIcon(null, '');
|
window.setOverlayIcon(null, '');
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'darwin':
|
case 'darwin':
|
||||||
var app = remote.require('app');
|
var app = remote.require('app');
|
||||||
if(unreadCount > 0){
|
if (unreadCount > 0) {
|
||||||
app.dock.setBadge(unreadCount.toString());
|
app.dock.setBadge(unreadCount.toString());
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
app.dock.setBadge('');
|
app.dock.setBadge('');
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -64,7 +65,7 @@ var showUnreadBadge = function(unreadCount){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
webView.addEventListener('ipc-message', function(event){
|
webView.addEventListener('ipc-message', function(event) {
|
||||||
switch (event.channel) {
|
switch (event.channel) {
|
||||||
case 'retrieveUnreadCount':
|
case 'retrieveUnreadCount':
|
||||||
var unreadCount = event.args[0];
|
var unreadCount = event.args[0];
|
||||||
|
185
main.js
185
main.js
@@ -1,91 +1,94 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var app = require('app'); // Module to control application life.
|
var app = require('app'); // Module to control application life.
|
||||||
var BrowserWindow = require('browser-window'); // Module to create native browser window.
|
var BrowserWindow = require('browser-window'); // Module to create native browser window.
|
||||||
var Menu = require('menu');
|
var Menu = require('menu');
|
||||||
var appMenu = require('./app-menu');
|
var appMenu = require('./app-menu');
|
||||||
|
|
||||||
// Keep a global reference of the window object, if you don't, the window will
|
// 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.
|
// be closed automatically when the JavaScript object is garbage collected.
|
||||||
var mainWindow = null;
|
var mainWindow = null;
|
||||||
var willAppQuit = false;
|
var willAppQuit = false;
|
||||||
|
|
||||||
// Quit when all windows are closed.
|
// Quit when all windows are closed.
|
||||||
app.on('window-all-closed', function() {
|
app.on('window-all-closed', function() {
|
||||||
// On OS X it is common for applications and their menu bar
|
// On OS X it is common for applications and their menu bar
|
||||||
// to stay active until the user quits explicitly with Cmd + Q
|
// to stay active until the user quits explicitly with Cmd + Q
|
||||||
if (process.platform !== 'darwin') {
|
if (process.platform !== 'darwin') {
|
||||||
app.quit();
|
app.quit();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// For win32, auto-hide menu bar.
|
// For win32, auto-hide menu bar.
|
||||||
app.on('browser-window-created', function(event, window){
|
app.on('browser-window-created', function(event, window) {
|
||||||
if(process.platform === 'win32'){
|
if (process.platform === 'win32') {
|
||||||
window.setAutoHideMenuBar(true);
|
window.setAutoHideMenuBar(true);
|
||||||
window.setMenuBarVisibility(false);
|
window.setMenuBarVisibility(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// For OSX, show hidden mainWindow when clicking dock icon.
|
// For OSX, show hidden mainWindow when clicking dock icon.
|
||||||
app.on('activate', function(event){
|
app.on('activate', function(event) {
|
||||||
mainWindow.show();
|
mainWindow.show();
|
||||||
});
|
});
|
||||||
|
|
||||||
app.on('before-quit', function(){
|
app.on('before-quit', function() {
|
||||||
willAppQuit = true;
|
willAppQuit = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
// This method will be called when Electron has finished
|
// This method will be called when Electron has finished
|
||||||
// initialization and is ready to create browser windows.
|
// initialization and is ready to create browser windows.
|
||||||
app.on('ready', function() {
|
app.on('ready', function() {
|
||||||
// Create the browser window.
|
// Create the browser window.
|
||||||
mainWindow = new BrowserWindow({width: 800, height: 600});
|
mainWindow = new BrowserWindow({
|
||||||
|
width: 800,
|
||||||
// and load the index.html of the app.
|
height: 600
|
||||||
mainWindow.loadUrl('file://' + __dirname + '/index.html');
|
});
|
||||||
|
|
||||||
// Open the DevTools.
|
// and load the index.html of the app.
|
||||||
// mainWindow.openDevTools();
|
mainWindow.loadUrl('file://' + __dirname + '/index.html');
|
||||||
|
|
||||||
mainWindow.on('close', function(event){
|
// Open the DevTools.
|
||||||
// Minimize or hide the window for close button.
|
// mainWindow.openDevTools();
|
||||||
if(!willAppQuit){ // avoid [Ctrl|Cmd]+Q
|
|
||||||
event.preventDefault();
|
mainWindow.on('close', function(event) {
|
||||||
switch (process.platform) {
|
// Minimize or hide the window for close button.
|
||||||
case 'win32':
|
if (!willAppQuit) { // avoid [Ctrl|Cmd]+Q
|
||||||
mainWindow.minimize();
|
event.preventDefault();
|
||||||
break;
|
switch (process.platform) {
|
||||||
case 'darwin':
|
case 'win32':
|
||||||
mainWindow.hide();
|
mainWindow.minimize();
|
||||||
break;
|
break;
|
||||||
default:
|
case 'darwin':
|
||||||
}
|
mainWindow.hide();
|
||||||
}
|
break;
|
||||||
});
|
default:
|
||||||
|
}
|
||||||
var menu = appMenu.createMenu(mainWindow);
|
}
|
||||||
Menu.setApplicationMenu(menu);
|
});
|
||||||
|
|
||||||
// Emitted when the window is closed.
|
var menu = appMenu.createMenu(mainWindow);
|
||||||
mainWindow.on('closed', function() {
|
Menu.setApplicationMenu(menu);
|
||||||
// Dereference the window object, usually you would store windows
|
|
||||||
// in an array if your app supports multi windows, this is the time
|
// Emitted when the window is closed.
|
||||||
// when you should delete the corresponding element.
|
mainWindow.on('closed', function() {
|
||||||
mainWindow = null;
|
// 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.
|
||||||
// Deny drag&drop navigation in mainWindow.
|
mainWindow = null;
|
||||||
// Drag&drop is allowed in webview of index.html.
|
});
|
||||||
mainWindow.webContents.on('will-navigate', function(event, url){
|
|
||||||
var dirname = __dirname;
|
// Deny drag&drop navigation in mainWindow.
|
||||||
if (process.platform === 'win32'){
|
// Drag&drop is allowed in webview of index.html.
|
||||||
dirname = '/' + dirname.replace(/\\/g, '/');
|
mainWindow.webContents.on('will-navigate', function(event, url) {
|
||||||
}
|
var dirname = __dirname;
|
||||||
|
if (process.platform === 'win32') {
|
||||||
var index = url.indexOf('file://' + dirname);
|
dirname = '/' + dirname.replace(/\\/g, '/');
|
||||||
if(index !== 0){
|
}
|
||||||
event.preventDefault();
|
|
||||||
}
|
var index = url.indexOf('file://' + dirname);
|
||||||
});
|
if (index !== 0) {
|
||||||
});
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
@@ -1,12 +1,16 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>Settings</title>
|
<title>Settings</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<h1>Settings</h1>
|
<h1>Settings</h1>
|
||||||
<p>URL: <input type="text" id="url"></p>
|
<p>URL:
|
||||||
|
<input type="text" id="url">
|
||||||
|
</p>
|
||||||
<input type="button" value="OK" onclick="saveSettings()">
|
<input type="button" value="OK" onclick="saveSettings()">
|
||||||
<input type="button" value="Cancel" onclick="goBack()">
|
<input type="button" value="Cancel" onclick="goBack()">
|
||||||
|
|
||||||
@@ -14,21 +18,22 @@
|
|||||||
var remote = require('remote');
|
var remote = require('remote');
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
|
|
||||||
var saveSettings = function(){
|
var saveSettings = function() {
|
||||||
var configFile = remote.require('app').getPath('userData') + '/config.json';
|
var configFile = remote.require('app').getPath('userData') + '/config.json';
|
||||||
var urlInput = document.getElementById('url');
|
var urlInput = document.getElementById('url');
|
||||||
var config = {
|
var config = {
|
||||||
url: urlInput.value
|
url: urlInput.value
|
||||||
};
|
};
|
||||||
fs.writeFile(configFile, JSON.stringify(config, null, ' '), function(err){
|
fs.writeFile(configFile, JSON.stringify(config, null, ' '), function(err) {
|
||||||
if(err) throw err;
|
if (err) throw err;
|
||||||
window.location.href = './index.html';
|
window.location.href = './index.html';
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var goBack = function(){
|
var goBack = function() {
|
||||||
remote.getCurrentWindow().webContents.goBack();
|
remote.getCurrentWindow().webContents.goBack();
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
|
||||||
|
</html>
|
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
var ipc = require('ipc');
|
var ipc = require('ipc');
|
||||||
|
|
||||||
ipc.on('retrieveUnreadCount', function(){
|
ipc.on('retrieveUnreadCount', function() {
|
||||||
var unreadCount = document.getElementsByClassName('unread-title').length;
|
var unreadCount = document.getElementsByClassName('unread-title').length;
|
||||||
ipc.sendToHost('retrieveUnreadCount', unreadCount);
|
ipc.sendToHost('retrieveUnreadCount', unreadCount);
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user