-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Open cozy-app when offline only if it supports Offline mode
When offline, we want to open coz-apps only when they declare to be compatible with Offline mode Cozy-app can declare this by setting `offline_support: true` in their manifest.webapp file Non compatible cozy-app won't be opened when the Flagship app is offline, and instead an error message will be displayed
- Loading branch information
Showing
2 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import RNFS from 'react-native-fs' | ||
|
||
import { getErrorMessage } from 'cozy-intent' | ||
import Minilog from 'cozy-minilog' | ||
|
||
import { getCurrentAppConfigurationForFqdnAndSlug } from '/libs/cozyAppBundle/cozyAppBundleConfiguration' | ||
import { getBaseFolderForFqdnAndSlugAndCurrentVersion } from '/libs/httpserver/httpPaths' | ||
|
||
export const log = Minilog('IsOfflineCompatible') | ||
|
||
export const isOfflineCompatible = async ( | ||
fqdn: string, | ||
slug: string | ||
): Promise<boolean> => { | ||
try { | ||
const appConfiguration = await getCurrentAppConfigurationForFqdnAndSlug( | ||
fqdn, | ||
slug | ||
) | ||
|
||
if (!appConfiguration) { | ||
return false | ||
} | ||
|
||
const basePath = await getBaseFolderForFqdnAndSlugAndCurrentVersion( | ||
fqdn, | ||
slug | ||
) | ||
|
||
const manifestPath = basePath + '/manifest.webapp' | ||
|
||
if (!(await RNFS.exists(manifestPath))) { | ||
return false | ||
} | ||
|
||
const fileContent = await RNFS.readFile(manifestPath) | ||
|
||
const manifest = JSON.parse(fileContent) as Record<string, unknown> | ||
|
||
return manifest.offline_support === true | ||
} catch (error) { | ||
log.error( | ||
`Could not read manifest for app "${slug}": ${getErrorMessage(error)}.` | ||
) | ||
|
||
return false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters