Skip to content

Commit

Permalink
fix: login issue
Browse files Browse the repository at this point in the history
  • Loading branch information
dice2o committed Apr 8, 2023
1 parent 31bbc9b commit 00ef912
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 136 deletions.
4 changes: 2 additions & 2 deletions forge.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module.exports = {
productName: 'BingGPT',
description: 'AI-powered copilot',
productDescription: 'AI-powered copilot',
version: '0.3.2',
version: '0.3.3',
categories: ['Utility'],
maintainer: 'dice2o',
homepage: 'https://github.com/dice2o/BingGPT',
Expand All @@ -56,7 +56,7 @@ module.exports = {
productName: 'BingGPT',
description: 'AI-powered copilot',
productDescription: 'AI-powered copilot',
version: '0.3.2',
version: '0.3.3',
categories: ['Utility'],
maintainer: 'dice2o',
homepage: 'https://github.com/dice2o/BingGPT',
Expand Down
19 changes: 12 additions & 7 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ const createWindow = () => {
},
},
{
label: 'BingGPT v0.3.2',
label: 'BingGPT v0.3.3',
visible: parameters.selectionText.trim().length === 0,
click: () => {
shell.openExternal('https://github.com/dice2o/BingGPT/releases')
Expand All @@ -239,13 +239,20 @@ const createWindow = () => {
shell.openExternal(url)
return { action: 'deny' }
})
// Check if user is logged in successfully
// Login
mainWindow.webContents.on('will-redirect', (event, url) => {
if (
url.indexOf('https://edgeservices.bing.com/edgesvc/urlredirect') !== -1
) {
event.preventDefault()
mainWindow.loadURL(bingUrl)
// Get cookies
mainWindow
.loadURL(bingUrl.replace('edgediscover/query', 'edgesvc/shell'))
.then(() => {
setTimeout(() => {
mainWindow.loadURL(bingUrl)
}, 3000)
})
}
})
// Modify Content Security Policy
Expand All @@ -269,10 +276,8 @@ const createWindow = () => {
// Modify headers
mainWindow.webContents.session.webRequest.onBeforeSendHeaders(
(details, callback) => {
details.requestHeaders['user-agent'] = userAgent
if (details.url !== bingUrl) {
details.requestHeaders['x-forwarded-for'] = '1.1.1.1'
}
details.requestHeaders['User-Agent'] = userAgent
details.requestHeaders['X-Forwarded-For'] = '1.1.1.1'
callback({ requestHeaders: details.requestHeaders, cancel: false })
}
)
Expand Down
Loading

0 comments on commit 00ef912

Please sign in to comment.