Skip to content
This repository has been archived by the owner on Jun 15, 2022. It is now read-only.

Commit

Permalink
Merge branch 'release/3.5.14'
Browse files Browse the repository at this point in the history
  • Loading branch information
radko93 committed Dec 23, 2020
2 parents 2375ffb + b8913f5 commit a506a56
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 167 deletions.
5 changes: 5 additions & 0 deletions android/app/src/main/java/com/standardnotes/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.standardnotes;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.content.res.Configuration;

Expand All @@ -25,6 +27,9 @@ public SNReactActivityDelegate(ReactActivity activity, String mainComponentName)
protected Bundle getLaunchOptions() {
String packageName = this.getContext().getPackageName();
Bundle props = new Bundle();
SharedPreferences settings = this.getContext().getSharedPreferences("react-native", Context.MODE_PRIVATE);
String bugsnagOptOut = settings.getString("bugsnagoptout", "false");
props.putBoolean("bugsnagOptOut", bugsnagOptOut.equals("true"));
if (packageName.equals("com.standardnotes.dev")) {
props.putString("env", "dev");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.facebook.react.modules.network.OkHttpClientProvider;

import android.annotation.SuppressLint;
import android.content.SharedPreferences;
import android.database.CursorWindow;
import android.os.Bundle;
import android.view.WindowManager;
Expand Down Expand Up @@ -77,7 +78,12 @@ public void onCreate() {
add(BreadcrumbType.ERROR);
}});

Bugsnag.start(this, config);
SharedPreferences settings = getApplicationContext().getSharedPreferences("react-native", Context.MODE_PRIVATE);
String bugsnagOptOut = settings.getString("bugsnagoptout", "false");

if (!bugsnagOptOut.equals("true")) {
Bugsnag.start(this, config);
}

SoLoader.init(this, /* native exopackage */ false);

