#1005 Replace mobile detection method in get sortable delay. Make deviceInfo loading sync. Init Ross mods via function call.

This commit is contained in:
Cohee 2023-08-24 23:52:03 +03:00
parent ce67101651
commit 1900ab9726
6 changed files with 55 additions and 52 deletions

View File

@ -1,4 +1,4 @@
import { humanizedDateTime, favsToHotswap, getMessageTimeStamp, dragElement, isMobile, } from "./scripts/RossAscends-mods.js";
import { humanizedDateTime, favsToHotswap, getMessageTimeStamp, dragElement, isMobile, initRossMods, } from "./scripts/RossAscends-mods.js";
import { userStatsHandler, statMesProcess } from './scripts/stats.js';
import {
generateKoboldWithStreaming,
@ -156,7 +156,7 @@ import {
import { EventEmitter } from './lib/eventemitter.js';
import { markdownExclusionExt } from "./scripts/showdown-exclusion.js";
import { NOTE_MODULE_NAME, metadata_keys, setFloatingPrompt, shouldWIAddPrompt } from "./scripts/authors-note.js";
import { deviceInfo } from "./scripts/RossAscends-mods.js";
import { getDeviceInfo } from "./scripts/RossAscends-mods.js";
import { registerPromptManagerMigration } from "./scripts/PromptManager.js";
import { getRegexedString, regex_placement } from "./scripts/extensions/regex/engine.js";
import { FILTER_TYPES, FilterHelper } from "./scripts/filters.js";
@ -6293,6 +6293,7 @@ function openCharacterWorldPopup() {
template.find('.character_name').text(name);
// Not needed on mobile
const deviceInfo = getDeviceInfo();
if (deviceInfo && deviceInfo.device.type === 'desktop') {
$(extraSelect).select2({
width: '100%',
@ -6337,18 +6338,6 @@ function openCharacterWorldPopup() {
return;
}
/*let selectScrollTop = null;
if (deviceInfo && deviceInfo.device.type === 'desktop') {
e.preventDefault();
const option = $(e.target);
const selectElement = $(extraSelect)[0];
selectScrollTop = selectElement.scrollTop;
option.prop('selected', !option.prop('selected'));
await delay(1);
selectElement.scrollTop = selectScrollTop;
}*/
onExtraWorldInfoChanged();
});
@ -9022,4 +9011,7 @@ $(document).ready(function () {
$("#hideCharPanelAvatarButton").on('click', () => {
$('#avatar-and-name-block').slideToggle()
});
// Added here to prevent execution before script.js is loaded and get rid of quirky timeouts
initRossMods();
});

View File

@ -98,28 +98,45 @@ export function humanizeGenTime(total_gen_time) {
return time_spent;
}
// Device detection
export const deviceInfo = await getDeviceInfo();
async function getDeviceInfo() {
try {
const deviceInfo = await (await fetch('/deviceinfo')).json();
console.log("Device type: " + deviceInfo?.device?.type);
return deviceInfo;
}
catch {
console.log("Couldn't load device info. Defaulting to desktop");
return { device: { type: 'desktop' } };
}
}
/**
* Checks if the device is a mobile device.
* @returns {boolean} - True if the device is a mobile device, false otherwise.
*/
export function isMobile() {
const mobileTypes = ['smartphone', 'tablet', 'phablet', 'feature phone', 'portable media player'];
const deviceInfo = getDeviceInfo();
return mobileTypes.includes(deviceInfo?.device?.type);
}
/**
* Loads device info from the server. Caches the result in sessionStorage.
* @returns {object} - The device info object.
*/
export function getDeviceInfo() {
let deviceInfo = null;
if (sessionStorage.getItem('deviceInfo')) {
deviceInfo = JSON.parse(sessionStorage.getItem('deviceInfo'));
} else {
$.ajax({
url: '/deviceinfo',
dataType: 'json',
async: false,
cache: true,
success: function (result) {
sessionStorage.setItem('deviceInfo', JSON.stringify(result));
deviceInfo = result;
},
error: function () {
console.log("Couldn't load device info. Defaulting to desktop");
deviceInfo = { device: { type: 'desktop' } };
},
});
}
return deviceInfo;
}
function shouldSendOnEnter() {
if (!power_user) {
return false;
@ -394,8 +411,8 @@ function isUrlOrAPIKey(string) {
}
function OpenNavPanels() {
if (deviceInfo.device.type === 'desktop') {
const deviceInfo = getDeviceInfo();
if (deviceInfo && deviceInfo.device.type === 'desktop') {
//auto-open R nav if locked and previously open
if (LoadLocalBool("NavLockOn") == true && LoadLocalBool("NavOpened") == true) {
//console.log("RA -- clicking right nav to open");
@ -669,13 +686,7 @@ export async function initMovingUI() {
// ---------------------------------------------------
jQuery(async function () {
try {
await waitUntilCondition(() => online_status !== undefined, 1000, 10);
} catch {
console.log('Timeout waiting for online_status');
}
export function initRossMods() {
// initial status check
setTimeout(() => {
RA_checkOnlineStatus();
@ -1070,4 +1081,4 @@ jQuery(async function () {
console.log("Ctrl +" + event.key + " pressed!");
}
}
});
}

View File

@ -699,10 +699,8 @@ async function runGenerationInterceptors(chat, contextSize) {
}
jQuery(function () {
setTimeout(async function () {
addExtensionsButtonAndMenu();
$("#extensionsMenuButton").css("display", "flex");
}, 100)
addExtensionsButtonAndMenu();
$("#extensionsMenuButton").css("display", "flex");
$("#extensions_connect").on('click', connectClickHandler);
$("#extensions_autoconnect").on('input', autoConnectInputHandler);

View File

@ -7,8 +7,7 @@ import {
} from "../script.js";
import { SECRET_KEYS, writeSecret } from "./secrets.js";
import { delay } from "./utils.js";
import { deviceInfo } from "./RossAscends-mods.js";
import { power_user } from "./power-user.js";
import { getDeviceInfo } from "./RossAscends-mods.js";
import { autoSelectInstructPreset } from "./instruct-mode.js";
export {
@ -259,7 +258,8 @@ jQuery(function () {
$("#horde_kudos").on("click", showKudos);
// Not needed on mobile
if (deviceInfo.device.type === 'desktop') {
const deviceInfo = getDeviceInfo();
if (deviceInfo && deviceInfo.device.type === 'desktop') {
$('#horde_model').select2({
width: '100%',
placeholder: 'Select Horde models',

View File

@ -1,5 +1,6 @@
import { getContext } from "./extensions.js";
import { getRequestHeaders } from "../script.js";
import { isMobile } from "./RossAscends-mods.js";
/**
* Pagination status string template.
@ -38,10 +39,10 @@ export function isDigitsOnly(str) {
/**
* Gets a drag delay for sortable elements. This is to prevent accidental drags when scrolling.
* @returns {number} The delay in milliseconds. 100ms for desktop, 750ms for mobile.
* @returns {number} The delay in milliseconds. 50ms for desktop, 750ms for mobile.
*/
export function getSortableDelay() {
return navigator.maxTouchPoints > 0 ? 750 : 100;
return isMobile() ? 750 : 50;
}
/**

View File

@ -3,7 +3,7 @@ import { download, debounce, initScrollHeight, resetScrollHeight, parseJsonFile,
import { getContext } from "./extensions.js";
import { NOTE_MODULE_NAME, metadata_keys, shouldWIAddPrompt } from "./authors-note.js";
import { registerSlashCommand } from "./slash-commands.js";
import { deviceInfo } from "./RossAscends-mods.js";
import { getDeviceInfo } from "./RossAscends-mods.js";
import { FILTER_TYPES, FilterHelper } from "./filters.js";
import { getTokenCount } from "./tokenizers.js";
@ -1621,7 +1621,8 @@ jQuery(() => {
});
// Not needed on mobile
if (deviceInfo.device.type === 'desktop') {
const deviceInfo = getDeviceInfo();
if (deviceInfo && deviceInfo.device.type === 'desktop') {
$('#world_info').select2({
width: '100%',
placeholder: 'No Worlds active. Click here to select.',