Skip to content

Commit

Permalink
add what i have
Browse files Browse the repository at this point in the history
  • Loading branch information
swyxio committed Aug 7, 2023
1 parent 112a33b commit b9ef3ac
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 33 deletions.
18 changes: 15 additions & 3 deletions index.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ body {

.page {
--superprompt-height: 100px;
--titlebar-height: 20px;

background: #eeeeee;
/* overflow: auto; */
/* disabled because its quite buggy */
/* resize: both; */
width: 100%;
height: calc(100vh - var(--superprompt-height));
height: calc(100vh - var(--superprompt-height) - var(--titlebar-height));
margin-top: 4px;
margin: 0 auto;
position: relative;
Expand Down Expand Up @@ -97,13 +98,24 @@ body {
stroke: rgba(255, 255, 255, 0.8);
}

#webviewContainer {
border-top-left-radius: 8px;
border-top-right-radius: 8px;
display: flex;
}

.titlebar {
display: flex;
justify-content: space-around;
}

webview {
/* overflow: hidden; */
position: absolute;
top: 0;
top: 20px;
left: 0;
width: 100%;
height: calc(100vh - var(--superprompt-height));
height: calc(100vh - var(--superprompt-height) - var(--titlebar-height));
display: inline-flex !important;
}

Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</head>

<body class="">
<div id="webviewContainer" class="flex split">
<div id="webviewContainer" class="split">
<!-- Panes Go Here -->
</div>
<form id="form" class="">
Expand Down
20 changes: 10 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ const providers = {
Together: require('./providers/together'),
Perplexity: require('./providers/perplexity'),
Phind: require('./providers/phind'),
PerplexityLlama: require('./providers/perplexity-llama.js'),
HuggingChat: require('./providers/huggingchat'),
OobaBooga: require('./providers/oobabooga'),
Smol: require('./providers/smol'),
PerplexityLlama: require('./providers/perplexity-llama.js'),
};

// Getting all the providers in an array
Expand Down Expand Up @@ -87,7 +87,7 @@ app.on('ready', () => {
enableWebView: true, // from chatgpt
// nativeWindowOpen: true,
},
width: 1200,
width,
height: 750,
},
tray,
Expand Down Expand Up @@ -169,9 +169,9 @@ app.on('ready', () => {
});
}

settingsWindow.once('ready-to-show', () => {
mb.hideWindow();
});
// settingsWindow.once('ready-to-show', () => {
// mb.hideWindow();
// });
},
},
];
Expand Down Expand Up @@ -288,15 +288,15 @@ app.on('ready', () => {
const menu = new Menu();

function quickOpen() {
if (window.isVisible()) {
mb.hideWindow();
} else {
// if (window.isVisible()) {
// mb.hideWindow();
// } else {
mb.showWindow();
if (process.platform == 'darwin') {
mb.app.show();
}
mb.app.focus();
}
// }
mb.app.focus();
}

globalShortcut.register(
Expand Down
2 changes: 1 addition & 1 deletion interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ const providers = {
Together: require('./providers/together'),
Perplexity: require('./providers/perplexity'),
Phind: require('./providers/phind'),
PerplexityLlama: require('./providers/perplexity-llama.js'),
HuggingChat: require('./providers/huggingchat'),
OobaBooga: require('./providers/oobabooga'),
Smol: require('./providers/smol'),
PerplexityLlama: require('./providers/perplexity-llama.js'),
};

const { drawPanes, updateSplitSizes } = require('./src/panes');
Expand Down
2 changes: 1 addition & 1 deletion providers/huggingchat.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class HuggingChat extends Provider {
}

static isEnabled() {
return store.get(`${this.webviewId}Enabled`, true);
return store.get(`${this.webviewId}Enabled`, false);
}
}

Expand Down
12 changes: 4 additions & 8 deletions providers/phind.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,11 @@ class Phind extends Provider {
inputElement = document.querySelector('textarea[placeholder*="Send message"]');
}
function simulateUserInput(element, text) {
var nativeTextAreaValueSetter = Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype, "value").set;
var event = new Event('input', { bubbles: true});
var nativeTextAreaValueSetter = Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype, "value").set;
var event = new Event('input', { bubbles: true});
nativeTextAreaValueSetter.call(inputElement, text);
inputElement.dispatchEvent(event);
}
simulateUserInput(inputElement, "${input}");
nativeTextAreaValueSetter.call(inputElement, "${input}");
inputElement.dispatchEvent(event);
`);
}

Expand Down
33 changes: 24 additions & 9 deletions providers/smol.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,32 @@ class SmolTalk extends Provider {

static handleInput(input) {
this.getWebview().executeJavaScript(`
function simulateUserInput(element, text) {
const inputEvent = new Event('input', { bubbles: true });
element.focus();
element.value = text;
element.dispatchEvent(inputEvent);
}
var inputElement = document.querySelector('#smol-inputbox')
simulateUserInput(inputElement, "${input}");
var inputElement = document.querySelector('#smol-inputbox')
function simulateUserInput(element, text) {
var nativeTextAreaValueSetter = Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype, "value").set;
var event = new Event('input', { bubbles: true});
nativeTextAreaValueSetter.call(inputElement, text);
inputElement.dispatchEvent(event);
}
simulateUserInput(inputElement, "${input}");
`);
}

static clearCookies() {
this.getWebview().executeJavaScript(`
const cookies = document.cookie.split(";");
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i];
const eqPos = cookie.indexOf("=");
const name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
}
`);
}

static handleSubmit() {
this.getWebview().executeJavaScript(`
Expand Down Expand Up @@ -72,7 +87,7 @@ class SmolTalk extends Provider {
}

static isEnabled() {
return store.get(`${this.webviewId}Enabled`, false);
return store.get(`${this.webviewId}Enabled`, true);
}
}

Expand Down
15 changes: 15 additions & 0 deletions src/panes.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,21 @@ function drawPanes(providers) {
div.className = 'page darwin';
div.id = provider.paneId();

// create a title bar
const titlebar = document.createElement('div');
titlebar.className = 'titlebar'
// add in a h1 with the provider name
const title = document.createElement('span');
title.innerHTML = provider.name;
titlebar.appendChild(title);
// add in a button to toggle dark mode
const darkModeButton = document.createElement('button');
darkModeButton.innerHTML = 'Clear Cookies';
darkModeButton.addEventListener('click', provider.clearCookies);
titlebar.appendChild(darkModeButton);

div.appendChild(titlebar);

// Create a new webview and set its id, source url, and autosize attributes
const webview = document.createElement('webview');
webview.id = provider.webviewId;
Expand Down

0 comments on commit b9ef3ac

Please sign in to comment.