Skip to content

Commit

Permalink
Replace @capacitor/screen-orientation
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelmayer-dev committed Apr 28, 2024
1 parent e67f249 commit 7831cc2
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 37 deletions.
2 changes: 1 addition & 1 deletion android/app/capacitor.build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dependencies {
implementation project(':capacitor-app')
implementation project(':capacitor-haptics')
implementation project(':capacitor-keyboard')
implementation project(':capacitor-screen-orientation')
implementation project(':capawesome-capacitor-screen-orientation')
implementation project(':sslhandler')

}
Expand Down
4 changes: 2 additions & 2 deletions android/capacitor.settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ project(':capacitor-haptics').projectDir = new File('../node_modules/@capacitor/
include ':capacitor-keyboard'
project(':capacitor-keyboard').projectDir = new File('../node_modules/@capacitor/keyboard/android')

include ':capacitor-screen-orientation'
project(':capacitor-screen-orientation').projectDir = new File('../node_modules/@capacitor/screen-orientation/android')
include ':capawesome-capacitor-screen-orientation'
project(':capawesome-capacitor-screen-orientation').projectDir = new File('../node_modules/@capawesome/capacitor-screen-orientation/android')

include ':sslhandler'
project(':sslhandler').projectDir = new File('../node_modules/sslhandler/android')
5 changes: 5 additions & 0 deletions ios/App/App/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import UIKit
import Capacitor
import CapawesomeCapacitorScreenOrientation

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
Expand All @@ -11,6 +12,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
return true
}

func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return ScreenOrientation.getSupportedInterfaceOrientations()
}

func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
Expand Down
2 changes: 1 addition & 1 deletion ios/App/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def capacitor_pods
pod 'CapacitorApp', :path => '../../node_modules/@capacitor/app'
pod 'CapacitorHaptics', :path => '../../node_modules/@capacitor/haptics'
pod 'CapacitorKeyboard', :path => '../../node_modules/@capacitor/keyboard'
pod 'CapacitorScreenOrientation', :path => '../../node_modules/@capacitor/screen-orientation'
pod 'CapawesomeCapacitorScreenOrientation', :path => '../../node_modules/@capawesome/capacitor-screen-orientation'
pod 'Sslhandler', :path => '../../node_modules/sslhandler'
pod 'CordovaPlugins', :path => '../capacitor-cordova-ios-plugins'
end
Expand Down
12 changes: 6 additions & 6 deletions ios/App/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ PODS:
- Capacitor
- CapacitorKeyboard (5.0.6):
- Capacitor
- CapacitorScreenOrientation (5.0.6):
- CapawesomeCapacitorScreenOrientation (6.0.0):
- Capacitor
- CordovaPlugins (5.2.3):
- CapacitorCordova
Expand All @@ -24,7 +24,7 @@ DEPENDENCIES:
- "CapacitorCordova (from `../../node_modules/@capacitor/ios`)"
- "CapacitorHaptics (from `../../node_modules/@capacitor/haptics`)"
- "CapacitorKeyboard (from `../../node_modules/@capacitor/keyboard`)"
- "CapacitorScreenOrientation (from `../../node_modules/@capacitor/screen-orientation`)"
- "CapawesomeCapacitorScreenOrientation (from `../../node_modules/@capawesome/capacitor-screen-orientation`)"
- CordovaPlugins (from `../capacitor-cordova-ios-plugins`)
- Sslhandler (from `../../node_modules/sslhandler`)

Expand All @@ -41,8 +41,8 @@ EXTERNAL SOURCES:
:path: "../../node_modules/@capacitor/haptics"
CapacitorKeyboard:
:path: "../../node_modules/@capacitor/keyboard"
CapacitorScreenOrientation:
:path: "../../node_modules/@capacitor/screen-orientation"
CapawesomeCapacitorScreenOrientation:
:path: "../../node_modules/@capawesome/capacitor-screen-orientation"
CordovaPlugins:
:path: "../capacitor-cordova-ios-plugins"
Sslhandler:
Expand All @@ -55,10 +55,10 @@ SPEC CHECKSUMS:
CapacitorCordova: 35def3ebfdef491f0a7b652816eb873ff4b20bbf
CapacitorHaptics: 1fffc1217c7e64a472d7845be50fb0c2f7d4204c
CapacitorKeyboard: b978154b024a5f65e044908e37d15b7de58b9d12
CapacitorScreenOrientation: e5ef438489815d05340f1b51a2b1794108dc0ac3
CapawesomeCapacitorScreenOrientation: 82675c41cb616a64630c834b06344515a2849ff3
CordovaPlugins: d4671f1d2a1af985cd35caa0d8bbb58b95ef3c70
Sslhandler: 5b1dfaa41fdbad6e788cea98538cb0c2995b9153

