Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
inulute committed Jul 28, 2023
1 parent 2905592 commit 4b146f0
Show file tree
Hide file tree
Showing 16 changed files with 315 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
8 changes: 8 additions & 0 deletions assets/css/no-topbar.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#webview {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: inline-flex !important;
}
6 changes: 6 additions & 0 deletions assets/css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
body {
margin: 0;
padding: 0;
-webkit-app-region: drag;
-webkit-user-select: none;
}
Binary file added assets/icons/mac/favicon.icns
Binary file not shown.
Binary file added assets/icons/png/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icons/png/perplexity.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icons/win/favicon.ico
Binary file not shown.
45 changes: 45 additions & 0 deletions assets/js/renderer.js
Original file line number Diff line number Diff line change
@@ -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);
});
}
});
12 changes: 12 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="assets/css/style.css">
<link rel="stylesheet" href="assets/css/no-topbar.css">
<script defer src="assets/js/renderer.js"></script>
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; style-src 'self' 'unsafe-inline';">
</head>
<body>
<webview id="webview" autosize="on" src="https://labs.perplexity.ai/"></webview>
</body>
</html>
37 changes: 37 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -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();
});
57 changes: 57 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
}
}
11 changes: 11 additions & 0 deletions preload.js
Original file line number Diff line number Diff line change
@@ -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);
}
},
});
71 changes: 71 additions & 0 deletions src/menu.js
Original file line number Diff line number Diff line change
@@ -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;
};
11 changes: 11 additions & 0 deletions src/print.js
Original file line number Diff line number Diff line change
@@ -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);
});
13 changes: 13 additions & 0 deletions src/view.js
Original file line number Diff line number Diff line change
@@ -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);
};
23 changes: 23 additions & 0 deletions src/window.js
Original file line number Diff line number Diff line change
@@ -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,
},
});
};

0 comments on commit 4b146f0

Please sign in to comment.