Skip to content

Commit

Permalink
Create the main.js and refactor with src files
Browse files Browse the repository at this point in the history
  • Loading branch information
matfranca committed Jun 24, 2020
1 parent 6b9fb39 commit b7bd2bf
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 132 deletions.
137 changes: 137 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
const { app, BrowserWindow, Tray, Menu, ipcMain } = require('electron');
const shell = require('electron').shell;

// Handle creating/removing shortcuts on Windows when installing/uninstalling.
if (require('electron-squirrel-startup')) { // eslint-disable-line global-require
app.quit();
}


const createWindow = () => {
// Create the browser window.
const mainWindow = new BrowserWindow({
width: 340,
resizable: false,
height: 500,
maximizable: false,
frame: false,
enableLargerThanScreen: false,
opacity: 0.90,
titleBarStyle: "hidden",
webPreferences: {
nodeIntegration: true
},
});

// and load the index.html of the app.
mainWindow.loadFile('src/index.html');

// Open the DevTools.
// mainWindow.webContents.openDevTools();

// var menu = Menu.buildFromTemplate([
// {
// label: 'Menu',
// submenu: [
// {
// label: 'Hello',
// click() {
// console.log('World');
// }
// },
// {
// label: 'Hide from everybody',
// click() {
// app.hide(createWindow);
// }
// },
// {
// label: 'Tray On/Off',
// click() {
// tray.hide();
// }
// },
// {
// label: 'Exit',
// click(){
// app.quit;
// }
// }
// ]
// }
// ])

// Menu.setApplicationMenu(menu);
};

app.whenReady().then(createWindow);

// app.dock.hide();

let tray = null;

app.on('ready', () => {
tray = new Tray('public/assets/logo_16x16.png');
const contextMenu = Menu.buildFromTemplate([
{
label: 'Opacidade Settings',
submenu: [
{
label: 'Opacidade +',
},
{
label: 'Opacidade -' ,
}
]
},
{
label: 'Sair',
click (){
createWindow.call(createWindow);
}
}
]);
tray.setToolTip('Electron App');
tray.setContextMenu(contextMenu);

// const loginBtn = document.getElementById('loginBtn');

// loginBtn.addEventListener('click', () => {
// console.log('Button clicked');
// });

// const loginBtn = document.querySelector('loginBtn').addEventListener(
// 'click', () => {
// console.log('Button clicked');
// }
// );
});

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
//app.on('ready', createWindow);


// Quit when all windows are closed.
app.on('window-all-closed', () => {
// 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();
// }
});

app.on('activate', () => {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});

// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and import them here.
ipcMain.on('btnclick', function(event,arg) {
console.log(arg.username);
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"productName": "electron-desktop-app",
"version": "1.0.0",
"description": "My Electron application description",
"main": "src/index.js",
"main": "main.js",
"scripts": {
"start": "electron-forge start",
"package": "electron-forge package",
Expand Down
4 changes: 2 additions & 2 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
<form action="">
<div class="field-group">
<div class="field">
<input type="text" name="username" required="required" placeholder="Usuário">
<input id="usernameField" type="text" name="username" required="required" placeholder="Usuário">
</div>
<div class="field">
<input type="password" name="password" required="required" placeholder="Senha">
<input id="passwordField" type="password" name="password" required="required" placeholder="Senha">
</div>
<div class="field">
<a href="#"><strong>Criar nova conta</strong></a>
Expand Down
163 changes: 34 additions & 129 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,133 +1,38 @@
const { app, BrowserWindow, Tray, Menu } = require('electron');
const { resolve } = require('path');
const { BrowserView } = require('electron').remote;
const { ipcRenderer, remote, BrowserWindow } = require('electron');

// Handle creating/removing shortcuts on Windows when installing/uninstalling.
if (require('electron-squirrel-startup')) { // eslint-disable-line global-require
app.quit();
}

const createWindow = () => {
// Create the browser window.
const mainWindow = new BrowserWindow({
width: 340,
resizable: false,
height: 500,
maximizable: false,
frame: false,
enableLargerThanScreen: false,
opacity: 0.90,
titleBarStyle: "hidden",
webPreferences: {
nodeIntegration: true
},
});

// and load the index.html of the app.
mainWindow.loadFile('src/index.html');

// Open the DevTools.
// mainWindow.webContents.openDevTools();

// var menu = Menu.buildFromTemplate([
// {
// label: 'Menu',
// submenu: [
// {
// label: 'Hello',
// click() {
// console.log('World');
// }
// },
// {
// label: 'Hide from everybody',
// click() {
// app.hide(createWindow);
// }
// },
// {
// label: 'Tray On/Off',
// click() {
// tray.hide();
// }
// },
// {
// label: 'Exit',
// click(){
// app.quit;
// }
// }
// ]
// }
// ])
const loginBtn = document.getElementById('loginBtn');

Menu.setApplicationMenu(menu);
let userNotification = {
title: String,
body: 'Your login was made successfully',
};

app.whenReady().then(createWindow);

// app.dock.hide();

let tray = null;

app.on('ready', () => {
tray = new Tray('public/assets/logo_16x16.png');
const contextMenu = Menu.buildFromTemplate([
{
label: 'Opacidade Settings',
submenu: [
{
label: 'Opacidade +',
},
{
label: 'Opacidade -' ,
}
]
},
{
label: 'Sair',
click (){
createWindow.call(createWindow);
}
}
]);
tray.setToolTip('Electron App');
tray.setContextMenu(contextMenu);

// const loginBtn = document.getElementById('loginBtn');

// loginBtn.addEventListener('click', () => {
// console.log('Button clicked');
// });

// const loginBtn = document.querySelector('loginBtn').addEventListener(
// 'click', () => {
// console.log('Button clicked');
// }
// );
});

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
//app.on('ready', createWindow);


// Quit when all windows are closed.
app.on('window-all-closed', () => {
// 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();
// }
});

app.on('activate', () => {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
// Handle creating/removing shortcuts on Windows when installing/uninstalling.
// loginBtn.addEventListener('click', () => {
// console.log('Button clicked');
// });

loginBtn.addEventListener(
'click', () => {
let userLogin = {
username: document.getElementById('usernameField').value,
password: document.getElementById('passwordField').value,
};
const myNotification = new window.Notification(
userNotification.title = `Olá ${userLogin.username}`,
userNotification,
);
// console.log(userLogin);
// let window = remote.getCurrentWindow();
// window.close();
ipcRenderer.send("btnclick", userLogin);

let win = remote.getCurrentWindow();
win.hide();
}
});

// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and import them here.
);
// document.querySelector('loginBtn').addEventListener(
// 'click', () => {
// console.log('Button clicked');
// }
// );

0 comments on commit b7bd2bf

Please sign in to comment.