gulp prettifyを実行
This commit is contained in:
parent
3004e117bb
commit
2bb5169f08
167
app-menu.js
167
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
|
||||
};
|
||||
|
|
19
index.html
19
index.html
|
@ -1,21 +1,24 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Mattermost</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<!-- Modify src to your Mattermost url -->
|
||||
<webview id="mainWebview" autosize="on" preload="webview/mattermost.js"></webview>
|
||||
<style>
|
||||
webview {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
}
|
||||
webview {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
}
|
||||
</style>
|
||||
<script src="./index.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
</html>
|
27
index.js
27
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];
|
||||
|
|
185
main.js
185
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();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Settings</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<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="Cancel" onclick="goBack()">
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
</html>
|
|
@ -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);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue