Skip to content

Commit

Permalink
feat(geolocation): add geolocation module
Browse files Browse the repository at this point in the history
  • Loading branch information
Garrett Downs committed Mar 26, 2022
1 parent 1cf31a1 commit 69b954d
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 4 deletions.
11 changes: 11 additions & 0 deletions src/errors/PermissionError.ts
@@ -0,0 +1,11 @@
export class PermissionError extends Error {
name: string = 'PermissionError';

constructor(message?: string) {
super(message);

if (message) {
this.message = message;
}
}
}
1 change: 1 addition & 0 deletions src/errors/index.ts
@@ -0,0 +1 @@
export * from './PermissionError';
19 changes: 15 additions & 4 deletions src/index.ts
@@ -1,11 +1,22 @@
import { App } from './modules/app';
import { Battery } from './modules/battery';
import { FileStorage } from './modules/fileStorage';
import { Geolocation } from './modules/geolocation';
import { LocalStorage } from './modules/localStorage';
import { Volume } from './modules/volume';

export class KaiOS {
static Volume = Volume;
static LocalStorage = LocalStorage;
static FileStorage = FileStorage;
export * from './modules/app';
export * from './modules/battery';
export * from './modules/fileStorage';
export * from './modules/geolocation';
export * from './modules/localStorage';
export * from './modules/volume';

export default class KaiOS {
static App = App;
static Battery = Battery;
static FileStorage = FileStorage;
static Geolocation = Geolocation;
static LocalStorage = LocalStorage;
static Volume = Volume;
}
1 change: 1 addition & 0 deletions src/models/Location.ts
@@ -0,0 +1 @@
export type Location = GeolocationPosition;
1 change: 1 addition & 0 deletions src/models/MozNavigator.ts
Expand Up @@ -17,4 +17,5 @@ export type MozNavigator = Navigator & {
requestDown: () => void;
requestShow: () => void;
};
geolocation: any;
};
1 change: 1 addition & 0 deletions src/models/index.ts
Expand Up @@ -3,6 +3,7 @@ export * from './CallbackFn';
export * from './Connection';
export * from './DomApplication';
export * from './FileSearchResult';
export * from './Location';
export * from './Manifest';
export * from './MozDeviceStorage';
export * from './MozNavigator';
Expand Down
19 changes: 19 additions & 0 deletions src/modules/geolocation.ts
@@ -0,0 +1,19 @@
import { Navigator } from './navigator';

type GetCurrentOptions = {
maximumAge?: number;
timeout?: number;
enableHighAccuracy?: boolean;
};

export class Geolocation {
getCurrent(options?: GetCurrentOptions): Promise<Location> {
return new Promise((resolve, reject) => {
Navigator.navigator.geolocation.getCurrentPosition(
(position: Location) => resolve(position),
(err: GeolocationPositionError) => reject(err),
options
);
});
}
}

0 comments on commit 69b954d

Please sign in to comment.