Skip to content

Commit

Permalink
Update ai highlighter on tab in and not service init
Browse files Browse the repository at this point in the history
  • Loading branch information
gettinToasty committed Dec 16, 2024
1 parent dce1383 commit 055f91a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
14 changes: 13 additions & 1 deletion app/components-react/pages/Highlighter.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import SettingsView from 'components-react/highlighter/SettingsView';
import { useVuex } from 'components-react/hooks';
import React, { useState } from 'react';
import React, { useEffect, useState } from 'react';
import { EHighlighterView, IViewState } from 'services/highlighter';
import { Services } from 'components-react/service-provider';
import StreamView from 'components-react/highlighter/StreamView';
Expand Down Expand Up @@ -32,6 +32,18 @@ export default function Highlighter(props: { params?: { view: string } }) {
initialViewState = { view: EHighlighterView.SETTINGS };
}

useEffect(() => {
// check if ai highlighter is activated and we need to update it
async function shouldUpdate() {
const versionAvailable = await HighlighterService.aiHighlighterUpdater.isNewVersionAvailable();
return versionAvailable && aiHighlighterEnabled && v.useAiHighlighter;
}

shouldUpdate().then(shouldUpdate => {
if (shouldUpdate) HighlighterService.actions.startUpdater();
});
}, []);

const [viewState, setViewState] = useState<IViewState>(initialViewState);
const updaterModal = (
<UpdateModal
Expand Down
11 changes: 1 addition & 10 deletions app/services/highlighter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -719,15 +719,6 @@ export class HighlighterService extends PersistentStatefulService<IHighlighterSt
if (this.aiHighlighterEnabled && !this.aiHighlighterUpdater) {
this.aiHighlighterUpdater = new AiHighlighterUpdater();
}

// check if ai highlighter is activated and we need to update it
if (
this.aiHighlighterEnabled &&
this.views.useAiHighlighter &&
(await this.aiHighlighterUpdater.isNewVersionAvailable())
) {
await this.startUpdater();
}
});

//
Expand Down Expand Up @@ -2286,7 +2277,7 @@ export class HighlighterService extends PersistentStatefulService<IHighlighterSt
/**
* Start updater process
*/
private async startUpdater() {
async startUpdater() {
try {
this.SET_UPDATER_STATE(true);
this.SET_HIGHLIGHTER_VERSION(this.aiHighlighterUpdater.version || '');
Expand Down

0 comments on commit 055f91a

Please sign in to comment.