Skip to content
Draft
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 app.webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ module.exports = (env, params = {}) => {
// env.appComponents.push('~/android/cameraactivity');
env.appComponents.push('~/android/activity.android');
env.appComponents.push('~/android/camera_scan_activity');
env.appComponents.push('~/android/sync_alarm_receiver');
const config = webpackConfig(env, params);
config.entry.application = '~/android/application.android';
const {
Expand Down
37 changes: 37 additions & 0 deletions app/android/sync_alarm_receiver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Application, Utils } from '@nativescript/core';
import { SYNC_ALARM_ACTION, SYNC_THROTTLE_ALARM, syncService } from '../services/sync.android';
import { start } from '~/startHandler';

/**
* BroadcastReceiver for handling sync alarms on Android
*/
@NativeClass()
@JavaProxy('__PACKAGE__.SyncAlarmReceiver')
export class SyncAlarmReceiver extends android.content.BroadcastReceiver {
async onReceive(context: android.content.Context, intent: android.content.Intent) {
const action = intent.getAction();

// Check if this is our sync alarm action
if (action !== SYNC_ALARM_ACTION) {
return;
}

const serviceId = intent.getLongExtra('serviceId', -1);
if (serviceId === -1) {
return;
}

DEV_LOG && console.log('SyncAlarmReceiver', 'onReceive', action, serviceId, Application.servicesStarted);
function handleIntent() {
syncService.triggerThrottledSync(serviceId).catch((error) => {
console.error('SyncAlarmReceiver', 'failed to trigger sync', error);
});
}
try {
await start();
handleIntent();
} catch (error) {
console.error(error, error.stack);
}
}
}
36 changes: 9 additions & 27 deletions app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ import { SETTINGS_APP_VERSION, SETTINGS_SYNC_ON_START } from '~/utils/constants'
import { startOnCam } from './variables';
import { CollectionViewTraceCategory } from '@nativescript-community/ui-collectionview';
import { init as sharedInit } from '@shared/index';
import { start, stopAppServices } from '~/startHandler';

declare module '@nativescript/core/application/application-common' {
interface ApplicationCommon {
servicesStarted: boolean;
}
}

try {
// we cant really use firstAppOpen anymore as all apps
// already installed with older version without this code would
Expand Down Expand Up @@ -126,53 +128,33 @@ try {
Trace.enable();
}
if (__DEV__ && __IOS__) {
RocketSim.loadRocketSimConnect();
// TODO: it breaks NSUSerDefaults
// RocketSim.loadRocketSimConnect();
DEV_LOG && console.log('loadRocketSimConnect');
}

let launched = false;
async function start() {
try {
Application.servicesStarted = false;
// DEV_LOG && console.log('start');
setDocumentsService(documentsService);
await Promise.all([networkService.start(), securityService.start(), syncService.start(), ocrService.start(getCurrentISO3Language()), documentsService.start()]);
Application.servicesStarted = true;
// DEV_LOG && console.log('servicesStarted');
Application.notify({ eventName: 'servicesStarted' });
if (ApplicationSettings.getBoolean(SETTINGS_SYNC_ON_START, false)) {
syncService.syncDocuments({ withFolders: true });
}
} catch (error) {
showError(error, PLAY_STORE_BUILD ? { forcedMessage: lc('startup_error') } : {});
}
}

Application.on(Application.launchEvent, async () => {
// DEV_LOG && console.log('launch');
startThemeHelper();
launched = true;
start();

start().catch(showError);
});
Application.on(Application.resumeEvent, () => {
if (!launched) {
// DEV_LOG && console.log('resume');
launched = true;
start();
start().catch(showError);
}
});
let pageInstance;
Application.on(Application.exitEvent, async () => {
DEV_LOG && console.log('exit');
launched = false;
// ocrService.stop();
try {
securityService.stop();
// wait for sync to stop to stop documentService as their could be writes to the db
await syncService.stop();
documentsService.stop();
} catch (error) {
console.error(error, error.stack);
}
stopAppServices();
pageInstance?.$destroy();
pageInstance = null;
});
Expand Down
2 changes: 1 addition & 1 deletion app/components/common/ListItemAutoSize.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
fontSize={subtitleFontSize * $fontScale}
marginLeft={16}
opacity={enabled === false ? 0.38 : 1}
text={typeof rightValue === 'function' ? rightValue() : rightValue}
text={(typeof rightValue === 'function' ? rightValue() : rightValue) + ''}
textAlignment="right"
verticalAlignment="middle"
visibility={!!rightValue ? 'visible' : 'collapse'}
Expand Down
2 changes: 2 additions & 0 deletions app/components/list/MainList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@
}

export async function refresh(force = true, filter?: string) {

// DEV_LOG && console.log('refresh', force, filter);
if (loading || (!force && lastRefreshFilter === filter) || !documentsService.started) {
return;
Expand Down Expand Up @@ -255,6 +256,7 @@
documents.map((d) => d.doc?.id)
);
updateNoDocument();

} catch (error) {
showError(error);
} finally {
Expand Down
37 changes: 28 additions & 9 deletions app/components/settings/FolderImageSyncSettings.svelte
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
<script lang="ts">
import { Template } from '@nativescript-community/svelte-native/components';
import { NativeViewElementNode } from '@nativescript-community/svelte-native/dom';
import { CheckBox } from '@nativescript-community/ui-checkbox';
import { CollectionView } from '@nativescript-community/ui-collectionview';
import { Label } from '@nativescript-community/ui-label';
import { prompt } from '@nativescript-community/ui-material-dialogs';
import { TextField, TextFieldProperties } from '@nativescript-community/ui-material-textfield';
import { ApplicationSettings, Color, ObservableArray, View } from '@nativescript/core';
import { Template } from '@nativescript-community/svelte-native/components';
import { NativeViewElementNode } from '@nativescript-community/svelte-native/dom';
import { showError } from '@shared/utils/showError';
import { closeModal } from '@shared/utils/svelte/ui';
import { get, writable } from 'svelte/store';
import { l, lc } from '~/helpers/locale';
import { LocalFolderImageSyncServiceOptions } from '~/services/sync/LocalFolderImageSyncService';
import { SERVICES_SYNC_COLOR } from '~/services/sync/types';
import { ALERT_OPTION_MAX_HEIGHT, FILENAME_DATE_FORMAT, SETTINGS_FILE_NAME_FORMAT, getImageExportSettings } from '~/utils/constants';
import { showError } from '@shared/utils/showError';
import { closeModal } from '@shared/utils/svelte/ui';
import { createView, getNameFormatHTMLArgs, openLink, pickColor, requestNotificationPermission, showAlertOptionSelect, showSliderPopover } from '~/utils/ui';
import { colors, windowInset } from '~/variables';
import CActionBar from '../common/CActionBar.svelte';
import ListItemAutoSize from '../common/ListItemAutoSize.svelte';
import FolderTextView from '../common/FolderTextView.svelte';
import ListItemAutoSize from '../common/ListItemAutoSize.svelte';
import { checkAlarmPermission } from '~/services/sync/BaseSyncService';
// technique for only specific properties to get updated on store change
$: ({ colorError, colorOnError, colorOnSurfaceVariant, colorOutline, colorPrimary, colorSecondary } = $colors);

Expand Down Expand Up @@ -77,6 +78,21 @@
description: lc('local_auto_sync_desc'),
value: $store.autoSync
},
{
id: 'setting',
key: 'syncThrottleSeconds',
title: lc('sync_throttle_seconds'),
description: lc('sync_throttle_desc'),
valueType: 'number',
type: 'prompt',
textFieldProperties: {
keyboardType: 'number',
autocapitalizationType: 'none'
} as TextFieldProperties,
rightValue: () => $store.syncThrottleSeconds || 0,
default: 0,
validate: checkAlarmPermission
},
{
id: 'setting',
key: 'fileNameFormat',
Expand Down Expand Up @@ -209,11 +225,14 @@
});
DEV_LOG && console.log('prompt result', item.key, item.valueType, result);
if (result && !!result.result && result.text.length > 0) {
if (item.valueType === 'string') {
$store[item.key] = result.text;
} else {
$store[item.key] = parseInt(result.text, 10);
const newValue = item.valueType === 'string' ? result.text : parseInt(result.text, 10);
if (item.validate) {
const validated = await item.validate(newValue);
if (!validated) {
return;
}
}
$store[item.key] = newValue;
updateItem(item);
}
} else if (item.type === 'slider') {
Expand Down
30 changes: 25 additions & 5 deletions app/components/settings/FolderPDFSyncSettings.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import ListItemAutoSize from '../common/ListItemAutoSize.svelte';
import OcrSettingsBottomSheet from '../ocr/OCRSettingsBottomSheet.svelte';
import PdfSyncSettingsView from './PDFSyncSettingsView.svelte';
import { requestExactAlarmPermission } from '@nativescript-community/perms';
import { checkAlarmPermission } from '~/services/sync/BaseSyncService';
// technique for only specific properties to get updated on store change
$: ({ colorOnSurfaceVariant, colorOutline, colorPrimary } = $colors);

Expand Down Expand Up @@ -89,6 +91,21 @@
description: lc('local_auto_sync_desc'),
value: $store.autoSync
},
{
id: 'setting',
key: 'syncThrottleSeconds',
title: lc('sync_throttle_seconds'),
description: lc('sync_throttle_desc'),
valueType: 'number',
type: 'prompt',
textFieldProperties: {
keyboardType: 'number',
autocapitalizationType: 'none'
} as TextFieldProperties,
rightValue: () => $store.syncThrottleSeconds || 0,
default: 0,
validate: checkAlarmPermission
},
{
type: 'switch',
id: 'useDocumentName',
Expand Down Expand Up @@ -225,11 +242,14 @@
});
DEV_LOG && console.log('prompt result', item.key, item.valueType, result);
if (result && !!result.result && result.text.length > 0) {
if (item.valueType === 'string') {
$store[item.key] = result.text;
} else {
$store[item.key] = parseInt(result.text, 10);
const newValue = item.valueType === 'string' ? result.text : parseInt(result.text, 10);
if (item.validate) {
const validated = await item.validate(newValue);
if (!validated) {
return;
}
}
$store[item.key] = newValue;
updateItem(item);
}
} else if (item.type === 'slider') {
Expand Down Expand Up @@ -331,7 +351,7 @@

<page actionBarHidden={true}>
<gridlayout class="pageContent" rows="auto,*">
<collectionview ios:autoReloadItemOnLayout={true} itemTemplateSelector={selectTemplate} {items} row={1} android:paddingBottom={$windowInset.bottom}>
<collectionview id="folderPDFSettings" ios:autoReloadItemOnLayout={true} itemTemplateSelector={selectTemplate} {items} row={1} android:paddingBottom={$windowInset.bottom}>
<Template key="color" let:item>
<ListItemAutoSize fontSize={20} subtitle={lc('sync_service_color_desc')} title={lc('color')} on:tap={(e) => changeColor(item, e)}>
<absolutelayout backgroundColor={$store.color} borderColor={colorOutline} borderRadius="50%" borderWidth={2} col={1} height={40} marginLeft={10} width={40} />
Expand Down
28 changes: 7 additions & 21 deletions app/components/settings/PDFSyncSettingsView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -92,53 +92,39 @@
<textfield
editable={false}
hint={lc('orientation')}
margin={'0 4 5 0'}
margin="0 4 5 0"
text={PDF_OPTIONS['orientation'][$store.exportOptions.orientation].name}
{variant}
width={tWidth}
on:tap={(e) => selectPDFOption('orientation', e)} />
<textfield
editable={false}
hint={lc('paper_size')}
margin={'0 0 5 4'}
margin="0 0 5 4"
text={PDF_OPTIONS['paper_size'][$store.exportOptions.paper_size].name}
{variant}
width={tWidth}
on:tap={(e) => selectPDFOption('paper_size', e)} />

<textfield
editable={false}
hint={lc('color')}
margin={'5 4 5 0'}
text={PDF_OPTIONS['color'][$store.exportOptions.color].name}
{variant}
width={tWidth}
on:tap={(e) => selectPDFOption('color', e)} />
<textfield editable={false} hint={lc('color')} margin="5 4 5 0" text={PDF_OPTIONS['color'][$store.exportOptions.color].name} {variant} width={tWidth} on:tap={(e) => selectPDFOption('color', e)} />
<textfield
editable={false}
hint={lc('items_per_page')}
margin={'5 0 5 4'}
margin="5 0 5 4"
text={PDF_OPTIONS['items_per_page'][$store.exportOptions.items_per_page].name}
{variant}
width={tWidth}
on:tap={(e) => selectPDFOption('items_per_page', e, parseInt)} />
<textfield
editable={false}
hint={lc('page_padding')}
margin={'5 4 5 0'}
text={$store.exportOptions.page_padding}
{variant}
width={tWidth}
on:tap={(e) => selectSilderPDFOption('page_padding', e)} />
<stacklayout margin={'5 0 5 4'} orientation="horizontal" width={tWidth}>
<textfield editable={false} hint={lc('page_padding')} margin="5 4 5 0" text={$store.exportOptions.page_padding} {variant} width={tWidth} on:tap={(e) => selectSilderPDFOption('page_padding', e)} />
<stacklayout margin="5 0 5 4" orientation="horizontal" width={tWidth}>
<checkbox id="checkbox" checked={$store.exportOptions.draw_ocr_text} verticalAlignment="center" on:checkedChange={(e) => updatePDFOption('draw_ocr_text', e.value)} ios:margin={14} />
<label fontSize={14} text={lc('draw_ocr_text')} textWrap={true} verticalAlignment="center" on:tap={(e) => onCheckBox(e, 'draw_ocr_text')} />
</stacklayout>
<textfield
autocapitalizationType="none"
autocorrect={false}
hint={lc('optional_pdf_password')}
margin={'5 0 5 0'}
margin="5 0 5 0"
placeholder={lc('password')}
placeholderColor="gray"
returnKeyType="done"
Expand Down
2 changes: 1 addition & 1 deletion app/components/settings/SyncListSettings.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@

<page id="syncSettingsPage" actionBarHidden={true}>
<gridlayout class="pageContent" rows="auto,*">
<collectionview bind:this={collectionView} itemTemplateSelector={selectTemplate} {items} row={1} android:paddingBottom={$windowInset.bottom}>
<collectionview bind:this={collectionView} id="syncSettings" itemTemplateSelector={selectTemplate} {items} row={1} android:paddingBottom={$windowInset.bottom}>
<Template let:item>
<swipemenu
gestureHandlerOptions={{
Expand Down
18 changes: 18 additions & 0 deletions app/components/settings/WebdavDataSyncSettings.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import CActionBar from '../common/CActionBar.svelte';
import ListItemAutoSize from '../common/ListItemAutoSize.svelte';
import WebdavSettingsView from './WebdavSettingsView.svelte';
import { checkAlarmPermission } from '~/services/sync/BaseSyncService';
// technique for only specific properties to get updated on store change
$: ({ colorError, colorOnError, colorOnSurfaceVariant, colorOutline, colorPrimary, colorSecondary } = $colors);

Expand Down Expand Up @@ -107,6 +108,23 @@
$store.autoSync = e.value;
})} />
</ListItemAutoSize>
{#if $store.autoSync}
<ListItemAutoSize fontSize={20} subtitle={lc('sync_throttle_desc')} title={lc('sync_throttle_seconds')}>
<textfield
col={1}
hint="0"
keyboardType="number"
marginLeft={10}
text={String($store.syncThrottleSeconds || 0)}
width={100}
on:textChange={(e) => {
const value = parseInt(e.value, 10) || 0;
if (checkAlarmPermission(value)) {
$store.syncThrottleSeconds = Math.max(0, value);
}
}} />
</ListItemAutoSize>
{/if}
<WebdavSettingsView bind:this={webdavView} {store} />
</stacklayout>
</scrollview>
Expand Down
Loading