Add:Device setting for locking screen orientation #449

This commit is contained in:
advplyr 2022-12-04 10:41:09 -06:00
parent af216d9b38
commit 9687f47b6b
12 changed files with 100 additions and 7 deletions

View file

@ -6,6 +6,10 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonSubTypes import com.fasterxml.jackson.annotation.JsonSubTypes
import com.fasterxml.jackson.annotation.JsonTypeInfo import com.fasterxml.jackson.annotation.JsonTypeInfo
enum class LockOrientationSetting {
NONE, PORTRAIT, LANDSCAPE
}
data class ServerConnectionConfig( data class ServerConnectionConfig(
var id:String, var id:String,
var index:Int, var index:Int,
@ -22,7 +26,8 @@ data class DeviceSettings(
var enableAltView:Boolean, var enableAltView:Boolean,
var jumpBackwardsTime:Int, var jumpBackwardsTime:Int,
var jumpForwardTime:Int, var jumpForwardTime:Int,
var disableShakeToResetSleepTimer:Boolean var disableShakeToResetSleepTimer:Boolean,
var lockOrientation:LockOrientationSetting
) { ) {
companion object { companion object {
// Static method to get default device settings // Static method to get default device settings
@ -32,7 +37,8 @@ data class DeviceSettings(
enableAltView = false, enableAltView = false,
jumpBackwardsTime = 10, jumpBackwardsTime = 10,
jumpForwardTime = 10, jumpForwardTime = 10,
disableShakeToResetSleepTimer = false disableShakeToResetSleepTimer = false,
lockOrientation = LockOrientationSetting.NONE
) )
} }
} }

View file

@ -2,5 +2,9 @@
<widget version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0"> <widget version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<access origin="*" /> <access origin="*" />
<feature name="CDVOrientation">
<param name="android-package" value="cordova.plugins.screenorientation.CDVOrientation"/>
</feature>
</widget> </widget>

View file

@ -2,5 +2,9 @@
<widget version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0"> <widget version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<access origin="*" /> <access origin="*" />
<feature name="CDVOrientation">
<param name="ios-package" value="CDVOrientation"/>
</feature>
</widget> </widget>

View file

