fix auto sync

This commit is contained in:
ammarahm-ed
2020-12-10 15:26:02 +05:00
parent ab5a155901
commit 3bd2a52157
11 changed files with 52 additions and 229239 deletions

View File

@@ -1,215 +0,0 @@
// Initialize some variables before react-native code would access them
var onmessage=null, self=global;
// Cache Node's original require as __debug__.require
global.__debug__={require: require};
// Prevent leaking process.versions from debugger process to
// worker because pure React Native doesn't do that and some packages as js-md5 rely on this behavior
Object.defineProperty(process, "versions", {
value: undefined
});
// TODO: Replace by url.fileURLToPath method when Node 10 LTS become deprecated
function fileUrlToPath(url) {
if (process.platform === 'win32') {
return url.toString().replace('file:///', '');
} else {
return url.toString().replace('file://', '');
}
}
function getNativeModules() {
var NativeModules;
try {
// This approach is for old RN versions
NativeModules = global.require('NativeModules');
} catch (err) {
// ignore error and try another way for more recent RN versions
try {
var nativeModuleId;
var modules = global.__r.getModules();
var ids = Object.keys(modules);
for (var i = 0; i < ids.length; i++) {
if (modules[ids[i]].verboseName) {
var packagePath = new String(modules[ids[i]].verboseName);
if (packagePath.indexOf('react-native/Libraries/BatchedBridge/NativeModules.js') > 0) {
nativeModuleId = parseInt(ids[i], 10);
break;
}
}
}
if (nativeModuleId) {
NativeModules = global.__r(nativeModuleId);
}
}
catch (err) {
// suppress errors
}
}
return NativeModules;
}
// Originally, this was made for iOS only
var vscodeHandlers = {
'vscode_reloadApp': function () {
var NativeModules = getNativeModules();
if (NativeModules && NativeModules.DevMenu) {
NativeModules.DevMenu.reload();
}
},
'vscode_showDevMenu': function () {
var NativeModules = getNativeModules();
if (NativeModules && NativeModules.DevMenu) {
NativeModules.DevMenu.show();
}
}
};
process.on("message", function (message) {
if (message.data && vscodeHandlers[message.data.method]) {
vscodeHandlers[message.data.method]();
} else if(onmessage) {
onmessage(message);
}
});
var postMessage = function(message){
process.send(message);
};
if (!self.postMessage) {
self.postMessage = postMessage;
}
var importScripts = (function(){
var fs=require('fs'), vm=require('vm');
return function(scriptUrl){
scriptUrl = fileUrlToPath(scriptUrl);
var scriptCode = fs.readFileSync(scriptUrl, 'utf8');
// Add a 'debugger;' statement to stop code execution
// to wait for the sourcemaps to be processed by the debug adapter
vm.runInThisContext('debugger;' + scriptCode, {filename: scriptUrl});
};
})();
// Worker is ran as nodejs process, so console.trace() writes to stderr and it leads to error in native app
// To avoid this console.trace() is overridden to print stacktrace via console.log()
// Please, see Node JS implementation: https://github.com/nodejs/node/blob/master/lib/internal/console/constructor.js
console.trace = (function() {
return function() {
try {
var err = {
name: 'Trace',
message: require('util').format.apply(null, arguments)
};
// Node uses 10, but usually it's not enough for RN app trace
Error.stackTraceLimit = 30;
Error.captureStackTrace(err, console.trace);
console.log(err.stack);
} catch (e) {
console.error(e);
}
};
})();
// As worker is ran in node, it breaks broadcast-channels package approach of identifying if its ran in node:
// https://github.com/pubkey/broadcast-channel/blob/master/src/util.js#L64
// To avoid it if process.toString() is called if will return empty string instead of [object process].
var nativeObjectToString = Object.prototype.toString;
Object.prototype.toString = function() {
if (this === process) {
return '';
} else {
return nativeObjectToString.call(this);
}
};
"use strict";
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
/* global __fbBatchedBridge, self, importScripts, postMessage, onmessage: true */
/* eslint no-unused-vars: 0 */
onmessage = function () {
var visibilityState;
var showVisibilityWarning = function () {
var hasWarned = false;
return function () {
// Wait until `YellowBox` gets initialized before displaying the warning.
if (hasWarned || console.warn.toString().includes('[native code]')) {
return;
}
hasWarned = true;
console.warn('Remote debugger is in a background tab which may cause apps to ' + 'perform slowly. Fix this by foregrounding the tab (or opening it in ' + 'a separate window).');
};
}();
var messageHandlers = {
executeApplicationScript: function (message, sendReply) {
for (var key in message.inject) {
self[key] = JSON.parse(message.inject[key]);
}
var error;
try {
importScripts(message.url);
} catch (err) {
error = err.message;
}
sendReply(null
/* result */
, error);
},
setDebuggerVisibility: function (message) {
visibilityState = message.visibilityState;
}
};
return function (message) {
if (visibilityState === 'hidden') {
showVisibilityWarning();
}
var object = message.data;
var sendReply = function (result, error) {
postMessage({
replyID: object.id,
result: result,
error: error
});
};
var handler = messageHandlers[object.method];
if (handler) {
// Special cased handlers
handler(object, sendReply);
} else {
// Other methods get called on the bridge
var returnValue = [[], [], [], 0];
var error;
try {
if (typeof __fbBatchedBridge === 'object') {
returnValue = __fbBatchedBridge[object.method].apply(null, object.arguments);
} else {
error = 'Failed to call function, __fbBatchedBridge is undefined';
}
} catch (err) {
error = err.message;
} finally {
sendReply(JSON.stringify(returnValue), error);
}
}
};
}();
//# sourceMappingURL=debuggerWorker.js.map
// Notify debugger that we're done with loading
// and started listening for IPC messages
postMessage({workerLoaded:true});

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -127,7 +127,10 @@ const App = () => {
[intent, setIntent] = useState(false);
const syncChanges = async () => {
console.log('dispatching sync changes')
dispatch({type: Actions.LOADING,loading:true});
dispatch({type: Actions.ALL});
dispatch({type: Actions.LOADING,loading:false});
};
const startSyncer = async () => {
try {
@@ -153,7 +156,6 @@ const App = () => {
console.log(url);
_data = await ReceiveSharingIntent.getFileNames(url);
_data = IntentService.iosSortedData(_data);
console.log('DONE', 'DATA GETTING');
}
if (_data) {
IntentService.setIntent(_data);
@@ -224,7 +226,6 @@ const App = () => {
if (Platform.OS === 'ios') {
RNIap.getReceiptIOS()
.then((r) => {
console.log(r);
hasPurchased = true;
processReceipt(r);
})
@@ -247,6 +248,16 @@ const App = () => {
}
};
const dbSync = async () => {
try {
dispatch({type: Actions.SYNCING, syncing: true});
await db.sync(false);
} catch (e) {
} finally {
dispatch({type: Actions.SYNCING, syncing: false});
}
};
useEffect(() => {
eSubscribeEvent(eStartSyncer, startSyncer);
eSubscribeEvent(eDispatchAction, (type) => {
@@ -262,9 +273,12 @@ const App = () => {
if (Platform.OS === 'ios') {
Linking.addEventListener('url', _handleIntent);
}
EV.subscribe('db:sync', dbSync);
EV.subscribe('user:checkStatus', handlePremiumAccess);
return () => {
EV.unsubscribe('db:refresh', syncChanges);
EV.unsubscribe('db:sync', dbSync);
eUnSubscribeEvent(eStartSyncer, startSyncer);
eUnSubscribeEvent(eDispatchAction, (type) => {
dispatch(type);
@@ -299,7 +313,6 @@ const App = () => {
sleep(500).then(() => (appInit = true));
db.notes.init().then(() => {
dispatch({type: Actions.NOTES});
console.log(db.notes.all);
dispatch({type: Actions.LOADING, loading: false});
SettingsService.setAppLoaded();
});
@@ -349,7 +362,6 @@ const App = () => {
IntentService.getIntent()
.then(() => {
AppRootView = require('./initializer.intent').IntentView;
console.log('found intent');
setInit(false);
intentInit = true;
dispatch({type: Actions.ALL});
@@ -360,7 +372,6 @@ const App = () => {
.catch((e) => console.log)
.finally(() => {
if (!isIntent) {
console.log('no intent recieved');
ReceiveSharingIntent.clearFileNames();
intentInit = true;
loadMainApp();
@@ -382,10 +393,8 @@ const App = () => {
const onSuccessfulSubscription = (subscription) => {
if (hasPurchased) {
console.log('already processing');
return;
}
console.log('PROCESSING SUBS', subscription.transactionId);
const receipt = subscription.transactionReceipt;
processReceipt(receipt);
@@ -401,12 +410,13 @@ const App = () => {
};
const processReceipt = (receipt) => {
return;
if (receipt) {
if (Platform.OS === 'ios') {
fetch('http://192.168.10.5:8100/webhooks/assn', {
method: 'POST',
body: JSON.stringify({
receipt_data: subscription.transactionReceipt,
receipt_data: receipt,
}),
headers: {
'Content-Type': 'application/json',

View File

@@ -216,7 +216,7 @@ export const ActionSheetComponent = ({
copyNote: true,
novault: true,
locked: true,
item:note
item: note,
});
} else {
let text = await db.notes.note(note.id).content();
@@ -225,7 +225,6 @@ export const ActionSheetComponent = ({
Clipboard.setString(text);
ToastEvent.show('Note copied to clipboard', 'success', 'local');
}
},
},
{
@@ -615,25 +614,32 @@ export const ActionSheetComponent = ({
)}
{note.type !== 'note' || refreshing ? null : (
<Paragraph
color={colors.accent}
size={SIZE.xs}
<TouchableOpacity
activeOpacity={0.9}
testID={notesnook.ids.dialogs.actionsheet.sync}
onPress={onPressSync}
style={{
textAlignVertical: 'center',
marginTop: 5,
borderWidth: 1,
textAlign: 'center',
borderColor: colors.accent,
paddingHorizontal: 5,
borderRadius: 2,
justifyContent: 'center',
alignItems: 'center',
marginTop: 5,
borderWidth: 1,
height: 20,
}}>
<Paragraph
color={colors.accent}
size={SIZE.xs}
style={{
textAlignVertical: 'center',
textAlign: 'center',
}}>
{user && user.lastSynced > note.dateEdited
? 'Synced'
: 'Sync Now'}
</Paragraph>
</TouchableOpacity>
)}
{refreshing ? (

View File

@@ -36,7 +36,6 @@ export const NoteItemWrapper = ({item, index, isTrash = false}) => {
newNote.title === note.title &&
newNote.headline === note.headline
) {
console.log('returning from here', newNote.headline, note.headline);
return;
}
setNote(newNote);

View File

@@ -131,6 +131,7 @@ const SimpleList = ({
user = await db.user.get();
dispatch({type: Actions.USER, user: user});
await db.sync();
ToastEvent.show('Sync Complete', 'success');
} catch (e) {
if (!user) {

View File

@@ -21,7 +21,6 @@ export const NavigationStack = ({component = NavigatorStack}) => {
const [initRender, setInitRender] = React.useState(true);
React.useEffect(() => {
console.log('rendering drawer');
sleep(1000).then(() => {
setInitRender(false);
});
@@ -68,7 +67,6 @@ export const NavigationStack = ({component = NavigatorStack}) => {
height: initRender ? 0 : null,
borderRightWidth: 0,
}}
drawerContentOptions={{}}
edgeWidth={200}
drawerType="slide"
drawerContent={deviceMode !== 'mobile' ? () => <></> : DrawerComponent}

View File

@@ -77,7 +77,6 @@ export const NavigatorStack = React.memo(
React.useEffect(() => {
sleep(2000).then(() => {
console.log(SettingsService.get().homepage);
let headerState = {
heading: SettingsService.get().homepage,
id: SettingsService.get().homepage.toLowerCase() + '_navigation',

View File

@@ -11,7 +11,7 @@ export const reducer = (state, action) => {
case Actions.ALL: {
return {
...state,
notes: db.notes.group(SORT[sortSettings.sort]),
notes: [...db.notes.group(SORT[sortSettings.sort])],
notebooks: db.notebooks.all,
trash: db.trash.all,
tags: db.tags.all,

View File

@@ -58,10 +58,7 @@ function encrypt(password, data) {
function decrypt(password, data) {
return Sodium.decrypt(password,data).then((result) => {
console.log(result);
return result;
});
return Sodium.decrypt(password,data).then((result) => result);
}
let CRYPT_CONFIG = Platform.select({