mirror of
https://github.com/zulip/zulip-desktop.git
synced 2025-10-24 16:43:38 +00:00
🚀 change domain menu added
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
const electron = require('electron');
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const electron = require('electron');
|
||||||
|
|
||||||
|
|
||||||
let aboutWindow;
|
let aboutWindow;
|
||||||
@@ -18,7 +18,7 @@ function createAboutWindow() {
|
|||||||
center: true,
|
center: true,
|
||||||
fullscreen: false,
|
fullscreen: false,
|
||||||
fullscreenable: false,
|
fullscreenable: false,
|
||||||
resizable: false
|
resizable: false
|
||||||
})
|
})
|
||||||
const aboutURL = 'file://' + path.join(__dirname, '../renderer', 'about.html');
|
const aboutURL = 'file://' + path.join(__dirname, '../renderer', 'about.html');
|
||||||
aboutwin.loadURL(aboutURL);
|
aboutwin.loadURL(aboutURL);
|
||||||
@@ -26,12 +26,12 @@ function createAboutWindow() {
|
|||||||
|
|
||||||
// stop page to update it's title
|
// stop page to update it's title
|
||||||
aboutwin.on('page-title-updated', (e) => {
|
aboutwin.on('page-title-updated', (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
});
|
});
|
||||||
|
|
||||||
return aboutwin;
|
return aboutwin;
|
||||||
}
|
}
|
||||||
|
|
||||||
exports = module.exports = {
|
exports = module.exports = {
|
||||||
createAboutWindow, onClosed
|
createAboutWindow, onClosed
|
||||||
};
|
};
|
||||||
|
|||||||
24
app/main/domain.js
Normal file
24
app/main/domain.js
Normal 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
|
||||||
|
};
|
||||||
@@ -2,18 +2,17 @@
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
const electron = require('electron');
|
const electron = require('electron');
|
||||||
const {app, shell} = require('electron');
|
const {app, shell} = require('electron');
|
||||||
|
const ipc = require('electron').ipcMain;
|
||||||
|
|
||||||
const tray = require('./tray');
|
const tray = require('./tray');
|
||||||
const link = require ('./link_helper');
|
const link = require ('./link_helper');
|
||||||
|
|
||||||
|
|
||||||
const {linkIsInternal} = link;
|
const {linkIsInternal} = link;
|
||||||
|
|
||||||
// adds debug features like hotkeys for triggering dev tools and reload
|
// adds debug features like hotkeys for triggering dev tools and reload
|
||||||
require('electron-debug')();
|
require('electron-debug')();
|
||||||
|
|
||||||
// Load this url in main window
|
// 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
|
// prevent window being garbage collected
|
||||||
let mainWindow;
|
let mainWindow;
|
||||||
@@ -78,3 +77,7 @@ app.on('ready', () => {
|
|||||||
electron.shell.openExternal(url);
|
electron.shell.openExternal(url);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ipc.on('new-domain', function (e, domain) {
|
||||||
|
mainWindow.loadURL(domain);
|
||||||
|
});
|
||||||
@@ -4,10 +4,13 @@ const electron = require('electron');
|
|||||||
const app = require('electron').app;
|
const app = require('electron').app;
|
||||||
const {shell} = require('electron');
|
const {shell} = require('electron');
|
||||||
const about = require ('./about');
|
const about = require ('./about');
|
||||||
|
const domain = require ('./domain');
|
||||||
const { createAboutWindow, onClosed } = about;
|
const { createAboutWindow, onClosed } = about;
|
||||||
|
const { createdomainWindow } = domain;
|
||||||
|
|
||||||
let tray = null;
|
let tray = null;
|
||||||
let aboutWindow;
|
let aboutWindow;
|
||||||
|
let domainWindow;
|
||||||
|
|
||||||
exports.create = win => {
|
exports.create = win => {
|
||||||
if (process.platform === 'darwin' || tray) {
|
if (process.platform === 'darwin' || tray) {
|
||||||
@@ -33,6 +36,11 @@ exports.create = win => {
|
|||||||
aboutWindow.show();
|
aboutWindow.show();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const addDomain = () => {
|
||||||
|
domainWindow = createdomainWindow();
|
||||||
|
domainWindow.show();
|
||||||
|
};
|
||||||
|
|
||||||
const contextMenu = electron.Menu.buildFromTemplate([
|
const contextMenu = electron.Menu.buildFromTemplate([
|
||||||
{
|
{
|
||||||
label: 'About',
|
label: 'About',
|
||||||
@@ -43,6 +51,15 @@ exports.create = win => {
|
|||||||
{
|
{
|
||||||
type: 'separator'
|
type: 'separator'
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: 'Add new domain',
|
||||||
|
click() {
|
||||||
|
addDomain();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'separator'
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: 'Toggle',
|
label: 'Toggle',
|
||||||
click() {
|
click() {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<link rel="stylesheet" href="about.css">
|
<link rel="stylesheet" href="css/about.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="about">
|
<div class="about">
|
||||||
|
|||||||
24
app/renderer/css/pref.css
Normal file
24
app/renderer/css/pref.css
Normal 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
BIN
app/renderer/img/close.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 803 B |
@@ -2,9 +2,9 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<link rel="stylesheet" href="main.css">
|
<link rel="stylesheet" href="css/main.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<script src="main.js"></script>
|
<script src="js/main.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
19
app/renderer/js/main.js
Normal file
19
app/renderer/js/main.js
Normal 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
20
app/renderer/js/pref.js
Normal 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);
|
||||||
|
}
|
||||||
@@ -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
18
app/renderer/pref.html
Normal 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>
|
||||||
Reference in New Issue
Block a user