test
This commit is contained in:
commit
b06352370a
23
.gitignore
vendored
Normal file
23
.gitignore
vendored
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||||
|
|
||||||
|
# dependencies
|
||||||
|
/node_modules
|
||||||
|
/.pnp
|
||||||
|
.pnp.js
|
||||||
|
|
||||||
|
# testing
|
||||||
|
/coverage
|
||||||
|
|
||||||
|
# production
|
||||||
|
/build
|
||||||
|
|
||||||
|
# misc
|
||||||
|
.DS_Store
|
||||||
|
.env.local
|
||||||
|
.env.development.local
|
||||||
|
.env.test.local
|
||||||
|
.env.production.local
|
||||||
|
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
BIN
assets/images/icon.jpg
Normal file
BIN
assets/images/icon.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 147 KiB |
91
main.js
Normal file
91
main.js
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
const { nativeImage, Menu } = require('electron')
|
||||||
|
const { app, BrowserWindow, Notification, ipcMain, Tray } = require('electron/main')
|
||||||
|
const path = require('node:path')
|
||||||
|
const socketio = require('socket.io-client')
|
||||||
|
|
||||||
|
|
||||||
|
const socket = socketio('ws://184.83.153.182:5000/')
|
||||||
|
socket.emit('join-notifications')
|
||||||
|
|
||||||
|
socket.on('connect-notifications', () => {
|
||||||
|
console.log('connected to notification stream')
|
||||||
|
showNotification('Websocket Connected', "You successfully connected to the websocket.")
|
||||||
|
})
|
||||||
|
|
||||||
|
socket.on('send-notification', (data) => {
|
||||||
|
showNotification(data.title, data.body)
|
||||||
|
})
|
||||||
|
|
||||||
|
const createWindow = () => {
|
||||||
|
if (!tray){
|
||||||
|
createTray()
|
||||||
|
}
|
||||||
|
|
||||||
|
let win = new BrowserWindow({
|
||||||
|
width: 1280,
|
||||||
|
height: 720,
|
||||||
|
autoHideMenuBar: true,
|
||||||
|
icon: path.join(__dirname, 'assets/images/icon.jpg'),
|
||||||
|
title: "Treehouse Hub",
|
||||||
|
webPreferences: {
|
||||||
|
preload: path.join(__dirname, 'preload.js'),
|
||||||
|
nodeIntegration: false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
win.loadURL('http://184.83.153.182:5000/')
|
||||||
|
win.on('closed', function () {
|
||||||
|
win = null
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
let tray = null
|
||||||
|
function createTray(){
|
||||||
|
let icon = path.join(__dirname, 'assets/images/icon.jpg')
|
||||||
|
const trayicon = nativeImage.createFromPath(icon)
|
||||||
|
tray = new Tray(trayicon.resize({width:16}))
|
||||||
|
const contextMenu = Menu.buildFromTemplate([
|
||||||
|
{
|
||||||
|
label: 'Open Window',
|
||||||
|
click: () => {
|
||||||
|
createWindow()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Quit',
|
||||||
|
click: () => {
|
||||||
|
app.quit()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
])
|
||||||
|
tray.setContextMenu(contextMenu)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function showNotification (title, message) {
|
||||||
|
const icon = path.join(__dirname, 'assets/images/icon.jpg')
|
||||||
|
new Notification({title:title, body:message, icon:icon }).show()
|
||||||
|
}
|
||||||
|
|
||||||
|
app.whenReady().then(() => {
|
||||||
|
createWindow()
|
||||||
|
app.setAppUserModelId("Treehouse Hub")
|
||||||
|
app.on('activate', () => {
|
||||||
|
if (BrowserWindow.getAllWindows().length === 0) {
|
||||||
|
createWindow()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
app.on('window-all-closed', (event) => {
|
||||||
|
if (process.platform !== 'darwin') {
|
||||||
|
event.preventDefault()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// Listen for messages from the renderer process
|
||||||
|
ipcMain.on('notification', (event, title, message) => {
|
||||||
|
console.log('notifiy')
|
||||||
|
showNotification(title, message)
|
||||||
|
});
|
||||||
1019
package-lock.json
generated
Normal file
1019
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
20
package.json
Normal file
20
package.json
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"name": "treehousehub",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "This is a hub for all my friends!",
|
||||||
|
"license": "MIT",
|
||||||
|
"author": "jadoywne",
|
||||||
|
"type": "commonjs",
|
||||||
|
"main": "main.js",
|
||||||
|
"scripts": {
|
||||||
|
"start": "electron .",
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
|
"package": "electron-forge package",
|
||||||
|
"make": "electron-forge make"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"socket.io-client": "^4.8.1",
|
||||||
|
"electron-prebuilt-compile": "36.3.0"
|
||||||
|
},
|
||||||
|
"dependencies": {}
|
||||||
|
}
|
||||||
5
preload.js
Normal file
5
preload.js
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
const { contextBridge, ipcRenderer } = require('electron/renderer')
|
||||||
|
|
||||||
|
contextBridge.exposeInMainWorld('electronAPI', {
|
||||||
|
sendNotification: (title, message) => ipcRenderer.send('notification', title, message)
|
||||||
|
})
|
||||||
Loading…
x
Reference in New Issue
Block a user