diff --git a/api.js b/api.js new file mode 100644 index 0000000..8f7f225 --- /dev/null +++ b/api.js @@ -0,0 +1,18 @@ +module.exports = class API{ + constructor() { + this.link = "http://192.168.1.78:8080/" + } + + async getBuilding(){ + return (await fetch(`${this.link}building`, { + method: "GET" + })).json() + } + + async getFloors(id){ + return (await fetch(`${this.link}building/${id}/floors`, { + method: "GET" + })).json() + } + +} \ No newline at end of file diff --git a/html/index.html b/html/index.html new file mode 100644 index 0000000..ac5ee68 --- /dev/null +++ b/html/index.html @@ -0,0 +1,15 @@ + + + + + + + + + Interface + + + + + + diff --git a/index.html b/index.html deleted file mode 100644 index 5887b2c..0000000 --- a/index.html +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - Hello World! - - -

Hello World!

- We are using Node.js , - Хромиум , - and Electron . - -
-

- Удалить приложение -

-
- - - - - diff --git a/main.js b/main.js index 7699935..4c1f288 100644 --- a/main.js +++ b/main.js @@ -1,43 +1,38 @@ // Modules to control application life and create native browser window -const { app, BrowserWindow } = require('electron') +const { app, BrowserWindow, ipcMain} = require('electron') const path = require('node:path') +const apiModule = require("./api.js") + +const API = new apiModule() +let mainWindow function createWindow () { - // Create the browser window. - const mainWindow = new BrowserWindow({ + mainWindow = new BrowserWindow({ width: 800, height: 600, webPreferences: { preload: path.join(__dirname, 'preload.js') } }) + mainWindow.loadFile(path.join(__dirname, '/html/index.html')) - // and load the index.html of the app. - mainWindow.loadFile('index.html') + mainWindow.webContents.openDevTools() +} - // Open the DevTools. - // mainWindow.webContents.openDevTools() +async function getBuildings(){ + const resp = await API.getBuilding() + return resp } -// 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.whenReady().then(() => { createWindow() + ipcMain.handle('api:getBuildings', getBuildings) app.on('activate', function () { - // On macOS 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() }) }) -// Quit when all windows are closed, except on macOS. There, it's common -// for applications and their menu bar to stay active until the user quits -// explicitly with Cmd + Q. app.on('window-all-closed', function () { if (process.platform !== 'darwin') app.quit() }) - -// 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 require them here. diff --git a/preload.js b/preload.js index f26017e..a429134 100644 --- a/preload.js +++ b/preload.js @@ -6,13 +6,20 @@ * * https://www.electronjs.org/docs/latest/tutorial/sandbox */ -window.addEventListener('DOMContentLoaded', () => { - const replaceText = (selector, text) => { - const element = document.getElementById(selector) - if (element) element.innerText = text - } +// window.addEventListener('DOMContentLoaded', () => { +// const replaceText = (selector, text) => { +// const element = document.getElementById(selector) +// if (element) element.innerText = text +// } +// +// for (const type of ['chrome', 'node', 'electron']) { +// replaceText(`${type}-version`, process.versions[type]) +// } +// }) - for (const type of ['chrome', 'node', 'electron']) { - replaceText(`${type}-version`, process.versions[type]) - } +const { contextBridge, ipcRenderer } = require('electron') + +contextBridge.exposeInMainWorld('electronAPI', { + getBuildings: () => ipcRenderer.invoke('api:getBuildings'), }) + diff --git a/renderer.js b/renderer.js index 1e70849..061ff04 100644 --- a/renderer.js +++ b/renderer.js @@ -1,7 +1,13 @@ -/** - * This file is loaded via the