🚀 change domain menu added

This commit is contained in:
akashnimare
2016-07-03 16:22:12 +05:30
parent 4bceb634ac
commit 70d255926e
14 changed files with 137 additions and 33 deletions

View File

@@ -1,6 +1,6 @@
'use strict';
const electron = require('electron');
const path = require('path');
const electron = require('electron');
let aboutWindow;
@@ -18,7 +18,7 @@ function createAboutWindow() {
center: true,
fullscreen: false,
fullscreenable: false,
resizable: false
resizable: false
})
const aboutURL = 'file://' + path.join(__dirname, '../renderer', 'about.html');
aboutwin.loadURL(aboutURL);
@@ -26,12 +26,12 @@ function createAboutWindow() {
// stop page to update it's title
aboutwin.on('page-title-updated', (e) => {
e.preventDefault();
e.preventDefault();
});
return aboutwin;
}
exports = module.exports = {
createAboutWindow, onClosed
};
};

24
app/main/domain.js Normal file
View File

@@ -0,0 +1,24 @@
'use strict';
const electron = require('electron');
const path = require('path');
const {app} = require('electron');
const ipc = require('electron').ipcMain;
let domainWindow;
function createdomainWindow() {
const domainwin = new electron.BrowserWindow({
frame: false,
height: 200,
resizable: false,
width: 300
})
const domainURL = 'file://' + path.join(__dirname, '../renderer', 'pref.html');
domainwin.loadURL(domainURL);
return domainwin;
}
exports = module.exports = {
createdomainWindow
};

View File

@@ -2,18 +2,17 @@
const path = require('path');
const electron = require('electron');
const {app, shell} = require('electron');
const ipc = require('electron').ipcMain;
const tray = require('./tray');
const link = require ('./link_helper');
const {linkIsInternal} = link;
// adds debug features like hotkeys for triggering dev tools and reload
require('electron-debug')();
// Load this url in main window
const targetUrl = 'file://' + path.join(__dirname, '../renderer', 'index.html');
const targetUrl = 'file://' + path.join(__dirname, '../renderer', 'index.html');
// prevent window being garbage collected
let mainWindow;
@@ -78,3 +77,7 @@ app.on('ready', () => {
electron.shell.openExternal(url);
});
});
ipc.on('new-domain', function (e, domain) {
mainWindow.loadURL(domain);
});

View File

@@ -4,10 +4,13 @@ const electron = require('electron');
const app = require('electron').app;
const {shell} = require('electron');
const about = require ('./about');
const domain = require ('./domain');
const { createAboutWindow, onClosed } = about;
const { createdomainWindow } = domain;
let tray = null;
let aboutWindow;
let domainWindow;
exports.create = win => {
if (process.platform === 'darwin' || tray) {
@@ -33,6 +36,11 @@ exports.create = win => {
aboutWindow.show();
};
const addDomain = () => {
domainWindow = createdomainWindow();
domainWindow.show();
};
const contextMenu = electron.Menu.buildFromTemplate([
{
label: 'About',
@@ -43,6 +51,15 @@ exports.create = win => {
{
type: 'separator'
},
{
label: 'Add new domain',
click() {
addDomain();
}
},
{
type: 'separator'
},
{
label: 'Toggle',
click() {

View File

@@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="about.css">
<link rel="stylesheet" href="css/about.css">
</head>
<body>
<div class="about">

24
app/renderer/css/pref.css Normal file
View File

@@ -0,0 +1,24 @@
body{
background-color: #6BB6C7
}
.form {
position: absolute;
top: 42%;
left: 13%;
}
.close {
background: transparent url('../img/close.png') no-repeat 4px 4px;
background-size: 24px 24px;
cursor: pointer;
display: inline-block;
height: 32px;
position: absolute;
right: 6px;
text-indent: -10000px;
top: 6px;
width: 32px;
z-index: 1;
-webkit-app-region: no-drag;
}

BIN
app/renderer/img/close.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 803 B

View File

@@ -2,9 +2,9 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="main.css">
<link rel="stylesheet" href="css/main.css">
</head>
<body>
<script src="main.js"></script>
<script src="js/main.js"></script>
</body>
</html>

19
app/renderer/js/main.js Normal file
View File

@@ -0,0 +1,19 @@
window.onload = function getURL() {
const JsonDB = require('node-json-db');
const dialogs = require('dialogs');
const db = new JsonDB("domain", true, true);
const data = db.getData("/");
if (data["domain"] !== undefined) {
window.location.href = 'https://' + data["domain"];
} else {
dialogs.prompt('Enter the URL for your Zulip server', function(url) {
db.push("/domain", url);
window.location.href = 'https://' + url ;
})
}
const addPlaceHolder = document.getElementsByTagName('input')[0];
addPlaceHolder.setAttribute('placeholder', 'zulip.example.com');
}

20
app/renderer/js/pref.js Normal file
View File

@@ -0,0 +1,20 @@
'use strict';
const {remote} = require('electron');
document.getElementById('close-button').addEventListener('click', function (e) {
let window = remote.getCurrentWindow();
window.close();
});
function addDomain() {
const ipcRenderer = require('electron').ipcRenderer;
const JsonDB = require('node-json-db');
const db = new JsonDB('domain', true, true);
const newDomain = document.getElementById('url').value;
const domain = 'https://' + newDomain;
document.getElementById('urladded').innerHTML = newDomain + ' Added';
db.push('/domain', newDomain);
ipcRenderer.send('new-domain', domain);
}

View File

@@ -1,21 +0,0 @@
window.onload = function getURL() {
var shell = require('electron').shell;
var JsonDB = require('node-json-db');
var db = new JsonDB("domain", true, true);
var data = db.getData("/");
if (data["domain"] !== undefined) {
window.location.href = 'https://' + data["domain"];
} else {
var dialogs = require('dialogs')()
dialogs.prompt('Enter the URL for your Zulip server', function(ok) {
db.push("/domain", ok);
console.log(db);
window.location.href = 'https://' + ok;
})
}
var addPlaceHolder = document.getElementsByTagName('input')[0];
addPlaceHolder.setAttribute('placeholder', 'zulip.example.com');
}

18
app/renderer/pref.html Normal file
View File

@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="css/pref.css">
</head>
<body>
<div class="close" id="close-button">Close</div>
<div class="form">
<form onsubmit="addDomain(); return false">
<input id="url" type="text" placeholder="zulip.example.com">
<button type="submit" id="main" value="Submit" onclick="addDomain();">Add</button>
</form>
<p id="urladded"><p>
</div>
<script src="js/pref.js"></script>
</body>
</html>