feat(core): hide search locally button when battery save enabled (#13423)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Integrated a feature flag to control "battery save mode" within quick
search for documentation.

* **Behavior Changes**
  * Local search is now enabled by default for non-cloud workspaces.
* The "search locally" option is hidden when battery save mode is
active.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
EYHN
2025-08-06 13:50:05 +08:00
committed by GitHub
parent 99a7b7f676
commit 713f926247
2 changed files with 18 additions and 5 deletions
@@ -14,6 +14,7 @@ import type { WorkspaceServerService } from '../../cloud';
import type { DocRecord, DocsService } from '../../doc';
import type { DocDisplayMetaService } from '../../doc-display-meta';
import type { DocsSearchService } from '../../docs-search';
import type { FeatureFlagService } from '../../feature-flag';
import type { WorkspaceService } from '../../workspace';
import type { QuickSearchSession } from '../providers/quick-search-provider';
import type { QuickSearchItem } from '../types/item';
@@ -34,7 +35,8 @@ export class DocsQuickSearchSession
private readonly workspaceServerService: WorkspaceServerService,
private readonly docsSearchService: DocsSearchService,
private readonly docsService: DocsService,
private readonly docDisplayMetaService: DocDisplayMetaService
private readonly docDisplayMetaService: DocDisplayMetaService,
private readonly featureFlagService: FeatureFlagService
) {
super();
}
@@ -44,6 +46,9 @@ export class DocsQuickSearchSession
ServerFeature.Indexer
) ?? false;
private readonly isEnableBatterySaveMode = () =>
this.featureFlagService.flags.enable_battery_save_mode.value;
private readonly isIndexerLoading$ = this.docsSearchService.indexerState$.map(
({ completed }) => {
return !completed;
@@ -87,7 +92,7 @@ export class DocsQuickSearchSession
items$ = new LiveData<QuickSearchItem<'docs', DocsPayload>[]>([]);
searchLocally = false;
searchLocally = !this.isCloudWorkspace;
query = effect(
tap(query => {
@@ -144,7 +149,9 @@ export class DocsQuickSearchSession
return out.pipe(
tap((items: QuickSearchItem<'docs', DocsPayload>[]) => {
this.items$.next(
this.isSupportServerIndexer() && !this.searchLocally
this.isSupportServerIndexer() &&
!this.searchLocally &&
!this.isEnableBatterySaveMode()
? [...items, this.searchLocallyItem]
: items
);
@@ -153,7 +160,9 @@ export class DocsQuickSearchSession
onStart(() => {
this.error$.next(null);
this.items$.next(
this.isSupportServerIndexer() && !this.searchLocally
this.isSupportServerIndexer() &&
!this.searchLocally &&
!this.isEnableBatterySaveMode()
? [this.searchLocallyItem]
: []
);
@@ -162,7 +171,9 @@ export class DocsQuickSearchSession
catchError(err => {
this.error$.next(err instanceof Error ? err.message : err);
this.items$.next(
this.isSupportServerIndexer() && !this.searchLocally
this.isSupportServerIndexer() &&
!this.searchLocally &&
!this.isEnableBatterySaveMode()
? [this.searchLocallyItem]
: []
);
@@ -6,6 +6,7 @@ import { WorkspaceDialogService } from '../dialogs';
import { DocsService } from '../doc';
import { DocDisplayMetaService } from '../doc-display-meta';
import { DocsSearchService } from '../docs-search';
import { FeatureFlagService } from '../feature-flag';
import { GlobalContextService } from '../global-context';
import { JournalService } from '../journal';
import { TagService } from '../tag';
@@ -61,6 +62,7 @@ export function configureQuickSearchModule(framework: Framework) {
DocsSearchService,
DocsService,
DocDisplayMetaService,
FeatureFlagService,
])
.entity(LinksQuickSearchSession, [
WorkspaceService,