perf(settings): batch and deduplicate writes and persist panel dimensions
This commit is contained in:
1 parent
bc3fdd6119
commit
02413383d8
23 files changed
+869
-83
No files matched your search
@@ -27,8 +27,8 @@ class AppearanceSettings extends _$AppearanceSettings {
|
||||
|
||||
Future<void> setMode(AppAppearance appearance) => _writes.run(() async {
|
||||
if (!ref.mounted) return;
|
||||
await future;
|
||||
if (!ref.mounted) return;
|
||||
final current = await future;
|
||||
if (!ref.mounted || current == appearance) return;
|
||||
await ref.read(appearanceSettingsRepositoryProvider).save(appearance);
|
||||
if (ref.mounted) state = AsyncData(appearance);
|
||||
});
|
||||
@@ -44,8 +44,8 @@ class PaletteSettings extends _$PaletteSettings {
|
||||
|
||||
Future<void> setPalette(AppPalette palette) => _writes.run(() async {
|
||||
if (!ref.mounted) return;
|
||||
await future;
|
||||
if (!ref.mounted) return;
|
||||
final current = await future;
|
||||
if (!ref.mounted || current == palette) return;
|
||||
await ref.read(paletteSettingsRepositoryProvider).save(palette);
|
||||
if (ref.mounted) state = AsyncData(palette);
|
||||
});
|
||||
|
||||
@@ -34,7 +34,7 @@ final class AppearanceSettingsProvider
|
||||
}
|
||||
|
||||
String _$appearanceSettingsHash() =>
|
||||
r'df889bcd3ec16a726ebc1bccd98b9e7033989a69';
|
||||
r'c540755d69e4441b38db07394df144a0fc3544da';
|
||||
|
||||
abstract class _$AppearanceSettings extends $AsyncNotifier<AppAppearance> {
|
||||
FutureOr<AppAppearance> build();
|
||||
@@ -78,7 +78,7 @@ final class PaletteSettingsProvider
|
||||
PaletteSettings create() => PaletteSettings();
|
||||
}
|
||||
|
||||
String _$paletteSettingsHash() => r'95eecd4a35c8de3afbf6c94b1e13f282acb0f4ff';
|
||||
String _$paletteSettingsHash() => r'8676c4ef0be0ce7132da7c53b9694da56e9c658d';
|
||||
|
||||
abstract class _$PaletteSettings extends $AsyncNotifier<AppPalette> {
|
||||
FutureOr<AppPalette> build();
|
||||
|
||||
@@ -89,8 +89,8 @@ class LanguageSettings extends _$LanguageSettings {
|
||||
|
||||
Future<void> setLanguage(AppLanguage language) => _writes.run(() async {
|
||||
if (!ref.mounted) return;
|
||||
await future;
|
||||
if (!ref.mounted) return;
|
||||
final current = await future;
|
||||
if (!ref.mounted || current == language) return;
|
||||
await ref.read(languageSettingsRepositoryProvider).save(language);
|
||||
if (ref.mounted) state = AsyncData(language);
|
||||
});
|
||||
|
||||
@@ -33,7 +33,7 @@ final class LanguageSettingsProvider
|
||||
LanguageSettings create() => LanguageSettings();
|
||||
}
|
||||
|
||||
String _$languageSettingsHash() => r'fcd5bb7f010ea5bb09f9743d9023cd1668214f43';
|
||||
String _$languageSettingsHash() => r'6a1989abb393d00e262506572b1dfdd5b09be6c4';
|
||||
|
||||
abstract class _$LanguageSettings extends $AsyncNotifier<AppLanguage> {
|
||||
FutureOr<AppLanguage> build();
|
||||
|
||||
@@ -19,8 +19,8 @@ class TimelineRulerSettings extends _$TimelineRulerSettings {
|
||||
Future<void> setLayout(TimelineRulerTimecodeLayout layout) =>
|
||||
_writes.run(() async {
|
||||
if (!ref.mounted) return;
|
||||
await future;
|
||||
if (!ref.mounted) return;
|
||||
final current = await future;
|
||||
if (!ref.mounted || current == layout) return;
|
||||
await ref.read(timelineRulerSettingsRepositoryProvider).save(layout);
|
||||
if (ref.mounted) state = AsyncData(layout);
|
||||
});
|
||||
|
||||
@@ -38,7 +38,7 @@ final class TimelineRulerSettingsProvider
|
||||
}
|
||||
|
||||
String _$timelineRulerSettingsHash() =>
|
||||
r'26aef397f2aee8114b1d1229bb1c0b3f7a377f73';
|
||||
r'4917c2ec4b2aa715c9e0e2a45cd05adb66ae6089';
|
||||
|
||||
abstract class _$TimelineRulerSettings
|
||||
extends $AsyncNotifier<TimelineRulerTimecodeLayout> {
|
||||
|
||||
@@ -44,6 +44,7 @@ class McpSettings extends _$McpSettings {
|
||||
port: port ?? current.port,
|
||||
);
|
||||
_validate(next);
|
||||
if (next == current) return;
|
||||
await _persist(next);
|
||||
if (ref.mounted) state = AsyncData(next);
|
||||
});
|
||||
|
||||
@@ -33,7 +33,7 @@ final class McpSettingsProvider
|
||||
McpSettings create() => McpSettings();
|
||||
}
|
||||
|
||||
String _$mcpSettingsHash() => r'122c5ad73d0eec5808c546eb66dde6c4b0f29a8a';
|
||||
String _$mcpSettingsHash() => r'44c7a3dec17e78b4a67c5de92b1f5ae708af7f84';
|
||||
|
||||
abstract class _$McpSettings extends $AsyncNotifier<McpSettingsValue> {
|
||||
FutureOr<McpSettingsValue> build();
|
||||
|
||||
@@ -127,6 +127,7 @@ class ProjectViewConfigurations extends Table {
|
||||
TextColumn get projectId => text()();
|
||||
BoolColumn get propertiesOpen => boolean()();
|
||||
RealColumn get timelineHeight => real().nullable()();
|
||||
RealColumn get mediaWidth => real().nullable()();
|
||||
|
||||
@override
|
||||
Set<Column<Object>> get primaryKey => {projectId};
|
||||
@@ -169,13 +170,13 @@ class AppDatabase extends _$AppDatabase {
|
||||
AppDatabase(super.executor);
|
||||
|
||||
@override
|
||||
int get schemaVersion => 4;
|
||||
int get schemaVersion => 5;
|
||||
|
||||
@override
|
||||
MigrationStrategy get migration => MigrationStrategy(
|
||||
onCreate: (migrator) => migrator.createAll(),
|
||||
onUpgrade: (migrator, from, _) async {
|
||||
if (from != 2 && from != 3) {
|
||||
if (from < 2 || from > 4) {
|
||||
throw StateError('Unsupported app database schema version: $from');
|
||||
}
|
||||
if (from == 2) {
|
||||
@@ -184,9 +185,15 @@ class AppDatabase extends _$AppDatabase {
|
||||
appearanceConfigurations.palette,
|
||||
);
|
||||
}
|
||||
if (from < 4) {
|
||||
await migrator.addColumn(
|
||||
appearanceConfigurations,
|
||||
appearanceConfigurations.timelineRulerLayout,
|
||||
);
|
||||
}
|
||||
await migrator.addColumn(
|
||||
appearanceConfigurations,
|
||||
appearanceConfigurations.timelineRulerLayout,
|
||||
projectViewConfigurations,
|
||||
projectViewConfigurations.mediaWidth,
|
||||
);
|
||||
},
|
||||
beforeOpen: (_) async {
|
||||
|
||||
@@ -3535,11 +3535,23 @@ class $ProjectViewConfigurationsTable extends ProjectViewConfigurations
|
||||
type: DriftSqlType.double,
|
||||
requiredDuringInsert: false,
|
||||
);
|
||||
static const VerificationMeta _mediaWidthMeta = const VerificationMeta(
|
||||
'mediaWidth',
|
||||
);
|
||||
@override
|
||||
late final GeneratedColumn<double> mediaWidth = GeneratedColumn<double>(
|
||||
'media_width',
|
||||
aliasedName,
|
||||
true,
|
||||
type: DriftSqlType.double,
|
||||
requiredDuringInsert: false,
|
||||
);
|
||||
@override
|
||||
List<GeneratedColumn> get $columns => [
|
||||
projectId,
|
||||
propertiesOpen,
|
||||
timelineHeight,
|
||||
mediaWidth,
|
||||
];
|
||||
@override
|
||||
String get aliasedName => _alias ?? actualTableName;
|
||||
@@ -3581,6 +3593,12 @@ class $ProjectViewConfigurationsTable extends ProjectViewConfigurations
|
||||
),
|
||||
);
|
||||
}
|
||||
if (data.containsKey('media_width')) {
|
||||
context.handle(
|
||||
_mediaWidthMeta,
|
||||
mediaWidth.isAcceptableOrUnknown(data['media_width']!, _mediaWidthMeta),
|
||||
);
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
@@ -3605,6 +3623,10 @@ class $ProjectViewConfigurationsTable extends ProjectViewConfigurations
|
||||
DriftSqlType.double,
|
||||
data['${effectivePrefix}timeline_height'],
|
||||
),
|
||||
mediaWidth: attachedDatabase.typeMapping.read(
|
||||
DriftSqlType.double,
|
||||
data['${effectivePrefix}media_width'],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3619,10 +3641,12 @@ class ProjectViewConfiguration extends DataClass
|
||||
final String projectId;
|
||||
final bool propertiesOpen;
|
||||
final double? timelineHeight;
|
||||
final double? mediaWidth;
|
||||
const ProjectViewConfiguration({
|
||||
required this.projectId,
|
||||
required this.propertiesOpen,
|
||||
this.timelineHeight,
|
||||
this.mediaWidth,
|
||||
});
|
||||
@override
|
||||
Map<String, Expression> toColumns(bool nullToAbsent) {
|
||||
@@ -3632,6 +3656,9 @@ class ProjectViewConfiguration extends DataClass
|
||||
if (!nullToAbsent || timelineHeight != null) {
|
||||
map['timeline_height'] = Variable<double>(timelineHeight);
|
||||
}
|
||||
if (!nullToAbsent || mediaWidth != null) {
|
||||
map['media_width'] = Variable<double>(mediaWidth);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@@ -3642,6 +3669,9 @@ class ProjectViewConfiguration extends DataClass
|
||||
timelineHeight: timelineHeight == null && nullToAbsent
|
||||
? const Value.absent()
|
||||
: Value(timelineHeight),
|
||||
mediaWidth: mediaWidth == null && nullToAbsent
|
||||
? const Value.absent()
|
||||
: Value(mediaWidth),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3654,6 +3684,7 @@ class ProjectViewConfiguration extends DataClass
|
||||
projectId: serializer.fromJson<String>(json['projectId']),
|
||||
propertiesOpen: serializer.fromJson<bool>(json['propertiesOpen']),
|
||||
timelineHeight: serializer.fromJson<double?>(json['timelineHeight']),
|
||||
mediaWidth: serializer.fromJson<double?>(json['mediaWidth']),
|
||||
);
|
||||
}
|
||||
@override
|
||||
@@ -3663,6 +3694,7 @@ class ProjectViewConfiguration extends DataClass
|
||||
'projectId': serializer.toJson<String>(projectId),
|
||||
'propertiesOpen': serializer.toJson<bool>(propertiesOpen),
|
||||
'timelineHeight': serializer.toJson<double?>(timelineHeight),
|
||||
'mediaWidth': serializer.toJson<double?>(mediaWidth),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -3670,12 +3702,14 @@ class ProjectViewConfiguration extends DataClass
|
||||
String? projectId,
|
||||
bool? propertiesOpen,
|
||||
Value<double?> timelineHeight = const Value.absent(),
|
||||
Value<double?> mediaWidth = const Value.absent(),
|
||||
}) => ProjectViewConfiguration(
|
||||
projectId: projectId ?? this.projectId,
|
||||
propertiesOpen: propertiesOpen ?? this.propertiesOpen,
|
||||
timelineHeight: timelineHeight.present
|
||||
? timelineHeight.value
|
||||
: this.timelineHeight,
|
||||
mediaWidth: mediaWidth.present ? mediaWidth.value : this.mediaWidth,
|
||||
);
|
||||
ProjectViewConfiguration copyWithCompanion(
|
||||
ProjectViewConfigurationsCompanion data,
|
||||
@@ -3688,6 +3722,9 @@ class ProjectViewConfiguration extends DataClass
|
||||
timelineHeight: data.timelineHeight.present
|
||||
? data.timelineHeight.value
|
||||
: this.timelineHeight,
|
||||
mediaWidth: data.mediaWidth.present
|
||||
? data.mediaWidth.value
|
||||
: this.mediaWidth,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3696,20 +3733,23 @@ class ProjectViewConfiguration extends DataClass
|
||||
return (StringBuffer('ProjectViewConfiguration(')
|
||||
..write('projectId: $projectId, ')
|
||||
..write('propertiesOpen: $propertiesOpen, ')
|
||||
..write('timelineHeight: $timelineHeight')
|
||||
..write('timelineHeight: $timelineHeight, ')
|
||||
..write('mediaWidth: $mediaWidth')
|
||||
..write(')'))
|
||||
.toString();
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(projectId, propertiesOpen, timelineHeight);
|
||||
int get hashCode =>
|
||||
Object.hash(projectId, propertiesOpen, timelineHeight, mediaWidth);
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
(other is ProjectViewConfiguration &&
|
||||
other.projectId == this.projectId &&
|
||||
other.propertiesOpen == this.propertiesOpen &&
|
||||
other.timelineHeight == this.timelineHeight);
|
||||
other.timelineHeight == this.timelineHeight &&
|
||||
other.mediaWidth == this.mediaWidth);
|
||||
}
|
||||
|
||||
class ProjectViewConfigurationsCompanion
|
||||
@@ -3717,17 +3757,20 @@ class ProjectViewConfigurationsCompanion
|
||||
final Value<String> projectId;
|
||||
final Value<bool> propertiesOpen;
|
||||
final Value<double?> timelineHeight;
|
||||
final Value<double?> mediaWidth;
|
||||
final Value<int> rowid;
|
||||
const ProjectViewConfigurationsCompanion({
|
||||
this.projectId = const Value.absent(),
|
||||
this.propertiesOpen = const Value.absent(),
|
||||
this.timelineHeight = const Value.absent(),
|
||||
this.mediaWidth = const Value.absent(),
|
||||
this.rowid = const Value.absent(),
|
||||
});
|
||||
ProjectViewConfigurationsCompanion.insert({
|
||||
required String projectId,
|
||||
required bool propertiesOpen,
|
||||
this.timelineHeight = const Value.absent(),
|
||||
this.mediaWidth = const Value.absent(),
|
||||
this.rowid = const Value.absent(),
|
||||
}) : projectId = Value(projectId),
|
||||
propertiesOpen = Value(propertiesOpen);
|
||||
@@ -3735,12 +3778,14 @@ class ProjectViewConfigurationsCompanion
|
||||
Expression<String>? projectId,
|
||||
Expression<bool>? propertiesOpen,
|
||||
Expression<double>? timelineHeight,
|
||||
Expression<double>? mediaWidth,
|
||||
Expression<int>? rowid,
|
||||
}) {
|
||||
return RawValuesInsertable({
|
||||
if (projectId != null) 'project_id': projectId,
|
||||
if (propertiesOpen != null) 'properties_open': propertiesOpen,
|
||||
if (timelineHeight != null) 'timeline_height': timelineHeight,
|
||||
if (mediaWidth != null) 'media_width': mediaWidth,
|
||||
if (rowid != null) 'rowid': rowid,
|
||||
});
|
||||
}
|
||||
@@ -3749,12 +3794,14 @@ class ProjectViewConfigurationsCompanion
|
||||
Value<String>? projectId,
|
||||
Value<bool>? propertiesOpen,
|
||||
Value<double?>? timelineHeight,
|
||||
Value<double?>? mediaWidth,
|
||||
Value<int>? rowid,
|
||||
}) {
|
||||
return ProjectViewConfigurationsCompanion(
|
||||
projectId: projectId ?? this.projectId,
|
||||
propertiesOpen: propertiesOpen ?? this.propertiesOpen,
|
||||
timelineHeight: timelineHeight ?? this.timelineHeight,
|
||||
mediaWidth: mediaWidth ?? this.mediaWidth,
|
||||
rowid: rowid ?? this.rowid,
|
||||
);
|
||||
}
|
||||
@@ -3771,6 +3818,9 @@ class ProjectViewConfigurationsCompanion
|
||||
if (timelineHeight.present) {
|
||||
map['timeline_height'] = Variable<double>(timelineHeight.value);
|
||||
}
|
||||
if (mediaWidth.present) {
|
||||
map['media_width'] = Variable<double>(mediaWidth.value);
|
||||
}
|
||||
if (rowid.present) {
|
||||
map['rowid'] = Variable<int>(rowid.value);
|
||||
}
|
||||
@@ -3783,6 +3833,7 @@ class ProjectViewConfigurationsCompanion
|
||||
..write('projectId: $projectId, ')
|
||||
..write('propertiesOpen: $propertiesOpen, ')
|
||||
..write('timelineHeight: $timelineHeight, ')
|
||||
..write('mediaWidth: $mediaWidth, ')
|
||||
..write('rowid: $rowid')
|
||||
..write(')'))
|
||||
.toString();
|
||||
@@ -6782,6 +6833,7 @@ typedef $$ProjectViewConfigurationsTableCreateCompanionBuilder =
|
||||
required String projectId,
|
||||
required bool propertiesOpen,
|
||||
Value<double?> timelineHeight,
|
||||
Value<double?> mediaWidth,
|
||||
Value<int> rowid,
|
||||
});
|
||||
typedef $$ProjectViewConfigurationsTableUpdateCompanionBuilder =
|
||||
@@ -6789,6 +6841,7 @@ typedef $$ProjectViewConfigurationsTableUpdateCompanionBuilder =
|
||||
Value<String> projectId,
|
||||
Value<bool> propertiesOpen,
|
||||
Value<double?> timelineHeight,
|
||||
Value<double?> mediaWidth,
|
||||
Value<int> rowid,
|
||||
});
|
||||
|
||||
@@ -6815,6 +6868,11 @@ class $$ProjectViewConfigurationsTableFilterComposer
|
||||
column: $table.timelineHeight,
|
||||
builder: (column) => ColumnFilters(column),
|
||||
);
|
||||
|
||||
ColumnFilters<double> get mediaWidth => $composableBuilder(
|
||||
column: $table.mediaWidth,
|
||||
builder: (column) => ColumnFilters(column),
|
||||
);
|
||||
}
|
||||
|
||||
class $$ProjectViewConfigurationsTableOrderingComposer
|
||||
@@ -6840,6 +6898,11 @@ class $$ProjectViewConfigurationsTableOrderingComposer
|
||||
column: $table.timelineHeight,
|
||||
builder: (column) => ColumnOrderings(column),
|
||||
);
|
||||
|
||||
ColumnOrderings<double> get mediaWidth => $composableBuilder(
|
||||
column: $table.mediaWidth,
|
||||
builder: (column) => ColumnOrderings(column),
|
||||
);
|
||||
}
|
||||
|
||||
class $$ProjectViewConfigurationsTableAnnotationComposer
|
||||
@@ -6863,6 +6926,11 @@ class $$ProjectViewConfigurationsTableAnnotationComposer
|
||||
column: $table.timelineHeight,
|
||||
builder: (column) => column,
|
||||
);
|
||||
|
||||
GeneratedColumn<double> get mediaWidth => $composableBuilder(
|
||||
column: $table.mediaWidth,
|
||||
builder: (column) => column,
|
||||
);
|
||||
}
|
||||
|
||||
class $$ProjectViewConfigurationsTableTableManager
|
||||
@@ -6914,11 +6982,13 @@ class $$ProjectViewConfigurationsTableTableManager
|
||||
Value<String> projectId = const Value.absent(),
|
||||
Value<bool> propertiesOpen = const Value.absent(),
|
||||
Value<double?> timelineHeight = const Value.absent(),
|
||||
Value<double?> mediaWidth = const Value.absent(),
|
||||
Value<int> rowid = const Value.absent(),
|
||||
}) => ProjectViewConfigurationsCompanion(
|
||||
projectId: projectId,
|
||||
propertiesOpen: propertiesOpen,
|
||||
timelineHeight: timelineHeight,
|
||||
mediaWidth: mediaWidth,
|
||||
rowid: rowid,
|
||||
),
|
||||
createCompanionCallback:
|
||||
@@ -6926,11 +6996,13 @@ class $$ProjectViewConfigurationsTableTableManager
|
||||
required String projectId,
|
||||
required bool propertiesOpen,
|
||||
Value<double?> timelineHeight = const Value.absent(),
|
||||
Value<double?> mediaWidth = const Value.absent(),
|
||||
Value<int> rowid = const Value.absent(),
|
||||
}) => ProjectViewConfigurationsCompanion.insert(
|
||||
projectId: projectId,
|
||||
propertiesOpen: propertiesOpen,
|
||||
timelineHeight: timelineHeight,
|
||||
mediaWidth: mediaWidth,
|
||||
rowid: rowid,
|
||||
),
|
||||
withReferenceMapper: (p0) => p0
|
||||
|
||||
@@ -60,32 +60,29 @@ class DriftAgentSettingsRepository implements AgentSettingsRepository {
|
||||
_database.transaction(() async {
|
||||
await _database.delete(_database.agentModels).go();
|
||||
await _database.delete(_database.agentProviders).go();
|
||||
for (final provider in settings.providers) {
|
||||
await _database
|
||||
.into(_database.agentProviders)
|
||||
.insert(
|
||||
AgentProvidersCompanion.insert(
|
||||
id: provider.id,
|
||||
enabled: Value(provider.enabled),
|
||||
name: provider.name,
|
||||
apiType: provider.apiType,
|
||||
baseUrl: provider.baseUrl,
|
||||
credentialId: Value(provider.credentialId),
|
||||
await _database.batch((batch) {
|
||||
batch.insertAll(_database.agentProviders, [
|
||||
for (final provider in settings.providers)
|
||||
AgentProvidersCompanion.insert(
|
||||
id: provider.id,
|
||||
enabled: Value(provider.enabled),
|
||||
name: provider.name,
|
||||
apiType: provider.apiType,
|
||||
baseUrl: provider.baseUrl,
|
||||
credentialId: Value(provider.credentialId),
|
||||
),
|
||||
]);
|
||||
batch.insertAll(_database.agentModels, [
|
||||
for (final provider in settings.providers)
|
||||
for (final model in provider.models)
|
||||
AgentModelsCompanion.insert(
|
||||
providerId: provider.id,
|
||||
modelId: model.id,
|
||||
contextWindow: Value(model.contextWindow),
|
||||
maxOutputTokens: Value(model.maxOutputTokens),
|
||||
),
|
||||
);
|
||||
for (final model in provider.models) {
|
||||
await _database
|
||||
.into(_database.agentModels)
|
||||
.insert(
|
||||
AgentModelsCompanion.insert(
|
||||
providerId: provider.id,
|
||||
modelId: model.id,
|
||||
contextWindow: Value(model.contextWindow),
|
||||
maxOutputTokens: Value(model.maxOutputTokens),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
]);
|
||||
});
|
||||
await _database
|
||||
.into(_database.agentConfigurations)
|
||||
.insertOnConflictUpdate(
|
||||
|
||||
@@ -74,6 +74,7 @@ abstract class ProjectViewSettingsData with _$ProjectViewSettingsData {
|
||||
const factory ProjectViewSettingsData({
|
||||
@Default(false) bool propertiesOpen,
|
||||
double? timelineHeight,
|
||||
double? mediaWidth,
|
||||
}) = _ProjectViewSettingsData;
|
||||
}
|
||||
|
||||
@@ -101,6 +102,7 @@ class DriftProjectViewSettingsRepository
|
||||
: ProjectViewSettingsData(
|
||||
propertiesOpen: row.propertiesOpen,
|
||||
timelineHeight: row.timelineHeight,
|
||||
mediaWidth: row.mediaWidth,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -113,6 +115,7 @@ class DriftProjectViewSettingsRepository
|
||||
projectId: projectId,
|
||||
propertiesOpen: settings.propertiesOpen,
|
||||
timelineHeight: Value(settings.timelineHeight),
|
||||
mediaWidth: Value(settings.mediaWidth),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -464,6 +464,7 @@ class __$WorkspaceViewSettingsDataCopyWithImpl<$Res>
|
||||
mixin _$ProjectViewSettingsData {
|
||||
bool get propertiesOpen;
|
||||
double? get timelineHeight;
|
||||
double? get mediaWidth;
|
||||
|
||||
/// Create a copy of ProjectViewSettingsData
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@@ -484,19 +485,26 @@ mixin _$ProjectViewSettingsData {
|
||||
(identical(other.propertiesOpen, _this.propertiesOpen) ||
|
||||
other.propertiesOpen == _this.propertiesOpen) &&
|
||||
(identical(other.timelineHeight, _this.timelineHeight) ||
|
||||
other.timelineHeight == _this.timelineHeight));
|
||||
other.timelineHeight == _this.timelineHeight) &&
|
||||
(identical(other.mediaWidth, _this.mediaWidth) ||
|
||||
other.mediaWidth == _this.mediaWidth));
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
final _this = this as ProjectViewSettingsData;
|
||||
return Object.hash(runtimeType, _this.propertiesOpen, _this.timelineHeight);
|
||||
return Object.hash(
|
||||
runtimeType,
|
||||
_this.propertiesOpen,
|
||||
_this.timelineHeight,
|
||||
_this.mediaWidth,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
final _this = this as ProjectViewSettingsData;
|
||||
return 'ProjectViewSettingsData(propertiesOpen: ${_this.propertiesOpen}, timelineHeight: ${_this.timelineHeight})';
|
||||
return 'ProjectViewSettingsData(propertiesOpen: ${_this.propertiesOpen}, timelineHeight: ${_this.timelineHeight}, mediaWidth: ${_this.mediaWidth})';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -507,7 +515,7 @@ abstract mixin class $ProjectViewSettingsDataCopyWith<$Res> {
|
||||
$Res Function(ProjectViewSettingsData) _then,
|
||||
) = _$ProjectViewSettingsDataCopyWithImpl;
|
||||
@useResult
|
||||
$Res call({bool propertiesOpen, double? timelineHeight});
|
||||
$Res call({bool propertiesOpen, double? timelineHeight, double? mediaWidth});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@@ -522,7 +530,11 @@ class _$ProjectViewSettingsDataCopyWithImpl<$Res>
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({Object? propertiesOpen = null, Object? timelineHeight = freezed}) {
|
||||
$Res call({
|
||||
Object? propertiesOpen = null,
|
||||
Object? timelineHeight = freezed,
|
||||
Object? mediaWidth = freezed,
|
||||
}) {
|
||||
return _then(
|
||||
ProjectViewSettingsData(
|
||||
propertiesOpen: null == propertiesOpen
|
||||
@@ -533,6 +545,10 @@ class _$ProjectViewSettingsDataCopyWithImpl<$Res>
|
||||
? _self.timelineHeight
|
||||
: timelineHeight // ignore: cast_nullable_to_non_nullable
|
||||
as double?,
|
||||
mediaWidth: freezed == mediaWidth
|
||||
? _self.mediaWidth
|
||||
: mediaWidth // ignore: cast_nullable_to_non_nullable
|
||||
as double?,
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -631,13 +647,22 @@ extension ProjectViewSettingsDataPatterns on ProjectViewSettingsData {
|
||||
|
||||
@optionalTypeArgs
|
||||
TResult maybeWhen<TResult extends Object?>(
|
||||
TResult Function(bool propertiesOpen, double? timelineHeight)? $default, {
|
||||
TResult Function(
|
||||
bool propertiesOpen,
|
||||
double? timelineHeight,
|
||||
double? mediaWidth,
|
||||
)?
|
||||
$default, {
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _ProjectViewSettingsData() when $default != null:
|
||||
return $default(_that.propertiesOpen, _that.timelineHeight);
|
||||
return $default(
|
||||
_that.propertiesOpen,
|
||||
_that.timelineHeight,
|
||||
_that.mediaWidth,
|
||||
);
|
||||
case _:
|
||||
return orElse();
|
||||
}
|
||||
@@ -658,12 +683,21 @@ extension ProjectViewSettingsDataPatterns on ProjectViewSettingsData {
|
||||
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>(
|
||||
TResult Function(bool propertiesOpen, double? timelineHeight) $default,
|
||||
TResult Function(
|
||||
bool propertiesOpen,
|
||||
double? timelineHeight,
|
||||
double? mediaWidth,
|
||||
)
|
||||
$default,
|
||||
) {
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _ProjectViewSettingsData():
|
||||
return $default(_that.propertiesOpen, _that.timelineHeight);
|
||||
return $default(
|
||||
_that.propertiesOpen,
|
||||
_that.timelineHeight,
|
||||
_that.mediaWidth,
|
||||
);
|
||||
case _:
|
||||
throw StateError('Unexpected subclass');
|
||||
}
|
||||
@@ -683,12 +717,21 @@ extension ProjectViewSettingsDataPatterns on ProjectViewSettingsData {
|
||||
|
||||
@optionalTypeArgs
|
||||
TResult? whenOrNull<TResult extends Object?>(
|
||||
TResult? Function(bool propertiesOpen, double? timelineHeight)? $default,
|
||||
TResult? Function(
|
||||
bool propertiesOpen,
|
||||
double? timelineHeight,
|
||||
double? mediaWidth,
|
||||
)?
|
||||
$default,
|
||||
) {
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _ProjectViewSettingsData() when $default != null:
|
||||
return $default(_that.propertiesOpen, _that.timelineHeight);
|
||||
return $default(
|
||||
_that.propertiesOpen,
|
||||
_that.timelineHeight,
|
||||
_that.mediaWidth,
|
||||
);
|
||||
case _:
|
||||
return null;
|
||||
}
|
||||
@@ -701,6 +744,7 @@ class _ProjectViewSettingsData extends ProjectViewSettingsData {
|
||||
const _ProjectViewSettingsData({
|
||||
this.propertiesOpen = false,
|
||||
this.timelineHeight,
|
||||
this.mediaWidth,
|
||||
}) : super._();
|
||||
|
||||
@override
|
||||
@@ -708,6 +752,8 @@ class _ProjectViewSettingsData extends ProjectViewSettingsData {
|
||||
final bool propertiesOpen;
|
||||
@override
|
||||
final double? timelineHeight;
|
||||
@override
|
||||
final double? mediaWidth;
|
||||
|
||||
/// Create a copy of ProjectViewSettingsData
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@@ -728,17 +774,19 @@ class _ProjectViewSettingsData extends ProjectViewSettingsData {
|
||||
(identical(other.propertiesOpen, propertiesOpen) ||
|
||||
other.propertiesOpen == propertiesOpen) &&
|
||||
(identical(other.timelineHeight, timelineHeight) ||
|
||||
other.timelineHeight == timelineHeight));
|
||||
other.timelineHeight == timelineHeight) &&
|
||||
(identical(other.mediaWidth, mediaWidth) ||
|
||||
other.mediaWidth == mediaWidth));
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return Object.hash(runtimeType, propertiesOpen, timelineHeight);
|
||||
return Object.hash(runtimeType, propertiesOpen, timelineHeight, mediaWidth);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'ProjectViewSettingsData(propertiesOpen: $propertiesOpen, timelineHeight: $timelineHeight)';
|
||||
return 'ProjectViewSettingsData(propertiesOpen: $propertiesOpen, timelineHeight: $timelineHeight, mediaWidth: $mediaWidth)';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -751,7 +799,7 @@ abstract mixin class _$ProjectViewSettingsDataCopyWith<$Res>
|
||||
) = __$ProjectViewSettingsDataCopyWithImpl;
|
||||
@override
|
||||
@useResult
|
||||
$Res call({bool propertiesOpen, double? timelineHeight});
|
||||
$Res call({bool propertiesOpen, double? timelineHeight, double? mediaWidth});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@@ -766,7 +814,11 @@ class __$ProjectViewSettingsDataCopyWithImpl<$Res>
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
$Res call({Object? propertiesOpen = null, Object? timelineHeight = freezed}) {
|
||||
$Res call({
|
||||
Object? propertiesOpen = null,
|
||||
Object? timelineHeight = freezed,
|
||||
Object? mediaWidth = freezed,
|
||||
}) {
|
||||
return _then(
|
||||
_ProjectViewSettingsData(
|
||||
propertiesOpen: null == propertiesOpen
|
||||
@@ -777,6 +829,10 @@ class __$ProjectViewSettingsDataCopyWithImpl<$Res>
|
||||
? _self.timelineHeight
|
||||
: timelineHeight // ignore: cast_nullable_to_non_nullable
|
||||
as double?,
|
||||
mediaWidth: freezed == mediaWidth
|
||||
? _self.mediaWidth
|
||||
: mediaWidth // ignore: cast_nullable_to_non_nullable
|
||||
as double?,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -95,6 +95,8 @@ final class TimelineViewStateBinding {
|
||||
session,
|
||||
repository,
|
||||
);
|
||||
binding._savedViews.addAll(saved.sequences);
|
||||
binding._savedActiveSequenceId = saved.activeSequenceId;
|
||||
for (final sequenceId in sequenceIds) {
|
||||
final controller = session.view(sequenceId);
|
||||
void listener() => binding._schedule(sequenceId);
|
||||
@@ -133,6 +135,8 @@ final class TimelineViewStateBinding {
|
||||
final EditorTimelineSession session;
|
||||
final TimelineViewSettingsRepository repository;
|
||||
final Map<SequenceId, void Function()> _listeners = {};
|
||||
final Map<SequenceId, TimelineSequenceViewState> _savedViews = {};
|
||||
SequenceId? _savedActiveSequenceId;
|
||||
SequenceId? _activeSequenceId;
|
||||
Timer? _timer;
|
||||
Future<void> _tail = Future.value();
|
||||
@@ -162,21 +166,36 @@ final class TimelineViewStateBinding {
|
||||
|
||||
Future<void> _save(SequenceId sequenceId) async {
|
||||
final controller = session.view(sequenceId);
|
||||
final value = TimelineSequenceViewState(
|
||||
playheadTick: controller.playheadTick,
|
||||
camera: controller.camera,
|
||||
);
|
||||
// Selection notifications and closing can repeat the last persisted view.
|
||||
// A sequence switch must still update the repository's active sequence.
|
||||
if (_savedActiveSequenceId == sequenceId &&
|
||||
_sameView(_savedViews[sequenceId], value)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await repository.save(
|
||||
projectId,
|
||||
timelineId,
|
||||
sequenceId,
|
||||
TimelineSequenceViewState(
|
||||
playheadTick: controller.playheadTick,
|
||||
camera: controller.camera,
|
||||
),
|
||||
);
|
||||
await repository.save(projectId, timelineId, sequenceId, value);
|
||||
_savedViews[sequenceId] = value;
|
||||
_savedActiveSequenceId = sequenceId;
|
||||
} catch (_) {
|
||||
// View state must never block editing or project persistence.
|
||||
}
|
||||
}
|
||||
|
||||
static bool _sameView(
|
||||
TimelineSequenceViewState? saved,
|
||||
TimelineSequenceViewState next,
|
||||
) =>
|
||||
saved != null &&
|
||||
saved.playheadTick == next.playheadTick &&
|
||||
saved.camera.baseTick == next.camera.baseTick &&
|
||||
saved.camera.fractionalTick == next.camera.fractionalTick &&
|
||||
saved.camera.pixelsPerTick == next.camera.pixelsPerTick &&
|
||||
saved.camera.verticalOffset == next.camera.verticalOffset;
|
||||
|
||||
Future<void> close() async {
|
||||
if (_closed) return;
|
||||
_closed = true;
|
||||
|
||||
@@ -12,11 +12,21 @@ part 'view_settings.g.dart';
|
||||
@Riverpod(keepAlive: true)
|
||||
class WorkspaceViewSettings extends _$WorkspaceViewSettings {
|
||||
final _writes = SettingsWriteQueue();
|
||||
WorkspaceViewSettingsRepository? _savedRepository;
|
||||
WorkspaceViewSettingsData? _savedValue;
|
||||
|
||||
@override
|
||||
Future<WorkspaceViewSettingsData> build() async {
|
||||
_savedRepository = null;
|
||||
_savedValue = null;
|
||||
final repository = ref.watch(workspaceViewSettingsRepositoryProvider);
|
||||
try {
|
||||
return await ref.watch(workspaceViewSettingsRepositoryProvider).load();
|
||||
final value = await repository.load();
|
||||
if (value.hasSavedState) {
|
||||
_savedRepository = repository;
|
||||
_savedValue = value;
|
||||
}
|
||||
return value;
|
||||
} catch (error, stackTrace) {
|
||||
AppDiagnostics.failure(
|
||||
'settings',
|
||||
@@ -43,7 +53,14 @@ class WorkspaceViewSettings extends _$WorkspaceViewSettings {
|
||||
final value = state.requireValue.copyWith(activeProjectId: activeProjectId);
|
||||
state = AsyncData(value);
|
||||
final repository = ref.read(workspaceViewSettingsRepositoryProvider);
|
||||
return _writes.run(() => repository.save(value));
|
||||
return _writes.run(() async {
|
||||
if (identical(repository, _savedRepository) && value == _savedValue) {
|
||||
return;
|
||||
}
|
||||
await repository.save(value);
|
||||
_savedRepository = repository;
|
||||
_savedValue = value;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,13 +68,19 @@ class WorkspaceViewSettings extends _$WorkspaceViewSettings {
|
||||
@Riverpod(keepAlive: true)
|
||||
class ProjectViewSettings extends _$ProjectViewSettings {
|
||||
final _writes = SettingsWriteQueue();
|
||||
ProjectViewSettingsRepository? _savedRepository;
|
||||
ProjectViewSettingsData? _savedValue;
|
||||
|
||||
@override
|
||||
Future<ProjectViewSettingsData> build(String projectId) async {
|
||||
_savedRepository = null;
|
||||
_savedValue = null;
|
||||
final repository = ref.watch(projectViewSettingsRepositoryProvider);
|
||||
try {
|
||||
return await ref
|
||||
.watch(projectViewSettingsRepositoryProvider)
|
||||
.load(projectId);
|
||||
final value = await repository.load(projectId);
|
||||
_savedRepository = repository;
|
||||
_savedValue = value;
|
||||
return value;
|
||||
} catch (error, stackTrace) {
|
||||
AppDiagnostics.failure('settings', 'loadProjectView', error, stackTrace);
|
||||
return const ProjectViewSettingsData();
|
||||
@@ -70,9 +93,19 @@ class ProjectViewSettings extends _$ProjectViewSettings {
|
||||
void setTimelineHeight(double? height) =>
|
||||
state = AsyncData(state.requireValue.copyWith(timelineHeight: height));
|
||||
|
||||
void setMediaWidth(double? width) =>
|
||||
state = AsyncData(state.requireValue.copyWith(mediaWidth: width));
|
||||
|
||||
Future<void> save() {
|
||||
final value = state.requireValue;
|
||||
final repository = ref.read(projectViewSettingsRepositoryProvider);
|
||||
return _writes.run(() => repository.save(projectId, value));
|
||||
return _writes.run(() async {
|
||||
if (identical(repository, _savedRepository) && value == _savedValue) {
|
||||
return;
|
||||
}
|
||||
await repository.save(projectId, value);
|
||||
_savedRepository = repository;
|
||||
_savedValue = value;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,7 @@ final class WorkspaceViewSettingsProvider
|
||||
}
|
||||
|
||||
String _$workspaceViewSettingsHash() =>
|
||||
r'35836b74a1bbd2718e9a381d5623255ff507c63a';
|
||||
r'4b333ecfae5603a101b76117b44e008b389d0f27';
|
||||
|
||||
/// Persistent navigation preferences, shared by the application surface.
|
||||
|
||||
@@ -119,7 +119,7 @@ final class ProjectViewSettingsProvider
|
||||
}
|
||||
|
||||
String _$projectViewSettingsHash() =>
|
||||
r'c036088de9f39789b8604c48000a63a52517c966';
|
||||
r'e072707714bf53ba058f10482397572f50dfb75a';
|
||||
|
||||
/// Project preferences survive timeline switches and widget reconstruction.
|
||||
|
||||
|
||||
Reference in new issue
Block a user