Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

로그아웃된 경우 자동으로 다시 로그인 #26

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@
"matches": ["https://infra.yonsei.ac.kr/sso/PmSSOService*"],
"js": ["js/content-scripts/infra-login-page.js"]
},

{
"matches": [
"https://ys.learnus.org/",
"https://ys.learnus.org/index.php*",
"https://ys.learnus.org/login.php*"
],
"js": ["js/content-scripts/learnus-login-entry-page.js"]
},
{
"matches": ["https://portal.yonsei.ac.kr/ui/index.html*"],
"js": ["js/content-scripts/portal-login-entry-page.js"]
},

{
"matches": ["https://*.learnus.org/*"],
"js": ["js/content-scripts/learnus-all-pages.js", "js/vendor.js"]
Expand All @@ -32,6 +46,7 @@
"matches": ["https://*.yonsei.ac.kr/*"],
"js": ["js/content-scripts/yonsei-all-pages.js", "js/vendor.js"]
},

{
"matches": [
"https://ys.learnus.org/",
Expand Down
13 changes: 11 additions & 2 deletions src/core/login/refresh-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,24 @@ import loginPortal from './login-portal'
import {
saveLastSessionRefreshedTime,
saveIsSessionRefreshing,
removeLastSessionRefreshedTime,
} from './login-status'
import updateLearnUsSesskey from './update-learnus-sesskey'

let isRefreshing = false

export async function refreshSession(): Promise<void> {
if (isRefreshing) return
export async function refreshSession(options?: {
isSignedOut?: boolean
}): Promise<void> {
const { isSignedOut = false } = options ?? {}

if (isRefreshing) return
isRefreshing = true

if (isSignedOut) {
await removeLastSessionRefreshedTime()
}

await saveIsSessionRefreshing(true)

const loginData = await loadLoginData()
Expand Down
4 changes: 4 additions & 0 deletions src/core/login/setup-refreshing-overlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export function setupRefreshingOverlay({ checkIsInLoginPage }: Options) {
}

function showRefreshingOverlay() {
if (document.getElementById('refreshing-overlay')) {
return
}

const element = renderToStaticMarkup(
<RefreshingOverlay id="refreshing-overlay" />
)
Expand Down
7 changes: 5 additions & 2 deletions src/entry/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from '../core/login/login-status'
import { startListeningNetworkStatus } from '../core/network-status'
import { refreshSession } from '../core/login/refresh-session'
import { sendMessageToTabs } from '../utils/tab-message'
import { sendMessageToTabs, TabMessage } from '../utils/tab-message'
import { migrateLocalStorageKey } from '../utils/migrate-storage-key'

chrome.runtime.onInstalled.addListener(async (details) => {
Expand Down Expand Up @@ -66,10 +66,13 @@ chrome.storage.onChanged.addListener(async () => {
})
})

chrome.runtime.onMessage.addListener(async (message) => {
chrome.runtime.onMessage.addListener(async (message: TabMessage) => {
switch (message.type) {
case 'recreate-refresh-session-alarm':
await recreateRefreshSessionAlarm()
break
case 'on-signed-out':
await refreshSession({ isSignedOut: true })
break
}
})
6 changes: 6 additions & 0 deletions src/entry/content-scripts/learnus-login-entry-page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { sendMessageToBackground } from '../../utils/tab-message'

const loginEntryButton = document.querySelector('a.btn.btn-sso')
if (loginEntryButton) {
sendMessageToBackground({ type: 'on-signed-out' })
}
6 changes: 6 additions & 0 deletions src/entry/content-scripts/portal-login-entry-page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { sendMessageToBackground } from '../../utils/tab-message'

const loginEntryButton = document.querySelector('div.login_btn')
if (loginEntryButton) {
sendMessageToBackground({ type: 'on-signed-out' })
}
5 changes: 5 additions & 0 deletions src/utils/tab-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export type TabMessage =
| ShowRefreshingOverlayMessage
| UpdateLearnUsSesskeyMessage
| RecreateRefreshSessionAlarmMessage
| OnSignedOutMessage

interface ShowRefreshingOverlayMessage {
type: 'refreshing-overlay'
Expand All @@ -17,6 +18,10 @@ interface RecreateRefreshSessionAlarmMessage {
type: 'recreate-refresh-session-alarm'
}

interface OnSignedOutMessage {
type: 'on-signed-out'
}

export async function sendMessageToTab(tabId: number, message: TabMessage) {
try {
await chrome.tabs.sendMessage<TabMessage>(tabId, message)
Expand Down
12 changes: 12 additions & 0 deletions webpack/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ module.exports = {
'content-scripts',
'learnus-main-page.ts'
),
'content-scripts/portal-login-entry-page': path.join(
srcDir,
'entry',
'content-scripts',
'portal-login-entry-page.ts'
),
'content-scripts/learnus-login-entry-page': path.join(
srcDir,
'entry',
'content-scripts',
'learnus-login-entry-page.ts'
),
},
output: {
path: path.join(__dirname, '../dist/js'),
Expand Down
Loading