diff --git a/electron/main.js b/electron/main.js index ce48caa..cde8cc2 100644 --- a/electron/main.js +++ b/electron/main.js @@ -1,5 +1,7 @@ -const { app, BrowserWindow } = require('electron'); +const { app, BrowserWindow, ipcMain } = require('electron'); +const electronPrompt = require('electron-prompt'); const { spawn } = require('child_process'); +const fs = require('fs'); const path = require('node:path'); // remember main window @@ -8,6 +10,19 @@ var mainWindow = null; // remember child process for exe so we can kill it when app exits var exeChildProcess = null; +// add support for showing a prompt window via ipc +ipcMain.handle('prompt', async(event, message) => { + return await electronPrompt({ + title: message, + label: '', + value: '', + type: 'input', + inputAttrs: { + type: 'text', + }, + }); +}); + function log(message) { // make sure main window exists @@ -44,7 +59,12 @@ app.whenReady().then(async () => { await mainWindow.loadFile(path.join(__dirname, 'loading.html')); // find path to python/cxfreeze reticulum webchat executable - const exe = path.join(__dirname, 'build/exe/ReticulumWebChat'); + var exe = path.join(__dirname, 'build/exe/ReticulumWebChat'); + + // if dist exe doesn't exist, check local build + if(!fs.existsSync(exe)){ + exe = path.join(__dirname, '..', 'build/exe/ReticulumWebChat'); + } try { diff --git a/electron/preload.js b/electron/preload.js index 23bd972..798e04b 100644 --- a/electron/preload.js +++ b/electron/preload.js @@ -1,4 +1,11 @@ -const { ipcRenderer } = require('electron'); +const { ipcRenderer, contextBridge } = require('electron'); // forward logs received from exe to web console ipcRenderer.on('log', (event, message) => console.log(message)); + +// add support for using "prompt" in electron browser window +contextBridge.exposeInMainWorld('electron', { + prompt: async function(message) { + return await ipcRenderer.invoke('prompt', message); + }, +}); diff --git a/package-lock.json b/package-lock.json index daabe0a..8488ef8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,9 @@ "name": "reticulum-webchat", "version": "1.0.0", "license": "MIT", + "dependencies": { + "electron-prompt": "^1.7.0" + }, "devDependencies": { "electron": "^30.0.8", "electron-builder": "^24.6.3" @@ -1584,6 +1587,11 @@ "node": ">= 10.0.0" } }, + "node_modules/electron-prompt": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/electron-prompt/-/electron-prompt-1.7.0.tgz", + "integrity": "sha512-IfqJYEgcRO6NuyPROo8AtdkAiZ6N9I1lQEf4dJAkPuhV5YgOHdmLqZJf6OXumZJfzrjpzCM5jHeYOrhGdgbnEA==" + }, "node_modules/electron-publish": { "version": "24.5.0", "resolved": "https://registry.npmjs.org/electron-publish/-/electron-publish-24.5.0.tgz", diff --git a/package.json b/package.json index 30c17c7..c222a08 100644 --- a/package.json +++ b/package.json @@ -60,5 +60,8 @@ "oneClick": false, "allowToChangeInstallationDirectory": true } + }, + "dependencies": { + "electron-prompt": "^1.7.0" } } diff --git a/public/index.html b/public/index.html index a0b6a9f..c23114d 100644 --- a/public/index.html +++ b/public/index.html @@ -45,16 +45,26 @@ - -
-
+ +
-
Announce
-
-
+ + Announce + + @@ -967,6 +977,34 @@ "display_name": this.displayName, }); }, + async startNewLXMFConversation() { + + // ask for destination address + const destinationHash = await this.prompt("Enter LXMF Address"); + if(!destinationHash){ + return; + } + + // attempt to find existing peer so we can show their name + const existingPeer = this.peers[destinationHash]; + if(existingPeer){ + this.onPeerClick(existingPeer); + return; + } + + // simple attempt to prevent garbage input + if(destinationHash.length !== 32){ + alert("Invalid Address"); + return; + } + + // we didn't find an existing peer, so just use an unknown name + this.onPeerClick({ + name: "Unknown Peer", + destination_hash: destinationHash, + }); + + }, downloadNomadNetFile(destinationHash, filePath, onSuccessCallback, onFailureCallback, onProgressCallback) { // do nothing if not connected to websocket @@ -1659,6 +1697,15 @@ } }, + async prompt(message) { + if(window.electron){ + // running inside electron, use ipc prompt + return await window.electron.prompt(message); + } else { + // running inside normal browser, use browser prompt + return window.prompt(message); + } + }, }, computed: { isMobile() {