Skip to content

Commit

Permalink
[fixes] MacOS Builds (#261)
Browse files Browse the repository at this point in the history
* fix: various issues preventing macos from building / working as expected after 0.1.8

* refactor: removing debugging code
  • Loading branch information
ereio authored Jun 5, 2021
1 parent 1c64303 commit 0aaf740
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 42 deletions.
2 changes: 0 additions & 2 deletions lib/cache/index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import 'package:sqflite_common_ffi/sqflite_ffi.dart' as sqflite_ffi;

class Cache {
// encryption references (in memory only)
static String? ivKey;
static String? ivKeyNext;
static String? cryptKey;

// hot cache refrences
Expand Down
6 changes: 0 additions & 6 deletions lib/global/algos.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ List<int> fibonacci(int n) {
return series;
}

void printJson(Map? jsonMap) {
final JsonEncoder encoder = JsonEncoder.withIndent(' ');
final String prettyEvent = encoder.convert(jsonMap);
debugPrint(prettyEvent, wrapWidth: 2048);
}

// time functions by wrapping them here - needs testing
Future timeWrapper(
Future<dynamic> Function() function, {
Expand Down
2 changes: 0 additions & 2 deletions lib/global/libs/matrix/encryption.dart
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,6 @@ abstract class Encryption {
},
};

printJson(payload);

return MatrixApi.sendEventToDevice(
protocol: protocol,
homeserver: homeserver,
Expand Down
7 changes: 6 additions & 1 deletion lib/global/platform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Future<void> initPlatformDependencies() async {
printDebug = (String message, {String? title}) {};
printInfo = (String message, {String? title}) {};
printError = (String message, {String? title}) {};
printJson = (Map? json) {};
}

// init platform overrides for compatability with dart libs
Expand Down Expand Up @@ -60,7 +61,11 @@ Future<void> initPlatformDependencies() async {
if (Platform.isMacOS) {
final directory = await getApplicationSupportDirectory();
printInfo('[macos] ${directory.path}');
// DynamicLibrary.open('libolm.dylib');
try {
DynamicLibrary.open('libolm.3.dylib');
} catch (error) {
print('[macos] ${error.toString()}');
}
}

// init background sync for Android only
Expand Down
10 changes: 10 additions & 0 deletions lib/global/print.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import 'dart:convert';

import 'package:flutter/material.dart';

typedef PrintJson = void Function(Map? jsonMap);
typedef PrintDebug = void Function(String message, {String title});
typedef PrintError = void Function(String message, {String? title});

Expand All @@ -23,6 +26,13 @@ void _printDebug(String content, {String? title}) {
debugPrint(body);
}

void _printJson(Map? jsonMap) {
final JsonEncoder encoder = JsonEncoder.withIndent(' ');
final String prettyEvent = encoder.convert(jsonMap);
debugPrint(prettyEvent, wrapWidth: 2048);
}

PrintJson printJson = _printJson;
PrintDebug printInfo = _printInfo;
PrintDebug printDebug = _printDebug;
PrintError printError = _printError;
Expand Down
9 changes: 8 additions & 1 deletion lib/storage/index.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:async';
import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:sembast/sembast.dart';
import 'package:sembast_sqflite/sembast_sqflite.dart';
Expand Down Expand Up @@ -31,14 +32,18 @@ class Storage {
static Map<String, dynamic> storageData = {};

// storage identifiers
static const mainLocation = '${Values.appNameLabel}-main-storage.db';
static const mainLocation =
'${Values.appNameLabel}-main-storage${kReleaseMode ? '' : '-debug'}.db';
}

Future<Database?> initStorage() async {
try {
DatabaseFactory? storageFactory;

var version;

if (Platform.isAndroid || Platform.isIOS) {
version = 1;
// always open cold storage as sqflite
storageFactory = getDatabaseFactorySqflite(
sqflite.databaseFactory,
Expand All @@ -47,6 +52,7 @@ Future<Database?> initStorage() async {

/// Supports Windows/Linux/MacOS for now.
if (Platform.isLinux || Platform.isWindows || Platform.isMacOS) {
version = 2;
storageFactory = getDatabaseFactorySqflite(
sqflite_ffi.databaseFactoryFfi,
);
Expand All @@ -63,6 +69,7 @@ Future<Database?> initStorage() async {
Storage.main = await storageFactory.openDatabase(
Storage.mainLocation,
codec: codec,
version: version,
);

return Storage.main;
Expand Down
11 changes: 0 additions & 11 deletions lib/store/crypto/actions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,6 @@ ThunkAction<AppState> generateIdentityKeys() {
}
};

printJson(deviceKeysPayload);

// cache current device key for authed user
final deviceKeysOwned = DeviceKey.fromMatrix(
deviceKeysPayload['device_keys'],
Expand All @@ -332,9 +330,6 @@ ThunkAction<AppState> uploadIdentityKeys({required DeviceKey deviceKey}) {
'device_keys': deviceKey.toMatrix(),
};

printDebug('[uploadIdentityKeys] start');
printJson(deviceKeyMap);

// upload the public device keys
final data = await MatrixApi.uploadKeys(
protocol: store.state.authStore.protocol,
Expand All @@ -346,9 +341,6 @@ ThunkAction<AppState> uploadIdentityKeys({required DeviceKey deviceKey}) {
if (data['errcode'] != null) {
throw data['error'];
}

printDebug('[uploadIdentityKeys] finish');
printJson(data);
} catch (error) {
store.dispatch(addAlert(
error: error,
Expand Down Expand Up @@ -571,9 +563,6 @@ ThunkAction<AppState> updateKeySessions({

final randomNumber = Random.secure().nextInt(1 << 31).toString();

printDebug('[sendSessionKeys] sending $randomNumber');
printJson(payload);

final response = await MatrixApi.sendEventToDevice(
trxId: randomNumber,
protocol: store.state.authStore.protocol,
Expand Down
4 changes: 0 additions & 4 deletions lib/store/events/actions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,6 @@ ThunkAction<AppState> fetchStateEvents({Room? room}) {
roomId: room!.id,
);

printInfo("${stateEvents.runtimeType}");

printJson(stateEvents);

if (stateEvents.runtimeType != List && stateEvents['errcode'] != null) {
throw stateEvents['error'];
}
Expand Down
6 changes: 0 additions & 6 deletions lib/store/sync/background/service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,6 @@ Future backgroundSyncLoop({
}
}

printJson(roomNames);

// Make sure the room name exists in the cache
if (!roomNames.containsKey(roomId) ||
roomNames[roomId] == Values.EMPTY_CHAT) {
Expand All @@ -280,7 +278,6 @@ Future backgroundSyncLoop({

roomNames[room.id] = roomName;

printJson(roomNames);
saveRoomNames(roomNames: roomNames);
} catch (error) {
print(
Expand Down Expand Up @@ -349,9 +346,6 @@ Future backgroundSyncLoop({

if (body.isEmpty) return Future.value();

print(message.id);
printJson(uncheckedMessages);

await showMessageNotification(
id: uncheckedMessages.isEmpty ? 0 : null,
body: body,
Expand Down
29 changes: 23 additions & 6 deletions macos/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@
33CC10F32044A3C60003C045 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 33CC10F22044A3C60003C045 /* Assets.xcassets */; };
33CC10F62044A3C60003C045 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 33CC10F42044A3C60003C045 /* MainMenu.xib */; };
33CC11132044BFA00003C045 /* MainFlutterWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33CC11122044BFA00003C045 /* MainFlutterWindow.swift */; };
D2743EC32651BBF5006FDB28 /* libolm.3.2.2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = D2743EC22651BBF5006FDB28 /* libolm.3.2.2.dylib */; };
D23E4F2126694FFA0064E72D /* libolm.3.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = D23E4F2026694FFA0064E72D /* libolm.3.dylib */; settings = {ATTRIBUTES = (Weak, ); }; };
D23E4F22266950D20064E72D /* libolm.3.dylib in Embed Libraries */ = {isa = PBXBuildFile; fileRef = D23E4F2026694FFA0064E72D /* libolm.3.dylib */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
D23E4F24266950D30064E72D /* libolm.3.2.2.dylib in Embed Libraries */ = {isa = PBXBuildFile; fileRef = D2743EC22651BBF5006FDB28 /* libolm.3.2.2.dylib */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
D23E4F252669521D0064E72D /* libolm.3.dylib in Resources */ = {isa = PBXBuildFile; fileRef = D23E4F2026694FFA0064E72D /* libolm.3.dylib */; };
D23E4F262669521F0064E72D /* libolm.3.2.2.dylib in Resources */ = {isa = PBXBuildFile; fileRef = D2743EC22651BBF5006FDB28 /* libolm.3.2.2.dylib */; };
D2743EC32651BBF5006FDB28 /* libolm.3.2.2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = D2743EC22651BBF5006FDB28 /* libolm.3.2.2.dylib */; settings = {ATTRIBUTES = (Weak, ); }; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -41,14 +46,16 @@
/* End PBXContainerItemProxy section */

/* Begin PBXCopyFilesBuildPhase section */
33CC110E2044A8840003C045 /* Bundle Framework */ = {
D23E4F23266950D20064E72D /* Embed Libraries */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
D23E4F24266950D30064E72D /* libolm.3.2.2.dylib in Embed Libraries */,
D23E4F22266950D20064E72D /* libolm.3.dylib in Embed Libraries */,
);
name = "Bundle Framework";
name = "Embed Libraries";
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */
Expand All @@ -73,6 +80,7 @@
9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Debug.xcconfig; sourceTree = "<group>"; };
B9D833B3E037FA761D00EF30 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = "<group>"; };
C1CD66FF4A25F1396737BF9C /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; };
D23E4F2026694FFA0064E72D /* libolm.3.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; path = libolm.3.dylib; sourceTree = "<group>"; };
D2743EC22651BBF5006FDB28 /* libolm.3.2.2.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; path = libolm.3.2.2.dylib; sourceTree = "<group>"; };
FE87411DC33C73CF1781CD2F /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand All @@ -82,6 +90,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
D23E4F2126694FFA0064E72D /* libolm.3.dylib in Frameworks */,
D2743EC32651BBF5006FDB28 /* libolm.3.2.2.dylib in Frameworks */,
26725682E95C9D306B1B4506 /* Pods_Runner.framework in Frameworks */,
);
Expand Down Expand Up @@ -168,6 +177,7 @@
D73912EC22F37F3D000D13A0 /* Frameworks */ = {
isa = PBXGroup;
children = (
D23E4F2026694FFA0064E72D /* libolm.3.dylib */,
D2743EC22651BBF5006FDB28 /* libolm.3.2.2.dylib */,
C1CD66FF4A25F1396737BF9C /* Pods_Runner.framework */,
);
Expand All @@ -185,9 +195,9 @@
33CC10E92044A3C60003C045 /* Sources */,
33CC10EA2044A3C60003C045 /* Frameworks */,
33CC10EB2044A3C60003C045 /* Resources */,
33CC110E2044A8840003C045 /* Bundle Framework */,
3399D490228B24CF009A79C7 /* ShellScript */,
1099EB9383B9AF0DE0476B42 /* [CP] Embed Pods Frameworks */,
D23E4F23266950D20064E72D /* Embed Libraries */,
);
buildRules = (
);
Expand All @@ -212,7 +222,6 @@
33CC10EC2044A3C60003C045 = {
CreatedOnToolsVersion = 9.2;
LastSwiftMigration = 0920;
ProvisioningStyle = Automatic;
SystemCapabilities = {
com.apple.Sandbox = {
enabled = 1;
Expand Down Expand Up @@ -251,6 +260,8 @@
files = (
33CC10F32044A3C60003C045 /* Assets.xcassets in Resources */,
33CC10F62044A3C60003C045 /* MainMenu.xib in Resources */,
D23E4F252669521D0064E72D /* libolm.3.dylib in Resources */,
D23E4F262669521F0064E72D /* libolm.3.2.2.dylib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -435,8 +446,10 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/DebugProfile.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
DEVELOPMENT_TEAM = W98LUTKH5G;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Flutter/ephemeral",
Expand Down Expand Up @@ -571,8 +584,10 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/DebugProfile.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
DEVELOPMENT_TEAM = W98LUTKH5G;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Flutter/ephemeral",
Expand Down Expand Up @@ -601,8 +616,10 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Runner/Release.entitlements;
CODE_SIGN_STYLE = Automatic;
CODE_SIGN_IDENTITY = "3rd Party Mac Developer Application";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
DEVELOPMENT_TEAM = W98LUTKH5G;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Flutter/ephemeral",
Expand Down
2 changes: 2 additions & 0 deletions macos/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
<string>$(FLUTTER_BUILD_NAME)</string>
<key>CFBundleVersion</key>
<string>$(FLUTTER_BUILD_NUMBER)</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.social-networking</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>NSHumanReadableCopyright</key>
Expand Down
8 changes: 5 additions & 3 deletions macos/Runner/Release.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
<key>com.apple.security.assets.movies.read-only</key>
<key>com.apple.security.assets.movies.read-only</key>
<true/>
<key>com.apple.security.assets.music.read-only</key>
<true/>
<key>com.apple.security.assets.pictures.read-only</key>
<true/>
<key>com.apple.security.device.camera</key>
<true/>
<key>com.apple.security.files.downloads.read-write</key>
<true/>
<key>com.apple.security.files.user-selected.read-only</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
</dict>
</plist>
Binary file added macos/libolm.3.dylib
Binary file not shown.

0 comments on commit 0aaf740

Please sign in to comment.