PODFILE CHECKSUM: 398e7d75531b27cb4b9dbfe967b8b16018b40804
PODFILE CHECKSUM: 4824b7d1cba227e54345c8671e97841c8e6cf1e7

COCOAPODS: 1.12.1
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@capacitor/haptics": "5.0.6",
"@capacitor/ios": "5.2.3",
"@capacitor/keyboard": "5.0.6",
"@capacitor/screen-orientation": "^5.0.6",
"@capawesome/capacitor-screen-orientation": "^6.0.0",
"@ionic-native/core": "^5.36.0",
"@ionic-native/ionic-webview": "^5.36.0",
"@ionic-native/screen-orientation": "^5.36.0",
Expand Down
16 changes: 8 additions & 8 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {WakelockService} from "./services/wakelock/wakelock.service";
import {ScreenOrientationService} from "./services/screen-orientation/screen-orientation.service";
import {SslHandler} from "../../capacitor_plugins/sslhandler/src";
import {SettingsService} from "./services/settings/settings.service";
import {DiagnosticService} from "./services/diagnostic/diagnostic.service";

@Component({
selector: 'app-root',
Expand All @@ -14,19 +15,18 @@ export class AppComponent implements OnInit {
constructor(private storage: Storage,
private wakeLockService: WakelockService,
private screenOrientationService: ScreenOrientationService,
private settingsService: SettingsService) {
private settingsService: SettingsService,
private diagnosticService: DiagnosticService) {
}

async ngOnInit() {
await this.storage.create();
await this.screenOrientationService.updateScreenOrientation();
try {
await this.wakeLockService.updateWakeLock();
} catch {
// exception is expected in browser because wake lock needs user interaction
}
await this.wakeLockService.updateWakeLock();

let skipSslValidation = await this.settingsService.getSkipSslValidation();
SslHandler.skipValidation({value: skipSslValidation});
if (this.diagnosticService.isAndroid()) {
let skipSslValidation = await this.settingsService.getSkipSslValidation();
SslHandler.skipValidation({value: skipSslValidation});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<ion-label slot="end">{{buttonLongPressDelay}}ms</ion-label>
</ion-item>

<ion-item *ngIf="isAndroidOriOS()">
<ion-item *ngIf="isiOSorAndroid()">
<ion-icon slot="start" class="mdi mdi-screen-rotation d-flex align-items-center"></ion-icon>
<ion-select [(ngModel)]="screenOrientation" label="Screen orientation">
<ion-select-option value="0">Auto</ion-select-option>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ export class SettingsModalComponent implements OnInit {
await this.settingsService.setScreenOrientation(Number.parseInt(this.screenOrientation));
await this.wakelockService.updateWakeLock();
await this.screenOrientationService.updateScreenOrientation();
SslHandler.skipValidation({value: this.skipSslValidation});
if (this.diagnosticService.isAndroid()) {
SslHandler.skipValidation({value: this.skipSslValidation});
}
}

async loadCurrentSettings() {
Expand Down Expand Up @@ -74,8 +76,8 @@ export class SettingsModalComponent implements OnInit {
return this.diagnosticService.isAndroid()
}

public isAndroidOriOS() {
return this.diagnosticService.isAndroid() || this.diagnosticService.isiOS();
public isiOSorAndroid() {
return this.diagnosticService.isiOSorAndroid();
}

protected readonly environment = environment;
Expand Down
3 changes: 3 additions & 0 deletions src/app/services/diagnostic/diagnostic.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ export class DiagnosticService {
return this.platform.is("ios");
}

public isiOSorAndroid() {
return this.isiOS() || this.isAndroid();
}
}
19 changes: 13 additions & 6 deletions src/app/services/screen-orientation/screen-orientation.service.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,40 @@
import { Injectable } from '@angular/core';
import {SettingsService} from "../settings/settings.service";
import {ScreenOrientationType} from "../../enums/screen-orientation-type";
import {ScreenOrientation} from "@capacitor/screen-orientation";
import { ScreenOrientation, OrientationType } from '@capawesome/capacitor-screen-orientation';
import {DiagnosticService} from "../diagnostic/diagnostic.service";


@Injectable({
providedIn: 'root'
})
export class ScreenOrientationService {

constructor(private settingsService: SettingsService) { }
constructor(private settingsService: SettingsService,
private diagnosticService: DiagnosticService) { }

public async updateScreenOrientation() {
if (!this.diagnosticService.isiOSorAndroid()) {
return;
}

let screenOrientation = await this.settingsService.getScreenOrientation();
try {
switch (screenOrientation) {
case ScreenOrientationType.Auto:
await ScreenOrientation.unlock();
break;
case ScreenOrientationType.Landscape:
await ScreenOrientation.lock({orientation: "landscape"});
await ScreenOrientation.lock({ type: OrientationType.LANDSCAPE_PRIMARY });
break;
case ScreenOrientationType.LandscapeAlt:
await ScreenOrientation.lock({orientation: "landscape-secondary"});
await ScreenOrientation.lock({ type: OrientationType.LANDSCAPE_SECONDARY });
break;
case ScreenOrientationType.Portrait:
await ScreenOrientation.lock({orientation: "portrait"});
await ScreenOrientation.lock({ type: OrientationType.PORTRAIT_PRIMARY });
break;
case ScreenOrientationType.PortraitAlt:
await ScreenOrientation.lock({orientation: "portrait-secondary"});
await ScreenOrientation.lock({ type: OrientationType.PORTRAIT_SECONDARY });
break;
}
} catch {
Expand Down
12 changes: 8 additions & 4 deletions src/app/services/wakelock/wakelock.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ export class WakelockService {
}

public async updateWakeLock() {
if (await this.settingsService.getWakeLockEnabled() === true) {
await this.enableWakeLock();
} else {
await this.disableWakeLock();
try {
if (await this.settingsService.getWakeLockEnabled() === true) {
await this.enableWakeLock();
} else {
await this.disableWakeLock();
}
} catch {
// exception is expected in browser because wake lock needs user interaction
}
}

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1436,10 +1436,10 @@
resolved "https://registry.yarnpkg.com/@capacitor/keyboard/-/keyboard-5.0.6.tgz#04400e71b677abf9f1fc1ceaffd1211e7d864319"
integrity sha512-9GewAa/y2Hwkdw/Be8MTdiAjrFZ7TPDKpR44M0Y/0QMnK+mBbgzcoZ/UkuumWv6e2F1IAI+VY5eYVQHDeZcRoA==

"@capacitor/screen-orientation@^5.0.6":
version "5.0.6"
resolved "https://registry.yarnpkg.com/@capacitor/screen-orientation/-/screen-orientation-5.0.6.tgz#fb2985ff06ccfb7a176c7ed07af99fc0c9584e2b"
integrity sha512-WK8zBo+i0ivzIY7gmvr37AMFVGGIsgFUm/vUWAH9molu5qZ3w899VqwROgntAWgr2GMIpihQ3LQBg+4Cd6Rndw==
"@capawesome/capacitor-screen-orientation@^6.0.0":
version "6.0.0"
resolved "https://registry.yarnpkg.com/@capawesome/capacitor-screen-orientation/-/capacitor-screen-orientation-6.0.0.tgz#d9572a5f31923bec147f4c898c62486ba11831f5"
integrity sha512-zVYMH/lcFNfjlfBUwheG5zSJkX9BE608p+Pxik1Talc6T7Iu2O0ivZKfMJP6f1WMmd54yD54mbsKkJ+uj0ZYtg==

"@colors/[email protected]":
version "1.5.0"
Expand Down

0 comments on commit 7831cc2

Please sign in to comment.