mirror of
https://github.com/tiddly-gittly/TidGi-Desktop.git
synced 2025-12-15 15:10:31 -08:00
fix: preference window authing login
This commit is contained in:
parent
f619f83313
commit
acbffebb49
4 changed files with 33 additions and 30 deletions
|
|
@ -1,35 +1,8 @@
|
|||
const { contextBridge, remote } = require('electron');
|
||||
const { contextBridge } = require('electron');
|
||||
|
||||
require('./common/i18n');
|
||||
require('./common/require-nodejs');
|
||||
require('./common/simple-context-menu');
|
||||
require('./common/authing-postmessage');
|
||||
|
||||
contextBridge.exposeInMainWorld('meta', { mode: 'add-workspace' });
|
||||
|
||||
// on production build, if we try to redirect to http://localhost:3000 , we will reach chrome-error://chromewebdata/ , but we can easily get back
|
||||
// this happens when we are redirected by OAuth login
|
||||
const { CHROME_ERROR_PATH, REACT_PATH } = require('../constants/paths');
|
||||
|
||||
const CHECK_LOADED_INTERVAL = 500;
|
||||
function refresh() {
|
||||
if (window.location.href === CHROME_ERROR_PATH) {
|
||||
remote.getCurrentWindow().loadURL(REACT_PATH);
|
||||
} else {
|
||||
setTimeout(refresh, CHECK_LOADED_INTERVAL);
|
||||
}
|
||||
}
|
||||
setTimeout(refresh, CHECK_LOADED_INTERVAL);
|
||||
|
||||
// Only passing message that Authing needs to the window https://github.com/Authing/Guard/blob/db9df517c00a5eb51e406377ee4d7bb097054b68/src/views/login/SocialButtonsList.vue#L82-L89
|
||||
// https://stackoverflow.com/questions/55544936/communication-between-preload-and-client-given-context-isolation-in-electron
|
||||
window.addEventListener(
|
||||
'message',
|
||||
event => {
|
||||
if (typeof event?.data?.code === 'number' && event?.data?.data?.token && event?.data.from !== 'preload') {
|
||||
// This message will be catch by this handler again, so we add a 'from' to indicate that it is re-send by ourself
|
||||
// we re-send this, so authing in this window can catch it
|
||||
window.postMessage({ ...event.data, from: 'preload' }, '*');
|
||||
}
|
||||
},
|
||||
false,
|
||||
);
|
||||
|
|
|
|||
29
public/preload/common/authing-postmessage.js
Normal file
29
public/preload/common/authing-postmessage.js
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
const { remote } = require('electron');
|
||||
|
||||
// on production build, if we try to redirect to http://localhost:3000 , we will reach chrome-error://chromewebdata/ , but we can easily get back
|
||||
// this happens when we are redirected by OAuth login
|
||||
const { CHROME_ERROR_PATH, REACT_PATH } = require('../../constants/paths');
|
||||
|
||||
const CHECK_LOADED_INTERVAL = 500;
|
||||
function refresh() {
|
||||
if (window.location.href === CHROME_ERROR_PATH) {
|
||||
remote.getCurrentWindow().loadURL(REACT_PATH);
|
||||
} else {
|
||||
setTimeout(refresh, CHECK_LOADED_INTERVAL);
|
||||
}
|
||||
}
|
||||
setTimeout(refresh, CHECK_LOADED_INTERVAL);
|
||||
|
||||
// Only passing message that Authing needs to the window https://github.com/Authing/Guard/blob/db9df517c00a5eb51e406377ee4d7bb097054b68/src/views/login/SocialButtonsList.vue#L82-L89
|
||||
// https://stackoverflow.com/questions/55544936/communication-between-preload-and-client-given-context-isolation-in-electron
|
||||
window.addEventListener(
|
||||
'message',
|
||||
event => {
|
||||
if (typeof event?.data?.code === 'number' && event?.data?.data?.token && event?.data.from !== 'preload') {
|
||||
// This message will be catch by this handler again, so we add a 'from' to indicate that it is re-send by ourself
|
||||
// we re-send this, so authing in this window can catch it
|
||||
window.postMessage({ ...event.data, from: 'preload' }, '*');
|
||||
}
|
||||
},
|
||||
false,
|
||||
);
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
require('./common/simple-context-menu');
|
||||
require('./common/require-nodejs');
|
||||
require('./common/i18n');
|
||||
require('./common/authing-postmessage');
|
||||
const { contextBridge } = require('electron');
|
||||
|
||||
contextBridge.exposeInMainWorld('meta', { mode: 'preferences' });
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ class GitHubLogin extends Component<Props, State> {
|
|||
<SyncToGithubButton
|
||||
onClick={async () => {
|
||||
const { code, message } = await this.auth.logout();
|
||||
window.remote.clearStorageData();
|
||||
// window.remote.clearStorageData();
|
||||
if (code === 200) {
|
||||
this.setState({ isLogin: false });
|
||||
this.updateLoginState();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue