sync initial
This commit is contained in:
@@ -29,6 +29,7 @@ export 'src/domain/services/gecko_readerable.dart';
|
||||
export 'src/domain/services/gecko_selection_action.dart';
|
||||
export 'src/domain/services/gecko_session.dart';
|
||||
export 'src/domain/services/gecko_suggestions.dart';
|
||||
export 'src/domain/services/gecko_sync.dart';
|
||||
export 'src/domain/services/gecko_tab.dart';
|
||||
export 'src/domain/services/gecko_tab_content.dart';
|
||||
export 'src/domain/services/gecko_viewport.dart';
|
||||
@@ -84,6 +85,13 @@ export 'src/pigeons/gecko.g.dart'
|
||||
SecurityInfoState,
|
||||
SitePermissionStatus,
|
||||
SitePermissions,
|
||||
SyncAccountInfo,
|
||||
SyncDevice,
|
||||
SyncDeviceTabs,
|
||||
SyncEngineStatus,
|
||||
SyncEngineValue,
|
||||
SyncIncomingTab,
|
||||
SyncRemoteTab,
|
||||
TabContent,
|
||||
TabContentState,
|
||||
TrackingProtectionException,
|
||||
|
||||
@@ -22,12 +22,16 @@ class GeckoBrowserService {
|
||||
LogLevel logLevel,
|
||||
ContentBlocking contentBlocking,
|
||||
AddonCollection? addonCollection,
|
||||
String? fxaServerOverride,
|
||||
String? syncTokenServerOverride,
|
||||
) {
|
||||
return _api.initialize(
|
||||
profileFolder,
|
||||
logLevel,
|
||||
contentBlocking,
|
||||
addonCollection,
|
||||
fxaServerOverride,
|
||||
syncTokenServerOverride,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_mozilla_components/src/extensions/subject.dart';
|
||||
import 'package:flutter_mozilla_components/src/pigeons/gecko.g.dart';
|
||||
import 'package:rxdart/rxdart.dart';
|
||||
|
||||
final _apiInstance = GeckoSyncApi();
|
||||
|
||||
class GeckoSyncService {
|
||||
final GeckoSyncApi _api;
|
||||
|
||||
GeckoSyncService({GeckoSyncApi? api}) : _api = api ?? _apiInstance;
|
||||
|
||||
Future<SyncAccountInfo> getAccountInfo() {
|
||||
return _api.getAccountInfo();
|
||||
}
|
||||
|
||||
Future<void> beginAuthentication() {
|
||||
return _api.beginAuthentication();
|
||||
}
|
||||
|
||||
Future<void> beginPairingAuthentication(String pairingUrl) {
|
||||
return _api.beginPairingAuthentication(pairingUrl);
|
||||
}
|
||||
|
||||
Future<void> logout() {
|
||||
return _api.logout();
|
||||
}
|
||||
|
||||
Future<void> syncNow() {
|
||||
return _api.syncNow();
|
||||
}
|
||||
|
||||
Future<void> setEngineEnabled(SyncEngineValue engine, bool enabled) {
|
||||
return _api.setEngineEnabled(engine, enabled);
|
||||
}
|
||||
|
||||
Future<List<SyncDeviceTabs>> getSyncedTabs() {
|
||||
return _api.getSyncedTabs();
|
||||
}
|
||||
|
||||
Future<List<SyncDevice>> getDevices() {
|
||||
return _api.getDevices();
|
||||
}
|
||||
|
||||
Future<bool> sendTabToDevice(String deviceId, String title, String url) {
|
||||
return _api.sendTabToDevice(deviceId, title, url);
|
||||
}
|
||||
|
||||
Future<void> refreshDevices() {
|
||||
return _api.refreshDevices();
|
||||
}
|
||||
|
||||
Future<void> pollDeviceCommands() {
|
||||
return _api.pollDeviceCommands();
|
||||
}
|
||||
|
||||
Future<List<SyncIncomingTab>> drainIncomingTabs() {
|
||||
return _api.drainIncomingTabs();
|
||||
}
|
||||
|
||||
Future<String?> getDeviceName() {
|
||||
return _api.getDeviceName();
|
||||
}
|
||||
|
||||
Future<bool> setDeviceName(String newName) {
|
||||
return _api.setDeviceName(newName);
|
||||
}
|
||||
}
|
||||
|
||||
class GeckoSyncStateService extends GeckoSyncStateEvents {
|
||||
final _authStateSubject = BehaviorSubject<SyncAccountInfo>();
|
||||
final _syncStartedSubject = PublishSubject<void>();
|
||||
final _syncCompletedSubject = PublishSubject<void>();
|
||||
final _syncErrorSubject = PublishSubject<String?>();
|
||||
|
||||
ValueStream<SyncAccountInfo> get authStateEvents => _authStateSubject.stream;
|
||||
Stream<void> get syncStartedEvents => _syncStartedSubject.stream;
|
||||
Stream<void> get syncCompletedEvents => _syncCompletedSubject.stream;
|
||||
Stream<String?> get syncErrorEvents => _syncErrorSubject.stream;
|
||||
|
||||
@override
|
||||
void onAuthStateChanged(int sequence, SyncAccountInfo accountInfo) {
|
||||
_authStateSubject.addWhenMoreRecent(sequence, null, accountInfo);
|
||||
}
|
||||
|
||||
@override
|
||||
void onSyncStarted(int sequence) {
|
||||
_syncStartedSubject.addWhenMoreRecent(sequence, null, null);
|
||||
}
|
||||
|
||||
@override
|
||||
void onSyncCompleted(int sequence) {
|
||||
_syncCompletedSubject.addWhenMoreRecent(sequence, null, null);
|
||||
}
|
||||
|
||||
@override
|
||||
void onSyncError(int sequence, String? errorMessage) {
|
||||
_syncErrorSubject.addWhenMoreRecent(sequence, null, errorMessage);
|
||||
}
|
||||
|
||||
GeckoSyncStateService.setUp({
|
||||
BinaryMessenger? binaryMessenger,
|
||||
String messageChannelSuffix = '',
|
||||
}) {
|
||||
GeckoSyncStateEvents.setUp(
|
||||
this,
|
||||
binaryMessenger: binaryMessenger,
|
||||
messageChannelSuffix: messageChannelSuffix,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> dispose() async {
|
||||
await Future.wait([
|
||||
_authStateSubject.close(),
|
||||
_syncStartedSubject.close(),
|
||||
_syncCompletedSubject.close(),
|
||||
_syncErrorSubject.close(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user