Skip to content

Commit

Permalink
update login issue
Browse files Browse the repository at this point in the history
  • Loading branch information
lony2003 committed Jan 18, 2024
1 parent 6d6a56c commit 6e666d7
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 26 deletions.
48 changes: 27 additions & 21 deletions electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,15 +271,15 @@ function createWindow() {
return {action: 'deny'}
})
// Login
mainWindow.webContents.on('will-redirect', (event, url) => {
if (
url.indexOf('https://bing.com') !== -1
) {
event.preventDefault()
// Get cookies
mainWindow.loadURL(urlUtil.format(bingUrl + "?login=1"))
}
})
// mainWindow.webContents.on('will-redirect', (event, url) => {
// if (
// url.indexOf('https://bing.com') !== -1
// ) {
// event.preventDefault()
// // Get cookies
// mainWindow.loadURL("https://login.live.com/login.srf?wa=wsignin1.0&rpsnv=11&ct=1705494251&rver=6.0.5286.0&wp=MBI_SSL&wreply=https:%2F%2fwww.bing.com%2Fsecure%2FPassport.aspx%3Fpopup%3D1%26ssl%3D1&lc=1033&id=264960&checkda=1")
// }
// })
// Modify Content Security Policy
mainWindow.webContents.session.webRequest.onHeadersReceived(
(details, callback) => {
Expand Down Expand Up @@ -386,18 +386,18 @@ function createWindow() {
}
})
// Replace compose page or reload window
mainWindow.webContents.on('dom-ready', () => {
const url = mainWindow.webContents.getURL()
if (url === bingUrl) {
mainWindow.webContents.send('replace-compose-page', isDarkMode)
}

if (url.indexOf('https://www.bing.com') !== -1) {
setTimeout(()=>{
mainWindow.webContents.loadURL(urlUtil.format(bingUrl + "?login=1"));
}, 3000);
}
})
// mainWindow.webContents.on('dom-ready', () => {
// const url = mainWindow.webContents.getURL()
// if (url === bingUrl) {
// mainWindow.webContents.send('replace-compose-page', isDarkMode)
// }
//
// // if (url.indexOf('https://www.bing.com/') !== -1) {
// // setTimeout(()=>{
// // mainWindow.webContents.loadURL(urlUtil.format(bingUrl + "?login=1"));
// // }, 3000);
// // }
// })
}

app.whenReady().then(() => {
Expand Down Expand Up @@ -479,6 +479,12 @@ app.whenReady().then(() => {
}schemeovr=1&FORM=SHORUN&udscs=1&udsnav=1&setlang=${locale}&features=udssydinternal&clientscopes=noheader,coauthor,chat,channelstable,&udsframed=1`

})

//getWrapperUrl
ipcMain.on("get-wrapper-url", (event) => {
event.returnValue = getWrapperUrl();
})

createWindow()
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) createWindow()
Expand Down
44 changes: 44 additions & 0 deletions electron/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function withPrototype(obj) {
return obj
}


window.addEventListener('DOMContentLoaded', () => {
// Change page title
document.title = 'BingGPT'
Expand Down Expand Up @@ -65,6 +66,44 @@ window.addEventListener('DOMContentLoaded', () => {
if (previewOptions) {
previewOptions.style.cssText = 'bottom: 1px'
}*/

if (window.location.href.indexOf('https://www.bing.com/') !== -1) {

let informationDiv = document.createElement("div");
informationDiv.style.cssText="width: 100vw; height: 100vh; position: absolute; background: #000000; " +
"z-index: 99999; top: 0; left: 0; display:flex;\n" +
" align-items:center;\n" +
" justify-content:center;";

informationDiv.innerHTML='<p ' +
'style="color: white; text-align: center; width: 100%; display: inline-block; font-weight: bold; font-size: large; vertical-align: middle">' +
'Getting Cookies......Please wait for 10 or 20s</p>';

document.body.appendChild(informationDiv);

let count = 0;
let cookieLength = 0;

setInterval(() => {

let cookieLengthNew = document.cookie.length;

if (cookieLength == 0 || cookieLength != cookieLengthNew) {
cookieLength = cookieLengthNew;
count = 0;
} else {
count++;
}

console.log(cookieLength);

// if (count > 6) {
// let urlWrapper = ipcRenderer.sendSync("get-wrapper-url") + "?login=1"
// window.location.replace(urlWrapper);
// }
}, 1500)
}

})

// New topic
Expand Down Expand Up @@ -393,4 +432,9 @@ window.ipcRenderer = {
const resp = ipcRenderer.sendSync("get-chat-url", "compose")
return resp
},

getWrapperUrl() {
const resp = ipcRenderer.sendSync("get-wrapper-url")
return resp
},
}
2 changes: 1 addition & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let login = location.search.indexOf("login") >= 0
if (login) {
router.push("/main")
} else if (localStorage.getItem("nosplash") == "true") {
window.location.replace("https://www.bing.com/fd/auth/signin?action=interactive&provider=windows_live_id&return_url=https%3A%2F%2Fbing.com")
window.location.replace("https://www.bing.com/fd/auth/signin?action=interactive&provider=windows_live_id&return_url=https:%2F%2fwww.bing.com%2F")
} else {
router.push("/splash")
}
Expand Down
6 changes: 3 additions & 3 deletions src/pages/Main.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<script setup>
import {ref} from "vue";
const urlWrapper = "https://www.bing.com/fd/auth/signin?action=interactive&provider=windows_live_id&return_url=";
let chatUrl = urlWrapper + encodeURIComponent(window.ipcRenderer.getChatUrl())
let composeUrl = urlWrapper + encodeURIComponent(window.ipcRenderer.getComposeUrl())
// const urlWrapper = "https://www.bing.com/fd/auth/signin?action=interactive&provider=windows_live_id&return_url=";
let chatUrl = window.ipcRenderer.getChatUrl()
let composeUrl = window.ipcRenderer.getComposeUrl()
let tab = ref("0")
</script>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Splash.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ watch(nosplash, async (newSplash, oldSplash) => {
<p class="splash_primary">BingGPT</p>
<p class="splash_secondary">Powered By Copilot with Bing Chat</p>
<p class="splash_check"><input type="checkbox" v-model="nosplash">don't show this again</p>
<a style='display: block; margin-top: 10px; font-size: 25px; text-align: center;' href='https://www.bing.com/fd/auth/signin?action=interactive&provider=windows_live_id&return_url=https%3A%2F%2Fbing.com'><Microsoft></Microsoft></a>
<a style='display: block; margin-top: 10px; font-size: 25px; text-align: center;' href='https://www.bing.com/fd/auth/signin?action=interactive&provider=windows_live_id&return_url=https:%2F%2fwww.bing.com%2F'><Microsoft></Microsoft></a>
</div>
</template>

Expand Down

0 comments on commit 6e666d7

Please sign in to comment.