Updated project structure

This commit is contained in:
2019-02-11 19:07:16 +01:00
parent cb3867584f
commit 250a4544ab
4 changed files with 2 additions and 2 deletions

136
modules/ApplicationMenu.js Normal file
View File

@ -0,0 +1,136 @@
/**
* Application menu
*
* @author Comunic Authors
*/
const {app, Menu} = require('electron');
/**
* Get application menu
*
* @param {BrowserWindow} window
* @return {Menu} Application menu
*/
module.exports.Get = function(window){
/**
* Execute javascript quickly
*/
let js = function(code) {window.webContents.executeJavaScript(code)};
return Menu.buildFromTemplate([
//File menu
{
label: "File",
submenu: [
//Close app
{
label: "Quit",
click: () => {
app.quit();
}
}
]
},
//Shorcuts menu
{
label: "Shorcuts",
submenu: [
//Latest posts
{
label: "Latest posts",
click: () => {
js("openPage('latest');");
}
},
//User page
{
label: "Your page",
click: () => {
js("openPage('user/' + userID());");
}
},
//Conversations
{
label: "Conversations",
click: () => {
js("openPage('conversations');");
}
},
//Groups
{
label: "Groups",
click: () => {
js("openPage('groups');");
}
}
]
},
//Settings menu
{
label: "Settings",
submenu: [
//Dark mode
{
label: "Toggle dark mode",
click: () => {
js("ComunicWeb.components.darkTheme.setEnabled(!ComunicWeb.components.darkTheme.isEnabled());");
}
},
//Incognito mode
{
label: "Enable incognito mode",
sublabel: "F6",
click: () => {
js("ComunicWeb.components.incognito.ui.confirmEnable();");
}
},
//Account settings
{
label: "Account settings",
click: () => {
js("openPage('settings');");
}
}
]
},
//Advanced menu
{
label: "Advanced",
submenu: [
//Dev tools
{
label: "Toggle developer tools",
click: () => {
window.webContents.toggleDevTools();
}
}
]
}
])
}

62
modules/MainWindow.js Normal file
View File

@ -0,0 +1,62 @@
/**
* Main Window script
*
* @author The Comunic authors
*/
const electron = require('electron');
const BrowserWindow = electron.BrowserWindow;
const {Menu, Tray} = require('electron');
const Config = require("../Config");
const TrayMenu = require("./TrayMenu");
const ApplicationMenu = require("./ApplicationMenu");
let mainWindow;
let tray = null;
let page_finished_loading = false;
/**
* Show main window
*/
exports.show = function(){
//Create and show main window
mainWindow = new BrowserWindow({
icon:'icon.png',
webPreferences: {
nodeIntegration: false
},
//show: false
});
//mainWindow.maximize();
//set the url which must be open
mainWindow.loadURL(Config.access_url);
mainWindow.on('closed', () =>{
//To close the window
mainWindow = null;
});
//Create tray
tray = new Tray('./icon.png');
tray.setToolTip('Comunic');
tray.setContextMenu(TrayMenu);
console.log("Started successfully");
//Set application menu
Menu.setApplicationMenu(ApplicationMenu.Get(mainWindow));
mainWindow.once('ready-to-show', () => {
mainWindow.show();
});
mainWindow.webContents.on('did-finish-load', function() {
page_finished_loading = true;
});
}

14
modules/TrayMenu.js Normal file
View File

@ -0,0 +1,14 @@
/**
* Tray menu
*
* @author Comunic Authors
*/
const {app, Menu} = require('electron');
module.exports = Menu.buildFromTemplate([{
label : 'Close',
click: () => {
app.quit();
console.log("Closed");
}
}]);