diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..6c80994 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 inulute + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/assets/css/no-topbar.css b/assets/css/no-topbar.css new file mode 100644 index 0000000..3fa58a4 --- /dev/null +++ b/assets/css/no-topbar.css @@ -0,0 +1,8 @@ +#webview { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + display: inline-flex !important; +} diff --git a/assets/css/style.css b/assets/css/style.css new file mode 100644 index 0000000..9d8bc9a --- /dev/null +++ b/assets/css/style.css @@ -0,0 +1,6 @@ +body { + margin: 0; + padding: 0; + -webkit-app-region: drag; + -webkit-user-select: none; +} \ No newline at end of file diff --git a/assets/icons/mac/favicon.icns b/assets/icons/mac/favicon.icns new file mode 100644 index 0000000..aa37542 Binary files /dev/null and b/assets/icons/mac/favicon.icns differ diff --git a/assets/icons/png/favicon.png b/assets/icons/png/favicon.png new file mode 100644 index 0000000..92a5a9d Binary files /dev/null and b/assets/icons/png/favicon.png differ diff --git a/assets/icons/png/perplexity.png b/assets/icons/png/perplexity.png new file mode 100644 index 0000000..bbbc9db Binary files /dev/null and b/assets/icons/png/perplexity.png differ diff --git a/assets/icons/win/favicon.ico b/assets/icons/win/favicon.ico new file mode 100644 index 0000000..1cc9aca Binary files /dev/null and b/assets/icons/win/favicon.ico differ diff --git a/assets/js/renderer.js b/assets/js/renderer.js new file mode 100644 index 0000000..7980d5c --- /dev/null +++ b/assets/js/renderer.js @@ -0,0 +1,45 @@ +const getControlsHeight = () => { + const controls = document.querySelector("#controls"); + if (controls) { + return controls.offsetHeight; + } + return 0; +}; + +const calculateLayoutSize = () => { + const webview = document.querySelector("webview"); + const windowWidth = document.documentElement.clientWidth; + const windowHeight = document.documentElement.clientHeight; + const controlsHeight = getControlsHeight(); + const webviewHeight = windowHeight - controlsHeight; + + webview.style.width = windowWidth + "px"; + webview.style.height = webviewHeight + "px"; +}; + +window.addEventListener("DOMContentLoaded", () => { + calculateLayoutSize(); + + // Dynamic resize function (responsive) + window.onresize = calculateLayoutSize; + + // Home button exists + if (document.querySelector("#home")) { + document.querySelector("#home").onclick = () => { + const home = document.getElementById("webview").getAttribute("data-home"); + document.querySelector("webview").src = home; + }; + } + + // Print button exits + if (document.querySelector("#print_button")) { + document + .querySelector("#print_button") + .addEventListener("click", async () => { + const url = document.querySelector("webview").getAttribute("src"); + + // Launch print window + await window.electron.print(url); + }); + } +}); diff --git a/index.html b/index.html new file mode 100644 index 0000000..1c600b3 --- /dev/null +++ b/index.html @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/main.js b/main.js new file mode 100644 index 0000000..94edf5b --- /dev/null +++ b/main.js @@ -0,0 +1,37 @@ +const { app, BrowserWindow, dialog } = require("electron"); + +app.allowRendererProcessReuse = true; + +app.on("ready", () => { + const mainWindow = new BrowserWindow(); + + // Hide the top menu bar + mainWindow.setMenu(null); + + mainWindow.loadURL(`file://${__dirname}/index.html`, { + userAgent: + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36", + }); + + const promptObject = { + type: "question", + title: "Choose an AI to navigate", + message: "Choose an AI to navigate:", + buttons: ["Perplexity AI: AI Search", "Labs Perplexity AI: AI Chat"], + }; + + dialog.showMessageBox(mainWindow, promptObject).then((response) => { + const chosenWebsite = promptObject.buttons[response.response]; + if (chosenWebsite === "Perplexity AI: AI Search") { + mainWindow.loadURL("https://perplexity.ai"); + } else if (chosenWebsite === "Labs Perplexity AI: AI Chat") { + mainWindow.loadURL("https://labs.perplexity.ai"); + } + }); + + const print = require("./src/print"); +}); + +app.on("window-all-closed", () => { + app.quit(); +}); diff --git a/package.json b/package.json new file mode 100644 index 0000000..e356b08 --- /dev/null +++ b/package.json @@ -0,0 +1,57 @@ +{ + "name": "perplexity-ai-app", + "productName": "Perplexity AI", + "version": "0.1.0", + "description": "Perplexity AI desktop application built with Electron.", + "main": "main.js", + "scripts": { + "start": "electron .", + "build": "electron-builder", + "package-mac": "electron-builder --mac", + "package-win": "electron-builder --win", + "package-linux": "electron-builder --linux" + }, + "repository": "https://github.com/inulute/perplexity-ai-app", + "author": "inulute", + "license": "MIT", + "devDependencies": { + "electron": "^22.0.0", + "electron-builder": "^24.6.3" + }, + "dependencies": { + "electron-prompt": "^1.7.0" + }, + "build": { + "appId": "com.perplexityai.app", + "productName": "Perplexity AI", + "directories": { + "output": "release-builds" + }, + "mac": { + "category": "your.app.Productivity", + "icon": "assets/icons/mac/favicon.icns" + }, + "win": { + "target": "nsis", + "icon": "assets/icons/win/favicon.ico" + }, + "linux": { + "target": "AppImage", + "icon": "assets/icons/png/favicon.png" + }, + "dmg": { + "contents": [ + { + "x": 130, + "y": 220 + }, + { + "x": 410, + "y": 220, + "type": "link", + "path": "/Applications" + } + ] + } + } +} diff --git a/preload.js b/preload.js new file mode 100644 index 0000000..fe5c54a --- /dev/null +++ b/preload.js @@ -0,0 +1,11 @@ +const { contextBridge, ipcRenderer } = require("electron"); + +contextBridge.exposeInMainWorld("electron", { + print: async (arg) => { + try { + await ipcRenderer.invoke("print", arg); + } catch (error) { + console.error("Error invoking print:", error); + } + }, +}); diff --git a/src/menu.js b/src/menu.js new file mode 100644 index 0000000..0545f29 --- /dev/null +++ b/src/menu.js @@ -0,0 +1,71 @@ +exports.createTemplate = (name) => { + let template = [ + { + label: "Edit", + submenu: [ + { role: "undo" }, + { role: "redo" }, + { type: "separator" }, + { role: "cut" }, + { role: "copy" }, + { role: "paste" }, + { role: "pasteandmatchstyle" }, + { role: "delete" }, + { role: "selectAll" }, // Changed "selectall" to "selectAll" to match Electron role names. + ], + }, + { + label: "View", + submenu: [ + { role: "reload" }, + { role: "forcereload" }, + { role: "toggledevtools" }, + { type: "separator" }, + { role: "resetzoom" }, + { role: "zoomin" }, + { role: "zoomout" }, + { type: "separator" }, + { role: "togglefullscreen" }, + ], + }, + { + role: "window", + submenu: [{ role: "minimize" }, { role: "close" }], + }, + ]; + + if (process.platform === "darwin") { + template.unshift({ + label: name, + submenu: [ + { role: "about" }, // Added "about" role for macOS app info. + { type: "separator" }, + { role: "services", submenu: [] }, + { type: "separator" }, + { role: "hide" }, + { role: "hideothers" }, + { role: "unhide" }, + { type: "separator" }, + { role: "quit" }, + ], + }); + + template[1].submenu.push( + { type: "separator" }, + { + label: "Speech", + submenu: [{ role: "startspeaking" }, { role: "stopspeaking" }], + } + ); + + template[3].submenu = [ + { role: "close" }, + { role: "minimize" }, + { role: "zoom" }, + { type: "separator" }, + { role: "front" }, + ]; + } + + return template; +}; diff --git a/src/print.js b/src/print.js new file mode 100644 index 0000000..450a045 --- /dev/null +++ b/src/print.js @@ -0,0 +1,11 @@ +const { ipcMain, BrowserWindow } = require("electron"); + +ipcMain.handle("print", async (event, arg) => { + let printWindow = new BrowserWindow({ autoHideMenuBar: true }); + + printWindow.webContents.on("did-finish-load", () => { + printWindow.webContents.print({ silent: false }); + }); + + printWindow.loadURL(arg); +}); diff --git a/src/view.js b/src/view.js new file mode 100644 index 0000000..e220ddb --- /dev/null +++ b/src/view.js @@ -0,0 +1,13 @@ +const { BrowserView } = require("electron"); + +exports.createBrowserView = (mainWindow) => { + const view = new BrowserView(); + mainWindow.setBrowserView(view); + view.setBounds({ x: 0, y: 0, width: 1024, height: 768 }); + + // Get the selected website from the dropdown menu + const selectedWebsite = mainWindow.webContents.getViewById("websiteDropdown").value; + + // Load the selected website in the browser view + view.webContents.loadURL(selectedWebsite); +}; \ No newline at end of file diff --git a/src/window.js b/src/window.js new file mode 100644 index 0000000..ea7f860 --- /dev/null +++ b/src/window.js @@ -0,0 +1,23 @@ +const path = require("path"); +const { BrowserWindow } = require("electron"); + +exports.createBrowserWindow = () => { + return new BrowserWindow({ + width: 1024, + height: 768, + minWidth: 400, + minHeight: 600, + icon: path.join(__dirname, "assets/icons/png/favicon.png"), + backgroundColor: "#fff", + autoHideMenuBar: true, + webPreferences: { + devTools: false, + contextIsolation: true, + webviewTag: true, + preload: path.join(__dirname, "../preload.js"), + nodeIntegration: false, + nativeWindowOpen: true, + webSecurity: true, + }, + }); +};