diff --git a/main.js b/main.js new file mode 100644 index 0000000..5aded88 --- /dev/null +++ b/main.js @@ -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); +}); diff --git a/package.json b/package.json index e0b55b7..dcd74e0 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/index.html b/src/index.html index a39ea0f..c7ccc20 100644 --- a/src/index.html +++ b/src/index.html @@ -20,10 +20,10 @@
- +
- +
Criar nova conta diff --git a/src/index.js b/src/index.js index 38693b0..65111fa 100644 --- a/src/index.js +++ b/src/index.js @@ -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'); +// } +// );