@ -236,11 +236,13 @@ public class AbsDatabase: CAPPlugin {
let enableAltView = call.getBool("enableAltView") ?? false let enableAltView = call.getBool("enableAltView") ?? false
let jumpBackwardsTime = call.getInt("jumpBackwardsTime") ?? 10 let jumpBackwardsTime = call.getInt("jumpBackwardsTime") ?? 10
let jumpForwardTime = call.getInt("jumpForwardTime") ?? 10 let jumpForwardTime = call.getInt("jumpForwardTime") ?? 10
let lockOrientation call.getString("lockOrientation") ?? "NONE"
let settings = DeviceSettings() let settings = DeviceSettings()
settings.disableAutoRewind = disableAutoRewind settings.disableAutoRewind = disableAutoRewind
settings.enableAltView = enableAltView settings.enableAltView = enableAltView
settings.jumpBackwardsTime = jumpBackwardsTime settings.jumpBackwardsTime = jumpBackwardsTime
settings.jumpForwardTime = jumpForwardTime settings.jumpForwardTime = jumpForwardTime
settings.lockOrientation = LockOrientationSetting(rawValue: lockOrientation)
Database.shared.setDeviceSettings(deviceSettings: settings) Database.shared.setDeviceSettings(deviceSettings: settings)

View file

@ -15,6 +15,7 @@ def capacitor_pods
pod 'CapacitorNetwork', :path => '..\..\node_modules\@capacitor\network' pod 'CapacitorNetwork', :path => '..\..\node_modules\@capacitor\network'
pod 'CapacitorStatusBar', :path => '..\..\node_modules\@capacitor\status-bar' pod 'CapacitorStatusBar', :path => '..\..\node_modules\@capacitor\status-bar'
pod 'CapacitorStorage', :path => '..\..\node_modules\@capacitor\storage' pod 'CapacitorStorage', :path => '..\..\node_modules\@capacitor\storage'
pod 'CordovaPlugins', :path => '../capacitor-cordova-ios-plugins'
end end
target 'Audiobookshelf' do target 'Audiobookshelf' do

View file

@ -8,11 +8,18 @@
import Foundation import Foundation
import RealmSwift import RealmSwift
enum LockOrientationSetting: Codable {
case NONE
case PORTRAIT
case LANDSCAPE
}
class DeviceSettings: Object { class DeviceSettings: Object {
@Persisted var disableAutoRewind: Bool = false @Persisted var disableAutoRewind: Bool = false
@Persisted var enableAltView: Bool = false @Persisted var enableAltView: Bool = false
@Persisted var jumpBackwardsTime: Int = 10 @Persisted var jumpBackwardsTime: Int = 10
@Persisted var jumpForwardTime: Int = 10 @Persisted var jumpForwardTime: Int = 10
@Persisted var lockOrientation: LockOrientationSetting = LockOrientationSetting.NONE
} }
func getDefaultDeviceSettings() -> DeviceSettings { func getDefaultDeviceSettings() -> DeviceSettings {
@ -24,6 +31,7 @@ func deviceSettingsToJSON(settings: DeviceSettings) -> Dictionary<String, Any> {
"disableAutoRewind": settings.disableAutoRewind, "disableAutoRewind": settings.disableAutoRewind,
"enableAltView": settings.enableAltView, "enableAltView": settings.enableAltView,
"jumpBackwardsTime": settings.jumpBackwardsTime, "jumpBackwardsTime": settings.jumpBackwardsTime,
"jumpForwardTime": settings.jumpForwardTime "jumpForwardTime": settings.jumpForwardTime,
"lockOrientation": settings.lockOrientation
] ]
} }

View file

@ -262,6 +262,7 @@ export default {
const deviceData = await this.$db.getDeviceData() const deviceData = await this.$db.getDeviceData()
this.$store.commit('setDeviceData', deviceData) this.$store.commit('setDeviceData', deviceData)
this.$setOrientationLock(this.$store.getters['getOrientationLockSetting'])
await this.$store.dispatch('setupNetworkListener') await this.$store.dispatch('setupNetworkListener')

20
package-lock.json generated
View file

@ -19,6 +19,7 @@
"@capacitor/status-bar": "^1.0.8", "@capacitor/status-bar": "^1.0.8",
"@capacitor/storage": "^1.2.5", "@capacitor/storage": "^1.2.5",
"@nuxtjs/axios": "^5.13.6", "@nuxtjs/axios": "^5.13.6",
"cordova-plugin-screen-orientation": "^3.0.2",
"core-js": "^3.15.1", "core-js": "^3.15.1",
"date-fns": "^2.25.0", "date-fns": "^2.25.0",
"epubjs": "^0.3.88", "epubjs": "^0.3.88",
@ -5739,6 +5740,18 @@
"node": ">=0.10.0" "node": ">=0.10.0"
} }
}, },
"node_modules/cordova-plugin-screen-orientation": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/cordova-plugin-screen-orientation/-/cordova-plugin-screen-orientation-3.0.2.tgz",
"integrity": "sha512-2w6CMC+HGvbhogJetalwGurL2Fx8DQCCPy3wlSZHN1/W7WoQ5n9ujVozcoKrY4VaagK6bxrPFih+ElkO8Uqfzg==",
"engines": {
"cordovaDependencies": {
"4.0.0": {
"cordova": ">100"
}
}
}
},
"node_modules/core-js": { "node_modules/core-js": {
"version": "3.21.1", "version": "3.21.1",
"resolved": "https://registry.npmjs.org/core-js/-/core-js-3.21.1.tgz", "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.21.1.tgz",
@ -23058,6 +23071,11 @@
"resolved": "https://registry.npmjs.org/copy-descriptor/-/copy-descriptor-0.1.1.tgz", "resolved": "https://registry.npmjs.org/copy-descriptor/-/copy-descriptor-0.1.1.tgz",
"integrity": "sha1-Z29us8OZl8LuGsOpJP1hJHSPV40=" "integrity": "sha1-Z29us8OZl8LuGsOpJP1hJHSPV40="
}, },
"cordova-plugin-screen-orientation": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/cordova-plugin-screen-orientation/-/cordova-plugin-screen-orientation-3.0.2.tgz",
"integrity": "sha512-2w6CMC+HGvbhogJetalwGurL2Fx8DQCCPy3wlSZHN1/W7WoQ5n9ujVozcoKrY4VaagK6bxrPFih+ElkO8Uqfzg=="
},
"core-js": { "core-js": {
"version": "3.21.1", "version": "3.21.1",
"resolved": "https://registry.npmjs.org/core-js/-/core-js-3.21.1.tgz", "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.21.1.tgz",
@ -32982,4 +33000,4 @@
"integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==" "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q=="
} }
} }
} }

