mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2025-01-31 18:49:43 +08:00
feat(user-agent): add User-Agent plugin (#1582)
* feat(user-agent): add User-Agent plugin * feat(user-agent): Few changes upon request
This commit is contained in:
parent
0b2227d35a
commit
6f6392ea5c
73
src/@ionic-native/plugins/user-agent/index.ts
Normal file
73
src/@ionic-native/plugins/user-agent/index.ts
Normal file
@ -0,0 +1,73 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Plugin, Cordova, IonicNativePlugin } from '@ionic-native/core';
|
||||
|
||||
/**
|
||||
* @name User Agent
|
||||
* @description
|
||||
* The UserAgent plugin provides functions to set the HTTP user-agent header. For more info about User-Agents, please [see the HTTP User-Agent docs](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent).
|
||||
*
|
||||
* Requires Cordova plugin: `cordova-useragent`. For more info, please see the [User-Agent plugin docs](https://github.com/LouisT/cordova-useragent).
|
||||
*
|
||||
* @usage
|
||||
* ```typescript
|
||||
* import { UserAgent } from '@ionic-native/user-agent';
|
||||
*
|
||||
*
|
||||
* constructor(private userAgent: UserAgent) { }
|
||||
*
|
||||
* ...
|
||||
*
|
||||
*
|
||||
* this.userAgent.set('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36')
|
||||
* .then((res: any) => console.log(res))
|
||||
* .catch((error: any) => console.error(error));
|
||||
*
|
||||
* * this.userAgent.get()
|
||||
* .then((res: any) => console.log(res))
|
||||
* .catch((error: any) => console.error(error));
|
||||
*
|
||||
* * this.userAgent.reset()
|
||||
* .then((res: any) => console.log(res))
|
||||
* .catch((error: any) => console.error(error));
|
||||
*
|
||||
* ```
|
||||
*/
|
||||
@Plugin({
|
||||
pluginName: 'UserAgent',
|
||||
plugin: 'https://github.com/LouisT/cordova-useragent',
|
||||
pluginRef: 'plugins.useragent',
|
||||
repo: 'https://github.com/LouisT/cordova-useragent',
|
||||
platforms: ['Android', 'iOS']
|
||||
})
|
||||
@Injectable()
|
||||
export class UserAgent extends IonicNativePlugin {
|
||||
|
||||
/**
|
||||
* Changes the current user-agent to the one sent by argument.
|
||||
* @param userAgent {string} User-Agent
|
||||
* @return {Promise<any>} Returns a promise that resolves when the user-agent changes
|
||||
*/
|
||||
@Cordova()
|
||||
set(userAgent: string): Promise<any> {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current user-agent string.
|
||||
* @return {Promise<any>} Returns a promise that resolves when the user-agent is returned
|
||||
*/
|
||||
@Cordova()
|
||||
get(): Promise<any> {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the user-agent back to default
|
||||
* @return {Promise<any>} Returns a promise that resolves when the user-agent resets
|
||||
*/
|
||||
@Cordova()
|
||||
reset(): Promise<any> {
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user