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

Update ai highlighter on tab in and not service init #5265

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all 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: 14 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,19 @@ 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() {
if (!HighlighterService.aiHighlighterUpdater) return false;
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
Loading