Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit dda9f25

Browse files
committed
fix: show the latest version @ Options
1 parent 9694ddb commit dda9f25

4 files changed

Lines changed: 31 additions & 8 deletions

File tree

src/configs/userConfig.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ export const actionConfig: ActionConfigType = {
122122
genPrompt: async (selection: string) => {
123123
const preferredLanguage = await getPreferredLanguage()
124124
return (
125-
`Translate the following into ${preferredLanguage} and only show me the translated content.` +
126-
`If it is already in ${preferredLanguage},` +
125+
`Translate the following into ${preferredLanguage} and only show me the translated content. ` +
126+
`If it is already in ${preferredLanguage}, ` +
127127
`translate it into English and only show me the translated content:\n"${selection}"`
128128
)
129129
},

src/content/index.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import '../../styles/base.css'
77
import '../../styles/styles.scss'
88
import ChatContainer from '../components/ChatContainer'
99
import FloatingToolbar from '../components/FloatingToolbar'
10-
import { SiteConfiguration, ThemeMode, updateUserConfig } from '../configs'
10+
import { getPreferredLanguage, SiteConfiguration, ThemeMode, updateUserConfig } from '../configs'
1111
import { createElementAtPosition, Session } from '../utils'
1212

1313
async function mountChatContainer(
@@ -94,17 +94,17 @@ const siteConfig = {
9494
// appendContainerQuery: ['.sidebar-secondary-items.sidebar-secondary__inner'],
9595
}
9696

97-
function getBodyContent() {
97+
async function getBodyContent() {
9898
const bodyElement = document.querySelector(siteConfig.bodyContainerQuery[0])
9999
if (bodyElement) {
100100
const maxLength = 1000 // Set the desired max length of the content
101101
const bodyContent = bodyElement.textContent || ''
102102
const trimmedContent =
103103
bodyContent.length > maxLength ? bodyContent.slice(0, maxLength) + '...' : bodyContent
104104

105+
const preferredLanguage = await getPreferredLanguage()
105106
// Append the limiting message
106-
const limitingMessage =
107-
'Summarize the conent in a few words. Please keep the discussion within the scope of this content from now on.'
107+
const limitingMessage = `Summarize the conent in a few words in ${preferredLanguage}. Please keep the discussion within the scope of this content from now on. Answer in ${preferredLanguage}.`
108108
const initialMessage = `${trimmedContent}\n\n${limitingMessage}`
109109

110110
return initialMessage
@@ -143,7 +143,7 @@ async function getSessionData() {
143143

144144
async function run() {
145145
console.debug('Mount LectureBotfor ἐντελέχεια.άι on', siteName)
146-
const initialQuestion = getBodyContent()
146+
const initialQuestion = await getBodyContent()
147147
// const session = initSession()
148148
const session = await getSessionData()
149149

src/options/App.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@ function OptionsPage(props: { theme: ThemeMode; onThemeChange: (theme: ThemeMode
2121
const [triggerMode, setTriggerMode] = useState<TriggerMode>(TriggerMode.Automatically)
2222
const [language, setLanguage] = useState<LanguageMode>(LanguageMode.Auto)
2323
const { setToast } = useToasts()
24+
const [currentVersion, setCurrentVersion] = useState('')
25+
const [latestVersion, setLatestVersion] = useState('')
26+
const [releaseUrl, setReleaseUrl] = useState('')
27+
28+
useEffect(() => {
29+
setCurrentVersion(getExtensionVersion())
30+
fetch('https://api.github.com/repos/entelecheia/entelecheia-lecture-bot/releases/latest').then(
31+
(response) =>
32+
response.json().then((data) => {
33+
setLatestVersion(data.tag_name.replace('v', ''))
34+
setReleaseUrl(data.html_url)
35+
}),
36+
)
37+
}, [])
2438

2539
useEffect(() => {
2640
getUserConfig().then((config) => {
@@ -55,6 +69,10 @@ function OptionsPage(props: { theme: ThemeMode; onThemeChange: (theme: ThemeMode
5569
[setToast],
5670
)
5771

72+
const openReleasePage = useCallback(() => {
73+
Browser.tabs.create({ url: releaseUrl })
74+
}, [releaseUrl])
75+
5876
return (
5977
<Fragment>
6078
<div className="container mx-auto">
@@ -64,6 +82,11 @@ function OptionsPage(props: { theme: ThemeMode; onThemeChange: (theme: ThemeMode
6482
<span className="font-semibold">
6583
LectureBot for ἐντελέχεια.άι(v{getExtensionVersion()})
6684
</span>
85+
<span className="cursor-pointer leading-[0]" onClick={openReleasePage}>
86+
{currentVersion === latestVersion
87+
? '🎉 Latest version 🎉'
88+
: `🚨 Latest version: v${latestVersion} 🚨`}
89+
</span>
6790
</div>
6891
</nav>
6992
<main className="w-[500px] mx-auto mt-14">

src/utils/getExtensionVersion.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Browser from 'webextension-polyfill'
22

33
export function getExtensionVersion() {
4-
return Browser.runtime.getManifest().version
4+
return Browser.runtime.getManifest().version.replace('v', '')
55
}

0 commit comments

Comments
 (0)