commit a2c5be0a7c0a1fb899a6099098814ff7ece1109d
parent 3a6549d07a07efc1b026ff8155736080c8346b2e
Author: triesap <137732411+triesap@users.noreply.github.com>
Date: Fri, 23 Aug 2024 13:39:15 +0000
client: add capacitor window api
Diffstat:
4 files changed, 56 insertions(+), 1 deletion(-)
diff --git a/client/package.json b/client/package.json
@@ -18,6 +18,8 @@
"@capacitor/network": "^6.0.0",
"@capacitor/preferences": "^6.0.0",
"@capacitor/share": "^6.0.0",
+ "@capacitor/splash-screen": "^6.0.0",
+ "@capacitor/status-bar": "^6.0.0",
"@radroots/capacitor-date-picker": "workspace:*",
"@radroots/capacitor-secure-storage": "workspace:*",
"@radroots/capacitor-wifi": "workspace:*"
diff --git a/client/src/capacitor/index.ts b/client/src/capacitor/index.ts
@@ -1,6 +1,6 @@
import { Capacitor } from "@capacitor/core";
-import type { IClient, IClientBrowser, IClientDatePicker, IClientDevice, IClientDialog, IClientGeolocation, IClientHaptics, IClientHttp, IClientKeystore, IClientNetwork, IClientPlatform, IClientPreferences, IClientShare, IClientWifi } from "../types";
+import type { IClient, IClientBrowser, IClientDatePicker, IClientDevice, IClientDialog, IClientGeolocation, IClientHaptics, IClientHttp, IClientKeystore, IClientNetwork, IClientPlatform, IClientPreferences, IClientShare, IClientWifi, IClientWindow } from "../types";
import { parse_platform } from "../utils";
import { CapacitorClientBrowser } from "./browser";
import { CapacitorClientDatePicker } from "./date-picker";
@@ -14,6 +14,7 @@ import { CapacitorClientNetwork } from "./network";
import { CapacitorClientPreferences } from "./preferences";
import { CapacitorClientShare } from "./share";
import { CapacitorClientWifi } from "./wifi";
+import { CapacitorClientWindow } from "./window";
export class ClientCapacitor implements IClient {
private _platform: IClientPlatform = parse_platform(Capacitor.getPlatform());
@@ -29,6 +30,7 @@ export class ClientCapacitor implements IClient {
private _dates: IClientDatePicker = new CapacitorClientDatePicker();
private _geo: IClientGeolocation = new CapacitorClientGeolocation();
private _http: IClientHttp = new CapacitorClientHttp();
+ private _window: IClientWindow = new CapacitorClientWindow();
public get platform() {
return this._platform;
@@ -81,4 +83,8 @@ export class ClientCapacitor implements IClient {
public get http() {
return this._http;
}
+
+ public get window() {
+ return this._window;
+ }
};
\ No newline at end of file
diff --git a/client/src/capacitor/window.ts b/client/src/capacitor/window.ts
@@ -0,0 +1,38 @@
+import { SplashScreen } from '@capacitor/splash-screen';
+import { StatusBar, Style } from '@capacitor/status-bar';
+import type { IClientWindow } from '../types';
+
+export class CapacitorClientWindow implements IClientWindow {
+ public async splash_hide(): Promise<void> {
+ try {
+ await SplashScreen.hide();
+ } catch (e) { };
+ }
+
+ public async splash_show(showDuration?: number): Promise<void> {
+ try {
+ await SplashScreen.show({
+ showDuration,
+ autoHide: showDuration ? true : false,
+ });
+ } catch (e) { };
+ }
+
+ public async status_hide(): Promise<void> {
+ try {
+ await StatusBar.hide();
+ } catch (e) { };
+ }
+
+ public async status_show(): Promise<void> {
+ try {
+ await StatusBar.show();
+ } catch (e) { };
+ }
+
+ public async status_style(style: 'light' | 'dark'): Promise<void> {
+ try {
+ await StatusBar.setStyle({ style: style === 'light' ? Style.Light : Style.Dark });
+ } catch (e) { };
+ }
+}
diff --git a/client/src/types.ts b/client/src/types.ts
@@ -15,6 +15,7 @@ export type IClient = {
dates: IClientDatePicker;
geo: IClientGeolocation;
http: IClientHttp;
+ window: IClientWindow;
};
export type IClientPlatform = `androiď` | `ios` | `web`;
@@ -152,4 +153,12 @@ export type IClientHttpResponse = {
export type IClientHttp = {
get(opts: IClientHttpOpts): Promise<IClientHttpResponse | undefined>;
post(opts: IClientHttpOpts): Promise<IClientHttpResponse | undefined>;
+};
+
+export type IClientWindow = {
+ splash_hide(): Promise<void>;
+ splash_show(showDuration?: number): Promise<void>;
+ status_hide(): Promise<void>;
+ status_show(): Promise<void>;
+ status_style(style: "light" | "dark"): Promise<void>;
};
\ No newline at end of file