Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into independent
Browse files Browse the repository at this point in the history
  • Loading branch information
vishnukvmd committed Jan 26, 2024
2 parents 5fde3c5 + aaa38d8 commit c54e7a7
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 32 deletions.
90 changes: 62 additions & 28 deletions lib/app.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "dart:async";
import 'dart:io';

import 'package:adaptive_theme/adaptive_theme.dart';
Expand All @@ -12,6 +13,7 @@ import 'package:photos/ente_theme_data.dart';
import "package:photos/generated/l10n.dart";
import "package:photos/l10n/l10n.dart";
import 'package:photos/services/app_lifecycle_service.dart';
import "package:photos/services/semantic_search/semantic_search_service.dart";
import 'package:photos/services/sync_service.dart';
import 'package:photos/ui/tabs/home_widget.dart';
import "package:photos/ui/viewer/actions/file_viewer.dart";
Expand Down Expand Up @@ -41,8 +43,12 @@ class EnteApp extends StatefulWidget {
}

class _EnteAppState extends State<EnteApp> with WidgetsBindingObserver {
static const initialInteractionTimeout = Duration(seconds: 10);
static const defaultInteractionTimeout = Duration(seconds: 5);

final _logger = Logger("EnteAppState");
late Locale locale;
late Timer _userInteractionTimer;

@override
void initState() {
Expand All @@ -51,6 +57,7 @@ class _EnteAppState extends State<EnteApp> with WidgetsBindingObserver {
locale = widget.locale;
setupIntentAction();
WidgetsBinding.instance.addObserver(this);
_setupInteractionTimer(timeout: initialInteractionTimeout);
}

setLocale(Locale newLocale) {
Expand All @@ -69,22 +76,65 @@ class _EnteAppState extends State<EnteApp> with WidgetsBindingObserver {
}
}

void _resetTimer() {
_userInteractionTimer.cancel();
_setupInteractionTimer();
}

void _setupInteractionTimer({Duration timeout = defaultInteractionTimeout}) {
_userInteractionTimer = Timer(timeout, () {
debugPrint("user is not interacting with the app");
SemanticSearchService.instance.resumeIndexing();
});
}

@override
Widget build(BuildContext context) {
if (Platform.isAndroid || kDebugMode) {
return AdaptiveTheme(
light: lightThemeData,
dark: darkThemeData,
initial: widget.savedThemeMode ?? AdaptiveThemeMode.system,
builder: (lightTheme, dartTheme) => MaterialApp(
return Listener(
onPointerDown: (event) {
SemanticSearchService.instance.pauseIndexing();
debugPrint("user is interacting with the app");
_resetTimer();
},
child: AdaptiveTheme(
light: lightThemeData,
dark: darkThemeData,
initial: widget.savedThemeMode ?? AdaptiveThemeMode.system,
builder: (lightTheme, dartTheme) => MaterialApp(
title: "ente",
themeMode: ThemeMode.system,
theme: lightTheme,
darkTheme: dartTheme,
home: AppLifecycleService.instance.mediaExtensionAction.action ==
IntentAction.view
? const FileViewer()
: const HomeWidget(),
debugShowCheckedModeBanner: false,
builder: EasyLoading.init(),
locale: locale,
supportedLocales: appSupportedLocales,
localeListResolutionCallback: localResolutionCallBack,
localizationsDelegates: const [
...AppLocalizations.localizationsDelegates,
S.delegate,
],
),
),
);
} else {
return Listener(
onPointerDown: (event) {
SemanticSearchService.instance.pauseIndexing();
debugPrint("user is interacting with the app");
_resetTimer();
},
child: MaterialApp(
title: "ente",
themeMode: ThemeMode.system,
theme: lightTheme,
darkTheme: dartTheme,
home: AppLifecycleService.instance.mediaExtensionAction.action ==
IntentAction.view
? const FileViewer()
: const HomeWidget(),
theme: lightThemeData,
darkTheme: darkThemeData,
home: const HomeWidget(),
debugShowCheckedModeBanner: false,
builder: EasyLoading.init(),
locale: locale,
Expand All @@ -96,29 +146,13 @@ class _EnteAppState extends State<EnteApp> with WidgetsBindingObserver {
],
),
);
} else {
return MaterialApp(
title: "ente",
themeMode: ThemeMode.system,
theme: lightThemeData,
darkTheme: darkThemeData,
home: const HomeWidget(),
debugShowCheckedModeBanner: false,
builder: EasyLoading.init(),
locale: locale,
supportedLocales: appSupportedLocales,
localeListResolutionCallback: localResolutionCallBack,
localizationsDelegates: const [
...AppLocalizations.localizationsDelegates,
S.delegate,
],
);
}
}

@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
_userInteractionTimer.cancel();
super.dispose();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class OnnxImageEncoder {
..setIntraOpNumThreads(1)
..setSessionGraphOptimizationLevel(GraphOptimizationLevel.ortEnableAll);
try {
final bytes = File(args["imageModelPath"]).readAsBytesSync();
final bytes = await File(args["imageModelPath"]).readAsBytes();
final session = OrtSession.fromBuffer(bytes, sessionOptions);
_logger.info('image model loaded');
return session.address;
Expand All @@ -25,10 +25,10 @@ class OnnxImageEncoder {
return -1;
}

List<double> inferByImage(Map args) {
Future<List<double>> inferByImage(Map args) async {
final runOptions = OrtRunOptions();
//Check the existence of imagePath locally
final rgb = img.decodeImage(File(args["imagePath"]).readAsBytesSync())!;
final rgb = img.decodeImage(await File(args["imagePath"]).readAsBytes())!;

final int nx = rgb.width;
final int ny = rgb.height;
Expand Down
17 changes: 17 additions & 0 deletions lib/services/semantic_search/semantic_search_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,22 @@ class SemanticSearchService {
Future<List<EnteFile>>? _ongoingRequest;
List<Embedding> _cachedEmbeddings = <Embedding>[];
PendingQuery? _nextQuery;
Completer<void> _userInteraction = Completer<void>();

get hasInitialized => _hasInitialized;

void resumeIndexing() {
_logger.info("Resuming indexing");
_userInteraction.complete();
}

void pauseIndexing() {
if (_userInteraction.isCompleted) {
_logger.info("Pausing indexing");
_userInteraction = Completer<void>();
}
}

Future<void> init({bool shouldSyncImmediately = false}) async {
if (!LocalSettings.instance.hasEnabledMagicSearch()) {
return;
Expand Down Expand Up @@ -279,6 +292,10 @@ class SemanticSearchService {
if (!_frameworkInitialization.isCompleted) {
return;
}
if (!_userInteraction.isCompleted) {
_logger.info("Waiting for user interactions to stop...");
await _userInteraction.future;
}
try {
final thumbnail = await getThumbnailForUploadedFile(file);
if (thumbnail == null) {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ description: ente photos application
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html

version: 0.8.47+567
version: 0.8.48+568

environment:
sdk: ">=3.0.0 <4.0.0"
Expand Down

0 comments on commit c54e7a7

Please sign in to comment.