Expand Down
2 changes: 0 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ if (__DEV__ === false) {
console.log = () => {};
console.warn = () => {};
console.error = () => {};
// eslint-disable-next-line no-new
new Bugsnag.start();
SNLog.onError = Bugsnag.notify;
SNLog.onLog = Bugsnag.leaveBreadcrumb;
} else {
Expand Down
6 changes: 6 additions & 0 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@ PODS:
- React-Core
- RNCMaskedView (0.1.10):
- React
- RNDefaultPreference (1.4.3):
- React
- RNFileViewer (2.1.4):
- React-Core
- RNFS (2.16.6):
Expand Down Expand Up @@ -408,6 +410,7 @@ DEPENDENCIES:
- ReactNativeAlternateIcons (from `../node_modules/react-native-alternate-icons`)
- "RNCAsyncStorage (from `../node_modules/@react-native-community/async-storage`)"
- "RNCMaskedView (from `../node_modules/@react-native-community/masked-view`)"
- RNDefaultPreference (from `../node_modules/react-native-default-preference`)
- RNFileViewer (from `../node_modules/react-native-file-viewer`)
- RNFS (from `../node_modules/react-native-fs`)
- RNGestureHandler (from `../node_modules/react-native-gesture-handler`)
Expand Down Expand Up @@ -514,6 +517,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/@react-native-community/async-storage"
RNCMaskedView:
:path: "../node_modules/@react-native-community/masked-view"
RNDefaultPreference:
:path: "../node_modules/react-native-default-preference"
RNFileViewer:
:path: "../node_modules/react-native-file-viewer"
RNFS:
Expand Down Expand Up @@ -590,6 +595,7 @@ SPEC CHECKSUMS:
ReactNativeAlternateIcons: b2a8a729d9d9756ed0652c352694f190407f297f
RNCAsyncStorage: b03032fdbdb725bea0bd9e5ec5a7272865ae7398
RNCMaskedView: 5a8ec07677aa885546a0d98da336457e2bea557f
RNDefaultPreference: 2f8d6d54230edbd78708ada8d63bb275e5a8415b
RNFileViewer: 83cc066ad795b1f986791d03b56fe0ee14b6a69f
RNFS: 2bd9eb49dc82fa9676382f0585b992c424cd59df
RNGestureHandler: 9b7e605a741412e20e13c512738a31bd1611759b
Expand Down
11 changes: 8 additions & 3 deletions ios/StandardNotes/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,17 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
#ifdef FB_SONARKIT_ENABLED
InitializeFlipper(application);
#endif

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *bugsnagOptOut = [defaults objectForKey:@"bugsnagoptout"];

BugsnagConfiguration *config = [BugsnagConfiguration loadConfig];
config.enabledBreadcrumbTypes = BSGEnabledBreadcrumbTypeNavigation | BSGEnabledBreadcrumbTypeLog
| BSGEnabledBreadcrumbTypeUser | BSGEnabledBreadcrumbTypeState | BSGEnabledBreadcrumbTypeNavigation | BSGEnabledBreadcrumbTypeProcess;

[Bugsnag startWithConfiguration:config];

if (![bugsnagOptOut isEqualToString:@"true"]) {
[Bugsnag startWithConfiguration:config];
}

[self configurePinning];

Expand All @@ -47,7 +52,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(

NSString *CFBundleIdentifier = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"];

NSDictionary * initialProperties = @{@"env" : [CFBundleIdentifier isEqualToString:@"com.standardnotes.standardnotes.dev"] ? @"dev" : @"prod"};
NSDictionary * initialProperties = @{@"env" : [CFBundleIdentifier isEqualToString:@"com.standardnotes.standardnotes.dev"] ? @"dev" : @"prod", @"bugsnagOptOut": [bugsnagOptOut isEqualToString:@"true"] ? @YES : @NO};

RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
Expand Down
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "StandardNotes",
"version": "3.5.13",
"user-version": "3.5.13",
"version": "3.5.14",
"user-version": "3.5.14",
"private": true,
"license": "AGPL-3.0-or-later",
"scripts": {
Expand All @@ -25,12 +25,15 @@
"@react-native-community/segmented-control": "^2.2.2",
"@react-navigation/native": "^5.8.10",
"@react-navigation/stack": "^5.12.8",
"@standardnotes/sncrypto-common": "1.2.9",
"@standardnotes/snjs": "2.0.27",
"js-base64": "^3.5.2",
"moment": "^2.29.1",
"react": "16.13.1",
"react-native": "0.63.4",
"react-native-aes-crypto": "standardnotes/react-native-aes#6430299",
"react-native-alternate-icons": "standardnotes/react-native-alternate-icons#1d335d",
"react-native-default-preference": "^1.4.3",
"react-native-fab": "standardnotes/react-native-fab#cb60e00",
"react-native-file-viewer": "^2.1.4",
"react-native-fingerprint-scanner": "standardnotes/react-native-fingerprint-scanner#8f3b2df05d88350f1f704417c8b90981cec87301",
Expand All @@ -52,9 +55,7 @@
"react-native-version-info": "^1.1.0",
"react-native-webview": "^10.10.2",
"react-navigation-header-buttons": "^6.0.0",
"sn-textview": "standardnotes/sn-textview#440dbd60eedef4397b6272735e68d4579bb41ac8",
"@standardnotes/sncrypto-common": "1.2.9",
"@standardnotes/snjs": "2.0.27",
"sn-textview": "standardnotes/sn-textview#f140ea8de28ac3a75eb5a3a6a521b637ef78d207",
"standard-notes-rn": "standardnotes/standard-notes-rn#996b016",
"styled-components": "^5.2.1"
},
Expand Down
14 changes: 13 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Bugsnag from '@bugsnag/react-native';
import { ActionSheetProvider } from '@expo/react-native-action-sheet';
import { MobileApplication } from '@Lib/application';
import { ApplicationGroup } from '@Lib/application_group';
Expand Down Expand Up @@ -125,11 +126,22 @@ const AppComponent: React.FC<{
const AppGroupInstance = new ApplicationGroup();
AppGroupInstance.initialize();

export const App = (props: { env: 'prod' | 'dev' }) => {
export const App = (props: { env: 'prod' | 'dev'; bugsnagOptOut: boolean }) => {
const applicationGroupRef = useRef(AppGroupInstance);
const [application, setApplication] = useState<
MobileApplication | undefined
>();

useEffect(() => {
if (!__DEV__ && !props.bugsnagOptOut) {
try {
Bugsnag.start();
} catch {
console.error('Bugnsag failed to start');
}
}
}, [props.bugsnagOptOut]);

useEffect(() => {
const removeAppChangeObserver = applicationGroupRef.current.addApplicationChangeObserver(
() => {
Expand Down
18 changes: 18 additions & 0 deletions src/lib/interface.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import AsyncStorage from '@react-native-community/async-storage';
import { ApplicationIdentifier, DeviceInterface } from '@standardnotes/snjs';
import { Alert, Linking, Platform } from 'react-native';
import DefaultPreference from 'react-native-default-preference';
import FingerprintScanner from 'react-native-fingerprint-scanner';
import Keychain from './keychain';

Expand All @@ -10,6 +11,11 @@ export type BiometricsType =
| 'Biometrics'
| 'Touch ID';

/**
* This key is used for getting bugsnag preference from native side
*/
const BUGSNAG_OPT_OUT_KEY = 'bugsnagoptout';

/**
* This identifier was the database name used in Standard Notes web/desktop.
*/
Expand Down Expand Up @@ -280,4 +286,16 @@ export class MobileDeviceInterface extends DeviceInterface {
})
.catch(() => showAlert());
}

async getBugsnagOptedOut() {
try {
return (await DefaultPreference.get(BUGSNAG_OPT_OUT_KEY)) === 'true';
} catch {
return false;
}
}

setBusgnagOptedOut(optedOut: true | false) {
return DefaultPreference.set(BUGSNAG_OPT_OUT_KEY, optedOut.toString());
}
}
43 changes: 42 additions & 1 deletion src/screens/Settings/Sections/CompanySection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { ButtonCell } from '@Components/ButtonCell';
import { SectionHeader } from '@Components/SectionHeader';
import { TableSection } from '@Components/TableSection';
import { ApplicationState } from '@Lib/application_state';
import { MobileDeviceInterface } from '@Lib/interface';
import { ApplicationContext } from '@Root/ApplicationContext';
import React, { useContext } from 'react';
import React, { useCallback, useContext, useEffect, useState } from 'react';
import { Platform, Share } from 'react-native';
import { ContentContainer, Label } from './CompanySection.styled';

Expand All @@ -27,12 +28,38 @@ type Props = {

export const CompanySection = (props: Props) => {
const application = useContext(ApplicationContext);
const [bugsnagOptOut, setBugsnagOptOut] = useState(false);
const storeName = Platform.OS === 'android' ? 'Play Store' : 'App Store';

const openUrl = (action: keyof typeof URLS) => {
application?.deviceInterface!.openUrl(URLS[action]);
};

useEffect(() => {
const getOptedOut = async () => {
const optedOut = await (application?.deviceInterface as MobileDeviceInterface).getBugsnagOptedOut();
setBugsnagOptOut(optedOut);
};
getOptedOut();
}, [application?.deviceInterface]);

const toggleBugnsagOptOut = useCallback(
async (optOut: boolean) => {
try {
await (application?.deviceInterface as MobileDeviceInterface).setBusgnagOptedOut(
optOut
);
setBugsnagOptOut(optOut);
application?.alertService.alert(
'Please restart the app to fully apply the requested changes.'
);
} catch {
application?.alertService.alert('An error occured. Please try again.');
}
},
[application?.alertService, application?.deviceInterface]
);

const shareEncryption = () => {
const title = 'The Unexpected Benefits of Encrypted Writing';
let message = Platform.OS === 'ios' ? title : '';
Expand Down Expand Up @@ -114,6 +141,20 @@ export const CompanySection = (props: Props) => {
<Label>https://standardnotes.org/privacy</Label>
</ButtonCell>

<ButtonCell
leftAligned={true}
title={
bugsnagOptOut ? 'Enable Error Reporting' : 'Disable Error Reporting'
}
onPress={() => toggleBugnsagOptOut(!bugsnagOptOut)}
>
<Label>
{
'Help us improve Standard Notes by automatically submitting anonymized error reports.'
}
</Label>
</ButtonCell>

<ButtonCell
leftAligned={true}
title="Rate Standard Notes"
Expand Down
Loading

0 comments on commit a506a56

Please sign in to comment.