Skip to content

Commit d6d60a3

Browse files
committed
Fixed factory not working. Initial stab for loading extensions via MAUI package. Need to filter the Include statements based on target conditions.
1 parent 2c678a1 commit d6d60a3

File tree

7 files changed

+81
-19
lines changed

7 files changed

+81
-19
lines changed

PowerSync/PowerSync.Common/Client/PowerSyncDatabase.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ public class DBAdapterSource(IDBAdapter Adapter) : IDatabaseSource
3535
public IDBAdapter Adapter { get; init; } = Adapter;
3636
}
3737

38-
public class OpenFactorySource(ISQLOpenFactory Factory) : IDatabaseSource
39-
{
40-
public ISQLOpenFactory Factory { get; init; } = Factory;
41-
}
42-
4338
public class PowerSyncDatabaseOptions() : BasePowerSyncDatabaseOptions()
4439
{
4540
/// <summary>
@@ -115,9 +110,9 @@ public PowerSyncDatabase(PowerSyncDatabaseOptions options)
115110
{
116111
Database = adapterSource.Adapter;
117112
}
118-
else if (options.Database is OpenFactorySource factorySource)
113+
else if (options.Database is ISQLOpenFactory factorySource)
119114
{
120-
Database = factorySource.Factory.OpenDatabase();
115+
Database = factorySource.OpenDatabase();
121116
}
122117
else if (options.Database is SQLOpenOptions openOptions)
123118
{

PowerSync/PowerSync.Common/Client/SQLOpenFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class SQLOpenOptions : IDatabaseSource
1515
public string? DbLocation { get; set; }
1616
}
1717

18-
public interface ISQLOpenFactory
18+
public interface ISQLOpenFactory: IDatabaseSource
1919
{
2020
/// <summary>
2121
/// Opens a connection adapter to a SQLite Database.

PowerSync/PowerSync.Common/MDSQLite/MDSQLiteDBOpenFactory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ public class MDSQLiteOpenFactoryOptions : SQLOpenOptions
88
public MDSQLiteOptions? SqliteOptions { get; set; }
99
}
1010

11-
public class MDSqliteDBOpenFactory : ISQLOpenFactory
11+
public class MDSQLiteDBOpenFactory : ISQLOpenFactory
1212
{
1313
private readonly MDSQLiteOpenFactoryOptions options;
1414

15-
public MDSqliteDBOpenFactory(MDSQLiteOpenFactoryOptions options)
15+
public MDSQLiteDBOpenFactory(MDSQLiteOpenFactoryOptions options)
1616
{
1717
this.options = options;
1818
}

PowerSync/PowerSync.Common/PowerSync.Common.csproj

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netstandard2.0;net6.0;net8.0;net9.0</TargetFrameworks>
4+
<TargetFrameworks>netstandard2.0;net6.0;net8.0;net9.0;net8.0-ios;net8.0-android</TargetFrameworks>
55
<LangVersion>12</LangVersion>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
@@ -28,9 +28,11 @@
2828
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
2929
<PackageReference Include="Nito.AsyncEx" Version="5.1.2" />
3030
<PackageReference Include="System.Threading.Channels" Version="8.0.0" />
31+
<!-- <PackageReference Include="Microsoft.Maui.Essentials" Version="8.0.0" />-->
32+
3133
</ItemGroup>
3234

33-
<!-- For monorepo, test if we can remove this in monorepo -->
35+
<!-- For monorepo-->
3436
<ItemGroup>
3537
<Content Include="runtimes\**\*.*">
3638
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
@@ -41,7 +43,7 @@
4143
<ItemGroup>
4244
<None Include="runtimes\**\*.*" Pack="true" PackagePath="runtimes\" />
4345
</ItemGroup>
44-
46+
4547

4648
<ItemGroup>
4749
<None Include="..\..\icon.png" Pack="true" PackagePath=""/>

PowerSync/PowerSync.Maui/PowerSync.Maui.csproj

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,34 @@
2828
<ItemGroup>
2929
<None Include="..\..\icon.png" Pack="true" PackagePath=""/>
3030
<None Include="README.md" Pack="true" PackagePath=""/>
31+
<None Update="Platforms\Android\Resources\values\colors.xml">
32+
<SubType>Designer</SubType>
33+
</None>
3134
</ItemGroup>
32-
35+
36+
<!-- For monorepo-->
37+
<ItemGroup>
38+
<Content Include="Platforms\**\*.*">
39+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
40+
</Content>
41+
</ItemGroup>
42+
43+
<!-- For releasing runtimes -->
44+
<ItemGroup>
45+
<None Include="Platforms\**\*.*" Pack="true" PackagePath="Platforms\" />
46+
</ItemGroup>
47+
48+
49+
<!-- <ItemGroup Condition="'$(TargetFramework)' == 'net8.0-ios'">-->
50+
<!-- <NativeReference Include="Platforms/iOS/NativeLibs/powersync-sqlite-core.xcframework">-->
51+
<!-- <Kind>Framework</Kind>-->
52+
<!-- <ForceLoad>true</ForceLoad> &lt;!&ndash; Required if static &ndash;&gt;-->
53+
<!-- <Frameworks>Foundation</Frameworks>-->
54+
<!-- </NativeReference>-->
55+
<!-- </ItemGroup>-->
56+
57+
<!-- <ItemGroup Condition="'$(TargetFramework)' == 'net8.0-android'">-->
58+
<!-- <AndroidNativeLibrary Include="Platforms/Android/jniLibs/**/*.so" />-->
59+
<!-- </ItemGroup>-->
60+
<!-- -->
3361
</Project>

PowerSync/PowerSync.Maui/SQLite/MAUISQLiteAdapter.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,27 @@ public MAUISQLiteAdapter(MDSQLiteAdapterOptions options) : base(options)
1616

1717
protected override void LoadExtension(SqliteConnection db)
1818
{
19+
db.EnableExtensions(true);
20+
1921
#if IOS
22+
LoadExtensionIOS(db);
23+
#elif ANDROID
24+
db.LoadExtension("libpowersync");
25+
#endif
26+
}
27+
28+
private void LoadExtensionIOS(SqliteConnection db)
29+
{
30+
#if IOS
2031
var bundlePath = Foundation.NSBundle.MainBundle.BundlePath;
2132
var filePath =
22-
Path.Combine(bundlePath, "Frameworks", "powersync-sqlite-core.framework", "powersync-sqlite-core");
33+
Path.Combine(bundlePath, "Frameworks", "powersync-sqlite-core.framework", "powersync-sqlite-core");
2334

2435
using var loadExtension = db.CreateCommand();
2536
loadExtension.CommandText = "SELECT load_extension(@path, @entryPoint)";
2637
loadExtension.Parameters.AddWithValue("@path", filePath);
2738
loadExtension.Parameters.AddWithValue("@entryPoint", "sqlite3_powersync_init");
2839
loadExtension.ExecuteNonQuery();
29-
30-
#elif ANDROID
31-
db.LoadExtension("libpowersync");
32-
#endif
40+
#endif
3341
}
3442
}

demos/TodoSQLite/TodoSQLite.csproj

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,35 @@
7070

7171
<ItemGroup>
7272
<ProjectReference Include="..\..\PowerSync\Powersync.Common\PowerSync.Common.csproj" />
73+
<ProjectReference Include="..\..\PowerSync\Powersync.Maui\PowerSync.Maui.csproj" />
7374
</ItemGroup>
7475

76+
<!-- <ItemGroup>-->
77+
<!-- <Folder Include="Platforms\iOS\NativeLibs\" />-->
78+
<!-- </ItemGroup>-->
79+
80+
<!-- <ItemGroup Condition="'$(TargetFramework)' == 'net8.0-ios'">-->
81+
<!-- <NativeReference Include="Platforms/iOS/NativeLibs/powersync-sqlite-core.xcframework">-->
82+
<!-- <Kind>Framework</Kind>-->
83+
<!-- <ForceLoad>true</ForceLoad> &lt;!&ndash; Required if static &ndash;&gt;-->
84+
<!-- <Frameworks>Foundation</Frameworks>-->
85+
<!-- </NativeReference>-->
86+
<!-- </ItemGroup>-->
87+
88+
<!-- <ItemGroup Condition="'$(TargetFramework)' == 'net8.0-android'">-->
89+
<!-- <AndroidNativeLibrary Include="Platforms/Android/jniLibs/**/*.so" />-->
90+
<!-- </ItemGroup>-->
91+
<!-- -->
92+
<!-- <ItemGroup Condition="'$(TargetFramework)' == 'net8.0-android'">-->
93+
<!-- <AndroidNativeLibrary Include="$(MSBuildThisFileDirectory)../Platforms/Android/jniLibs/**/*.so" />-->
94+
<!-- </ItemGroup>-->
95+
96+
<!-- <ItemGroup Condition="'$(TargetFramework)' == 'net8.0-ios'">-->
97+
<!-- <NativeReference Include="$(MSBuildThisFileDirectory)../Platforms/iOS/NativeLibs/powersync-sqlite-core.xcframework">-->
98+
<!-- <Kind>Framework</Kind>-->
99+
<!-- <ForceLoad>true</ForceLoad>-->
100+
<!-- <Frameworks>Foundation</Frameworks>-->
101+
<!-- </NativeReference>-->
102+
<!-- </ItemGroup>-->
103+
<!-- -->
75104
</Project>

0 commit comments

Comments
 (0)