Fix inconsistent android rotate
This commit is contained in:
@@ -154,6 +154,49 @@
|
||||
}
|
||||
}
|
||||
|
||||
async function onAndroidFullscreenChange() {
|
||||
const videoFormats = data.video.adaptiveFormats.filter((format) =>
|
||||
format.type.startsWith('video/')
|
||||
);
|
||||
|
||||
const isFullScreen = !!document.fullscreenElement;
|
||||
|
||||
if (isFullScreen) {
|
||||
// Ensure bar color is black while in fullscreen
|
||||
await SafeArea.enable({
|
||||
config: {
|
||||
customColorsForSystemBars: true,
|
||||
statusBarColor: '#00000000',
|
||||
statusBarContent: 'light',
|
||||
navigationBarColor: '#00000000',
|
||||
navigationBarContent: 'light'
|
||||
}
|
||||
});
|
||||
} else {
|
||||
await setStatusBarColor();
|
||||
}
|
||||
|
||||
if (!$playerAndroidLockOrientation) return;
|
||||
|
||||
console.log(videoFormats[0]);
|
||||
|
||||
if (isFullScreen && videoFormats[0].resolution) {
|
||||
const widthHeight = videoFormats[0].resolution.split('x');
|
||||
|
||||
if (widthHeight.length !== 2) return;
|
||||
|
||||
if (Number(widthHeight[0]) > Number(widthHeight[1])) {
|
||||
await ScreenOrientation.lock({ orientation: 'landscape' });
|
||||
} else {
|
||||
await ScreenOrientation.lock({ orientation: 'portrait' });
|
||||
}
|
||||
} else {
|
||||
await ScreenOrientation.lock({
|
||||
orientation: (originalOrigination as ScreenOrientationResult).type
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function androidHandleRotate() {
|
||||
if (
|
||||
Capacitor.getPlatform() !== 'android' ||
|
||||
@@ -162,55 +205,9 @@
|
||||
)
|
||||
return;
|
||||
|
||||
const videoFormats = data.video.adaptiveFormats.filter((format) =>
|
||||
format.type.startsWith('video/')
|
||||
);
|
||||
|
||||
originalOrigination = await ScreenOrientation.orientation();
|
||||
|
||||
document.addEventListener('fullscreenchange', async () => {
|
||||
const isFullScreen = !!document.fullscreenElement;
|
||||
|
||||
console.log('isFullScreen', isFullScreen);
|
||||
|
||||
if (isFullScreen) {
|
||||
// Ensure bar color is black while in fullscreen
|
||||
await SafeArea.enable({
|
||||
config: {
|
||||
customColorsForSystemBars: true,
|
||||
statusBarColor: '#00000000',
|
||||
statusBarContent: 'light',
|
||||
navigationBarColor: '#00000000',
|
||||
navigationBarContent: 'light'
|
||||
}
|
||||
});
|
||||
} else {
|
||||
await setStatusBarColor();
|
||||
}
|
||||
|
||||
if (!$playerAndroidLockOrientation) return;
|
||||
|
||||
console.log(videoFormats[0]);
|
||||
|
||||
if (isFullScreen && videoFormats[0].resolution) {
|
||||
const widthHeight = videoFormats[0].resolution.split('x');
|
||||
|
||||
if (widthHeight.length !== 2) return;
|
||||
|
||||
if (Number(widthHeight[0]) > Number(widthHeight[1])) {
|
||||
console.log('needs to be landscape');
|
||||
await ScreenOrientation.lock({ orientation: 'landscape' });
|
||||
} else {
|
||||
console.log('needs to be portrait');
|
||||
await ScreenOrientation.lock({ orientation: 'portrait' });
|
||||
}
|
||||
} else {
|
||||
console.log('reset to og');
|
||||
await ScreenOrientation.lock({
|
||||
orientation: (originalOrigination as ScreenOrientationResult).type
|
||||
});
|
||||
}
|
||||
});
|
||||
document.addEventListener('fullscreenchange', onAndroidFullscreenChange);
|
||||
}
|
||||
|
||||
async function setupSponsorSkip() {
|
||||
@@ -804,6 +801,8 @@
|
||||
savePlayerPos();
|
||||
} catch (error) {}
|
||||
|
||||
document.removeEventListener('fullscreenchange', onAndroidFullscreenChange);
|
||||
|
||||
Mousetrap.unbind(['left', 'right', 'space', 'c', 'f', 'shift+left', 'shift+right']);
|
||||
|
||||
if (watchProgressTimeout) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { resolve } from '$app/paths';
|
||||
import { instanceStore } from '$lib/store';
|
||||
import { instanceStore, interfaceAndroidUseNativeShare } from '$lib/store';
|
||||
import { Share } from '@capacitor/share';
|
||||
import ui from 'beercss';
|
||||
import { Clipboard } from '@capacitor/clipboard';
|
||||
@@ -20,7 +20,11 @@
|
||||
async function shareUrl(url: string, param: string = 't') {
|
||||
if (includeTimestamp) url += `?${param}=${Math.floor(currentTime ?? 0)}`;
|
||||
|
||||
if ((await Share.canShare()) && Capacitor.getPlatform() !== 'electron') {
|
||||
if (
|
||||
(await Share.canShare()) &&
|
||||
Capacitor.getPlatform() !== 'electron' &&
|
||||
$interfaceAndroidUseNativeShare
|
||||
) {
|
||||
await Share.share({ url: url, dialogTitle: video.title });
|
||||
} else {
|
||||
await Clipboard.write({ string: url });
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
instanceStore,
|
||||
interfaceAllowInsecureRequests,
|
||||
interfaceAmoledTheme,
|
||||
interfaceAndroidUseNativeShare,
|
||||
interfaceAutoExpandChapters,
|
||||
interfaceAutoExpandComments,
|
||||
interfaceAutoExpandDesc,
|
||||
@@ -304,6 +305,25 @@
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
{#if Capacitor.getPlatform() == 'android'}
|
||||
<div class="field no-margin">
|
||||
<nav class="no-padding">
|
||||
<div class="max">
|
||||
<div>{$_('layout.androidNativeShare')}</div>
|
||||
</div>
|
||||
<label class="switch" tabindex="0">
|
||||
<input
|
||||
type="checkbox"
|
||||
bind:checked={$interfaceAndroidUseNativeShare}
|
||||
onclick={() => interfaceAndroidUseNativeShare.set(!$interfaceAndroidUseNativeShare)}
|
||||
role="switch"
|
||||
/>
|
||||
<span></span>
|
||||
</label>
|
||||
</nav>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if Capacitor.getPlatform() == 'electron'}
|
||||
<div class="field no-margin">
|
||||
<nav class="no-padding">
|
||||
@@ -330,7 +350,7 @@
|
||||
bind:value={region}
|
||||
onchange={() => interfaceRegionStore.set(region)}
|
||||
>
|
||||
{#each iso31661 as region}
|
||||
{#each iso31661 as region (region)}
|
||||
<option selected={$interfaceRegionStore === region.alpha2} value={region.alpha2}
|
||||
>{region.alpha2} - {region.name}</option
|
||||
>
|
||||
@@ -348,7 +368,7 @@
|
||||
onchange={() => interfaceForceCase.set(forceCase)}
|
||||
>
|
||||
<option selected={$interfaceForceCase === null} value={null}>Default</option>
|
||||
{#each titleCases as caseType}
|
||||
{#each titleCases as caseType (caseType)}
|
||||
<option selected={$interfaceForceCase === caseType} value={caseType}
|
||||
>{letterCase(`${caseType}`, caseType)}</option
|
||||
>
|
||||
@@ -365,7 +385,7 @@
|
||||
bind:value={defaultPage}
|
||||
onchange={() => interfaceDefaultPage.set(defaultPage)}
|
||||
>
|
||||
{#each pages as page}
|
||||
{#each pages as page (page)}
|
||||
{#if !page.requiresAuth || get(authStore)}
|
||||
<option selected={$interfaceDefaultPage === page.href} value={page.href}>{page.name}</option
|
||||
>
|
||||
|
||||
@@ -158,6 +158,7 @@
|
||||
"expandComments": "Expand comments by default",
|
||||
"allowInsecureRequests": "Allow insecure requests",
|
||||
"disableAutoUpdate": "Disable automatic updates",
|
||||
"androidNativeShare": "Use native share",
|
||||
"player": {
|
||||
"title": "Player",
|
||||
"autoPlay": "Autoplay video",
|
||||
|
||||
@@ -265,6 +265,11 @@ export const interfaceDisableAutoUpdate = persist(
|
||||
createStorage(),
|
||||
'disableAutoUpdate'
|
||||
);
|
||||
export const interfaceAndroidUseNativeShare = persist(
|
||||
writable(true),
|
||||
createStorage(),
|
||||
'androidUseNativeShare'
|
||||
);
|
||||
|
||||
export const sponsorBlockStore = persist(writable(true), createStorage(), 'sponsorBlock');
|
||||
export const sponsorBlockUrlStore: Writable<string | null | undefined> = persist(
|
||||
|
||||
Reference in New Issue
Block a user