View file

@ -23,6 +23,7 @@
"@capacitor/status-bar": "^1.0.8", "@capacitor/status-bar": "^1.0.8",
"@capacitor/storage": "^1.2.5", "@capacitor/storage": "^1.2.5",
"@nuxtjs/axios": "^5.13.6", "@nuxtjs/axios": "^5.13.6",
"cordova-plugin-screen-orientation": "^3.0.2",
"core-js": "^3.15.1", "core-js": "^3.15.1",
"date-fns": "^2.25.0", "date-fns": "^2.25.0",
"epubjs": "^0.3.88", "epubjs": "^0.3.88",
@ -38,4 +39,4 @@
"@nuxtjs/tailwindcss": "^4.2.0", "@nuxtjs/tailwindcss": "^4.2.0",
"postcss": "^8.3.5" "postcss": "^8.3.5"
} }
} }

View file

@ -7,6 +7,12 @@
</div> </div>
<p class="pl-4">Alternative bookshelf view</p> <p class="pl-4">Alternative bookshelf view</p>
</div> </div>
<div class="flex items-center py-3" @click.stop="toggleLockOrientation">
<div class="w-10 flex justify-center">
<ui-toggle-switch v-model="lockCurrentOrientation" @input="saveSettings" />
</div>
<p class="pl-4">Lock orientation</p>
</div>
<p class="uppercase text-xs font-semibold text-gray-300 mb-2 mt-6">Playback Settings</p> <p class="uppercase text-xs font-semibold text-gray-300 mb-2 mt-6">Playback Settings</p>
<div v-if="!isiOS" class="flex items-center py-3" @click="toggleDisableAutoRewind"> <div v-if="!isiOS" class="flex items-center py-3" @click="toggleDisableAutoRewind">
@ -51,14 +57,16 @@ export default {
enableAltView: false, enableAltView: false,
jumpForwardTime: 10, jumpForwardTime: 10,
jumpBackwardsTime: 10, jumpBackwardsTime: 10,
disableShakeToResetSleepTimer: false disableShakeToResetSleepTimer: false,
lockOrientation: 0
}, },
settingInfo: { settingInfo: {
disableShakeToResetSleepTimer: { disableShakeToResetSleepTimer: {
name: 'Disable shake to reset sleep timer', name: 'Disable shake to reset sleep timer',
message: 'The sleep timer will start fading out when 30s is remaining. Shaking your device will reset the timer if it is within 30s OR has finished less than 2 mintues ago. Enable this setting to disable that feature.' message: 'The sleep timer will start fading out when 30s is remaining. Shaking your device will reset the timer if it is within 30s OR has finished less than 2 mintues ago. Enable this setting to disable that feature.'
} }
} },
lockCurrentOrientation: false
} }
}, },
computed: { computed: {
@ -107,6 +115,28 @@ export default {
this.settings.enableAltView = !this.settings.enableAltView this.settings.enableAltView = !this.settings.enableAltView
this.saveSettings() this.saveSettings()
}, },
getCurrentOrientation() {
const orientation = window.screen ? window.screen.orientation || {} : {}
const type = orientation.type || ''
console.log('getCurrentOrientation=' + type)
if (type.includes('landscape')) return 'LANDSCAPE'
return 'PORTRAIT' // default
},
toggleLockOrientation() {
console.log('TOGGLE LOCK ORIENTATION', this.lockCurrentOrientation)
this.lockCurrentOrientation = !this.lockCurrentOrientation
if (this.lockCurrentOrientation) {
console.log('CURRENT ORIENTATION=', this.getCurrentOrientation())
this.settings.lockOrientation = this.getCurrentOrientation()
} else {
console.log('SETTING CURRENT ORIENTATION TO NONE')
this.settings.lockOrientation = 'NONE'
}
this.$setOrientationLock(this.settings.lockOrientation)
console.log('NOW SAVING SETTINGS', this.settings.lockOrientation)
this.saveSettings()
},
toggleJumpForward() { toggleJumpForward() {
var next = (this.currentJumpForwardTimeIndex + 1) % 3 var next = (this.currentJumpForwardTimeIndex + 1) % 3
this.settings.jumpForwardTime = this.jumpForwardItems[next].value this.settings.jumpForwardTime = this.jumpForwardItems[next].value
@ -136,6 +166,10 @@ export default {
this.settings.jumpForwardTime = deviceSettings.jumpForwardTime || 10 this.settings.jumpForwardTime = deviceSettings.jumpForwardTime || 10
this.settings.jumpBackwardsTime = deviceSettings.jumpBackwardsTime || 10 this.settings.jumpBackwardsTime = deviceSettings.jumpBackwardsTime || 10
this.settings.disableShakeToResetSleepTimer = !!deviceSettings.disableShakeToResetSleepTimer this.settings.disableShakeToResetSleepTimer = !!deviceSettings.disableShakeToResetSleepTimer
this.settings.lockOrientation = deviceSettings.lockOrientation || 'NONE'
console.log('INIT SETTINGS LOCK ORIENTATION=', this.settings.lockOrientation)
this.lockCurrentOrientation = this.settings.lockOrientation !== 'NONE'
} }
}, },
mounted() { mounted() {

View file

@ -156,6 +156,16 @@ Vue.prototype.$encode = encode
const decode = (text) => Buffer.from(decodeURIComponent(text), 'base64').toString() const decode = (text) => Buffer.from(decodeURIComponent(text), 'base64').toString()
Vue.prototype.$decode = decode Vue.prototype.$decode = decode
Vue.prototype.$setOrientationLock = (orientationLockSetting) => {
if (orientationLockSetting == 'PORTRAIT') {
window.screen.orientation.lock('portrait')
} else if (orientationLockSetting == 'LANDSCAPE') {
window.screen.orientation.lock('landscape')
} else {
window.screen.orientation.unlock()
}
}
export default ({ store, app }) => { export default ({ store, app }) => {
// iOS Only // iOS Only
// backButton event does not work with iOS swipe navigation so use this workaround // backButton event does not work with iOS swipe navigation so use this workaround

View file

@ -52,6 +52,10 @@ export const getters = {
getAltViewEnabled: state => { getAltViewEnabled: state => {
if (!state.deviceData || !state.deviceData.deviceSettings) return false if (!state.deviceData || !state.deviceData.deviceSettings) return false
return state.deviceData.deviceSettings.enableAltView return state.deviceData.deviceSettings.enableAltView
},
getOrientationLockSetting: state => {
if (!state.deviceData || !state.deviceData.deviceSettings) return false
return state.deviceData.deviceSettings.lockOrientation
} }
} }