-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MALI-1408] - MiniApp preferences feature (#289)
* [MALI-1408] - Initial commit * Refactor
- Loading branch information
1 parent
8fc3597
commit cc222c9
Showing
5 changed files
with
272 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { MiniAppBridgeUtils, PlatformExecutor } from '../common-bridge'; | ||
import { parseMiniAppError } from '../types/error-types'; | ||
|
||
export class MiniAppPreferences { | ||
executor: PlatformExecutor; | ||
platform: string; | ||
|
||
constructor(executor: PlatformExecutor) { | ||
this.executor = executor; | ||
this.platform = executor.getPlatform(); | ||
} | ||
|
||
/** | ||
* Sets the value of the specified default key. | ||
* @param {key} string | ||
* @param {value} string | ||
* @see {set} | ||
*/ | ||
set(key: string, value: string) { | ||
return new Promise<boolean>((resolve, reject) => { | ||
return this.executor.exec( | ||
'setPreference', | ||
{ preferenceKey: key, preferenceValue: value }, | ||
response => { | ||
resolve(MiniAppBridgeUtils.BooleanValue(response)); | ||
}, | ||
error => reject(parseMiniAppError(error)) | ||
); | ||
}); | ||
} | ||
|
||
/** | ||
* Returns the object associated with the specified key. | ||
* @param {key} string | ||
* @see {get} | ||
*/ | ||
get(key: string) { | ||
return new Promise<string>((resolve, reject) => { | ||
return this.executor.exec( | ||
'getPreference', | ||
{ preferenceKey: key }, | ||
response => { | ||
resolve(response); | ||
}, | ||
error => reject(parseMiniAppError(error)) | ||
); | ||
}); | ||
} | ||
|
||
/** | ||
* Removes the value of the specified default key. | ||
* @param {key} string | ||
* @see {remove} | ||
*/ | ||
remove(key: string) { | ||
return new Promise<boolean>((resolve, reject) => { | ||
return this.executor.exec( | ||
'getPreference', | ||
{ preferenceKey: key }, | ||
response => { | ||
resolve(MiniAppBridgeUtils.BooleanValue(response)); | ||
}, | ||
error => reject(parseMiniAppError(error)) | ||
); | ||
}); | ||
} | ||
|
||
/** | ||
* Removes all keys that is stored | ||
* @param {key} string | ||
* @see {clearMiniAppPreferences} | ||
*/ | ||
clearMiniAppPreferences() { | ||
return new Promise<boolean>((resolve, reject) => { | ||
return this.executor.exec( | ||
'clearMiniAppPreferences', | ||
null, | ||
response => { | ||
resolve(MiniAppBridgeUtils.BooleanValue(response)); | ||
}, | ||
error => reject(parseMiniAppError(error)) | ||
); | ||
}); | ||
} | ||
} |
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
Oops, something went wrong.