Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/owner #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ app.*.map.json

# Exceptions to above rules.
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
peervault
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
run:
flutter run

release:
rm -rf /Applicationsbuild/macos/Build/Products/Release/
flutter build macos --release
cp peervault build/macos/Build/Products/Release/Peervault.app/Contents/MacOS/io.plab.peervault
codesign --deep --force --verbose --sign "6474BEC494BACEB22D23B3656F45F5BD7337552F" build/macos/Build/Products/Release/Peervault.app

install:
cp -r build/macos/Build/Products/Release/Peervault.app /Applications/
39 changes: 30 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,37 @@
# peervault
# Peervault - Client

A new Flutter project.

## Getting Started
## Release instruction

This project is a starting point for a Flutter application.
### Build for MacOs

A few resources to get you started if this is your first Flutter project:
1. build macos

- [Lab: Write your first Flutter app](https://flutter.dev/docs/get-started/codelab)
- [Cookbook: Useful Flutter samples](https://flutter.dev/docs/cookbook)
```
flutter build macos --releas
```

For help getting started with Flutter, view our
[online documentation](https://flutter.dev/docs), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
2. Sign with certificate from XCode
2.1 Get a certificate from Xcode. The simplest step is to use Xcode, add a new certificate.
Read more about it here https://help.apple.com/xcode/mac/current/#/dev154b28f09

2.2 Once you have the certificate you need to find the identity for it to sign your app.
```
security find-identity -p codesigning
```
run this in terminal and copy hash it gives you against the certificate name you just created.

2.3
```
codesign --deep --force --verbose --sign "<identity>" build/macos
```

2.4
Verify the signature codesign --verify -vvvv Application.app and spctl -a -vvvv Application.app

## Dev followup

- Structure directory for core service class
- Splash loader for daemon loading and API check if owner exists
- State with default settings (api url, ws url, p2p relay)
Binary file modified assets/logo-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions ios/Flutter/Debug.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Generated.xcconfig"
1 change: 1 addition & 0 deletions ios/Flutter/Release.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Generated.xcconfig"
87 changes: 87 additions & 0 deletions ios/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
'Debug' => :debug,
'Profile' => :release,
'Release' => :release,
}

def parse_KV_file(file, separator='=')
file_abs_path = File.expand_path(file)
if !File.exists? file_abs_path
return [];
end
generated_key_values = {}
skip_line_start_symbols = ["#", "/"]
File.foreach(file_abs_path) do |line|
next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ }
plugin = line.split(pattern=separator)
if plugin.length == 2
podname = plugin[0].strip()
path = plugin[1].strip()
podpath = File.expand_path("#{path}", file_abs_path)
generated_key_values[podname] = podpath
else
puts "Invalid plugin specification: #{line}"
end
end
generated_key_values
end

target 'Runner' do
use_frameworks!
use_modular_headers!

# Flutter Pod

copied_flutter_dir = File.join(__dir__, 'Flutter')
copied_framework_path = File.join(copied_flutter_dir, 'Flutter.framework')
copied_podspec_path = File.join(copied_flutter_dir, 'Flutter.podspec')
unless File.exist?(copied_framework_path) && File.exist?(copied_podspec_path)
# Copy Flutter.framework and Flutter.podspec to Flutter/ to have something to link against if the xcode backend script has not run yet.
# That script will copy the correct debug/profile/release version of the framework based on the currently selected Xcode configuration.
# CocoaPods will not embed the framework on pod install (before any build phases can generate) if the dylib does not exist.

generated_xcode_build_settings_path = File.join(copied_flutter_dir, 'Generated.xcconfig')
unless File.exist?(generated_xcode_build_settings_path)
raise "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter pub get is executed first"
end
generated_xcode_build_settings = parse_KV_file(generated_xcode_build_settings_path)
cached_framework_dir = generated_xcode_build_settings['FLUTTER_FRAMEWORK_DIR'];

unless File.exist?(copied_framework_path)
FileUtils.cp_r(File.join(cached_framework_dir, 'Flutter.framework'), copied_flutter_dir)
end
unless File.exist?(copied_podspec_path)
FileUtils.cp(File.join(cached_framework_dir, 'Flutter.podspec'), copied_flutter_dir)
end
end

# Keep pod path relative so it can be checked into Podfile.lock.
pod 'Flutter', :path => 'Flutter'

# Plugin Pods

# Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
# referring to absolute paths on developers' machines.
system('rm -rf .symlinks')
system('mkdir -p .symlinks/plugins')
plugin_pods = parse_KV_file('../.flutter-plugins')
plugin_pods.each do |name, path|
symlink = File.join('.symlinks', 'plugins', name)
File.symlink(path, symlink)
pod name, :path => File.join(symlink, 'ios')
end
end

post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['ENABLE_BITCODE'] = 'NO'
end
end
end
37 changes: 33 additions & 4 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,38 @@
import 'package:flutter/material.dart';
import 'package:peervault/ui/owner/display_seed.dart';
import 'package:window_utils/window_utils.dart';
import 'package:window_utils/window_frame.dart';

import 'package:peervault/ui/splash.dart';
import 'package:peervault/ui/home.dart';
import 'package:peervault/ui/owner/create_owner.dart';
import 'package:peervault/ui/unlock.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
class MyApp extends StatefulWidget {
const MyApp({Key key}) : super(key: key);

@override
PeerVaultApp createState() => new PeerVaultApp();
}

class PeerVaultApp extends State<MyApp> {
@override
void initState() {
WidgetsBinding.instance.addPostFrameCallback(
(_) {
WindowUtils.setSize(new Size(900, 640));
WindowUtils.centerWindow();
},
);
super.initState();
}

@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
debugShowCheckedModeBanner: true,
theme: ThemeData(
scaffoldBackgroundColor: Color(0xFF191919),
primarySwatch: MaterialColor(
Expand All @@ -28,12 +51,18 @@ class MyApp extends StatelessWidget {
}
),
accentColor: Color(0xFF82E1B3),
unselectedWidgetColor: Colors.white,
),
initialRoute: '/createOwner',
initialRoute: '/splash',
routes: {
'/': (context) => Home(),
'/splash': (context) => WindowsFrame(
active: true,
child: Splash()
),
'/home': (context) => Home(),
'/unlock': (context) => Unlock(),
'/createOwner': (context) => CreateOwner(),
'/owner/display_seed': (context) => DisplaySeed(),
},
);
}
Expand Down
44 changes: 44 additions & 0 deletions lib/model/owner.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
class Owner {
// ignore: non_constant_identifier_names
final String QmPeerId;
// ignore: non_constant_identifier_names
final String Nickname;
// ignore: non_constant_identifier_names
final String DeviceName;
// ignore: non_constant_identifier_names
final String UnlockCode;
// ignore: non_constant_identifier_names
final int AskPassword;

Owner({
// ignore: non_constant_identifier_names
this.QmPeerId,
// ignore: non_constant_identifier_names
this.Nickname,
// ignore: non_constant_identifier_names
this.DeviceName,
// ignore: non_constant_identifier_names
this.UnlockCode,
// ignore: non_constant_identifier_names
this.AskPassword
});

factory Owner.fromJson(Map<String, dynamic> json) {
return Owner(
QmPeerId: json['QmPeerId'],
Nickname: json['Nickname'],
DeviceName: json['DeviceName'],
UnlockCode: json['UnlockCode'],
AskPassword: json['AskPassword'],
);
}

Map<String, dynamic> toJson() {
return {
'Nickname': Nickname,
'DeviceName': DeviceName,
'UnlockCode': UnlockCode,
'AskPassword': AskPassword,
};
}
}
35 changes: 35 additions & 0 deletions lib/service/api/owner.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import 'dart:convert';

import 'package:http/http.dart' as http;
import 'package:peervault/model/owner.dart';

Future<Owner> fetchOwner() async {
final response = await http.get('http://localhost:4444/owner');

if (response.statusCode == 200) {
return Owner.fromJson(json.decode(response.body));
}

// NO OWNER SETUP
if (response.statusCode == 424) {
return null;
}

throw Exception('Error with PeerVault Daemon');
}

Future<String> createOwner(Owner owner) async {
var response = await http.post(
'http://localhost:4444/owner',
headers: {
'Content-Type': 'application/json'
},
body: jsonEncode(owner),
);

if (response.statusCode == 200) {
return json.decode(response.body)['seed'];
}

throw Exception('Error with PeerVault Daemon');
}
Loading