-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
66 additions
and
108 deletions.
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
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
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
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
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
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,41 @@ | ||
import * as FileSystem from "expo-file-system"; | ||
|
||
import { appConfig } from "../constants/app.config"; | ||
|
||
class ShortCutPayloadSingleton { | ||
private readonly storageKey = "openedApp"; | ||
private pathSplitted = FileSystem.documentDirectory?.split("/"); | ||
private appPath = this.pathSplitted?.slice(0, this.pathSplitted.length - 2).join("/"); | ||
private dataPath = `${this.appPath}/Library/Application Support/${appConfig.bundleIdentifier}/RCTAsyncLocalStorage_V1/appintent.json`; | ||
|
||
private loadAppIntentPayload = async (): Promise<Record<string, unknown>> => { | ||
const string = await FileSystem.readAsStringAsync(this.dataPath); | ||
const payload = JSON.parse(string) as Record<string, unknown>; | ||
return payload; | ||
}; | ||
|
||
public getPayload = async (): Promise<{ app: string; timestamp: string; event: string } | null> => { | ||
const payload = await this.loadAppIntentPayload(); | ||
const openedAppPayload = payload[this.storageKey] as string | undefined; | ||
if (openedAppPayload) { | ||
const [openedApp, timestamp, event] = openedAppPayload.split("_") as [string, string, string]; | ||
return { app: openedApp, timestamp, event }; | ||
} else { | ||
return null; | ||
} | ||
}; | ||
|
||
public update = async (app: string, event: string) => { | ||
const appIntentPayload = await this.loadAppIntentPayload(); | ||
appIntentPayload.openedApp = `${app}_${Date.now()}_${event}`; | ||
await FileSystem.writeAsStringAsync(this.dataPath, JSON.stringify(appIntentPayload)); | ||
}; | ||
|
||
public clear = async () => { | ||
const appIntentPayload = await this.loadAppIntentPayload(); | ||
delete appIntentPayload.openedApp; | ||
await FileSystem.writeAsStringAsync(this.dataPath, JSON.stringify(appIntentPayload)); | ||
}; | ||
} | ||
|
||
export const ShortCutPayload = new ShortCutPayloadSingleton(); |
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