-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
180 additions
and
454 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { manifest } from '@tix-factory/extension-utils'; | ||
import { getSettingValue } from '../../../services/settings'; | ||
import { getAuthenticatedUser } from '../../../services/users'; | ||
|
||
const notificationId = 'startup-notification'; | ||
|
||
const displayStartupNotification = async (): Promise<void> => { | ||
if (!manifest.icons) { | ||
console.warn('Missing manifest icons'); | ||
return; | ||
} | ||
|
||
const authenticatedUser = await getAuthenticatedUser(); | ||
chrome.notifications.create(notificationId, { | ||
type: 'basic', | ||
iconUrl: chrome.extension.getURL(manifest.icons['128']), | ||
title: 'Roblox+ Started', | ||
message: authenticatedUser | ||
? `Hello, ${authenticatedUser.displayName}` | ||
: 'You are currently signed out', | ||
contextMessage: `${manifest.name} ${manifest.version}, by WebGL3D`, | ||
}); | ||
}; | ||
|
||
getSettingValue('startupNotification') | ||
.then(async (setting) => { | ||
if (typeof setting !== 'object') { | ||
setting = { | ||
on: !chrome.extension.inIncognitoContext, | ||
visit: false, | ||
}; | ||
} | ||
|
||
if (!setting.on) { | ||
return; | ||
} | ||
|
||
if (setting.visit) { | ||
// Only show the startup notification after Roblox has been visited. | ||
const updatedListener = ( | ||
_tabId: number, | ||
_changes: chrome.tabs.TabChangeInfo, | ||
tab: chrome.tabs.Tab | ||
): Promise<void> => { | ||
return takeAction(tab); | ||
}; | ||
|
||
const takeAction = async (tab: chrome.tabs.Tab): Promise<void> => { | ||
if (!tab.url) { | ||
return; | ||
} | ||
|
||
try { | ||
const tabURL = new URL(tab.url); | ||
if (!tabURL.hostname.endsWith('.roblox.com')) { | ||
return; | ||
} | ||
|
||
chrome.tabs.onCreated.removeListener(takeAction); | ||
chrome.tabs.onUpdated.removeListener(updatedListener); | ||
await displayStartupNotification(); | ||
} catch { | ||
// don't care for now | ||
} | ||
}; | ||
|
||
chrome.tabs.onUpdated.addListener(updatedListener); | ||
chrome.tabs.onCreated.addListener(takeAction); | ||
} else { | ||
await displayStartupNotification(); | ||
} | ||
}) | ||
.catch((err) => { | ||
console.warn('Failed to render startup notification', err); | ||
}); | ||
|
||
chrome.notifications.onClicked.addListener((id) => { | ||
if (id !== notificationId) { | ||
return; | ||
} | ||
|
||
chrome.tabs.create({ | ||
url: `https://roblox.plus/about/changes?version=${manifest.version}`, | ||
active: true, | ||
}); | ||
}); |
Oops, something went wrong.