MattermostのURLをユーザーごとの設定フォルダに保存するように変更

This commit is contained in:
Yuya Ochiai 2015-10-09 22:50:48 +09:00
parent 6de38f9b32
commit e86c7f31f6
4 changed files with 55 additions and 2 deletions

View file

@ -6,7 +6,7 @@
</head>
<body>
<!-- Modify src to your Mattermost url -->
<webview id="mainWebview" src="http://192.168.99.100:8065" autosize="on" preload="./webview/mattermost.js"></webview>
<webview id="mainWebview" autosize="on"></webview>
<style>
webview {
position: absolute;

View file

@ -5,6 +5,19 @@ var url = require('url');
var webView = document.getElementById('mainWebview');
try{
var configFile = remote.require('app').getPath('userData') + '/config.json';
var config = require(configFile);
if(config.url){
webView.setAttribute('src', config.url);
}
else{
throw 'URL is not configured';
}
}catch(e){
window.location.href = './settings.html';
}
webView.addEventListener('page-title-set', function(e){
document.title = e.title;
});

View file

@ -43,8 +43,14 @@ app.on('ready', function() {
if(process.platform==='win32'){
var menu = Menu.buildFromTemplate([
{
label: 'File',
label: 'Menu',
submenu: [
{
label: 'Settings',
click: function(item, focusedWindow){
mainWindow.loadUrl(__dirname + '/settings.html');
}
},
{
label: 'Quit',
accelerator: 'Ctrl + Q',

34
settings.html Normal file
View file

@ -0,0 +1,34 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Settings</title>
</head>
<body>
<h1>Settings</h1>
<p>URL: <input type="text" id="url"></p>
<input type="button" value="OK" onclick="saveSettings()">
<input type="button" value="Cancel" onclick="goBack()">
<script type="text/javascript">
var remote = require('remote');
var fs = require('fs');
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;
window.location.href = './index.html';
});
}
var goBack = function(){
remote.getCurrentWindow().webContents.goBack();
}
</script>
</body>
</html>