mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
Chore: Mobile: Migrate shim-init-react to TypeScript (#10731)
This commit is contained in:
parent
668849603d
commit
9ad1249f11
@ -721,6 +721,7 @@ packages/app-mobile/utils/polyfills/bufferPolyfill.js
|
||||
packages/app-mobile/utils/polyfills/index.js
|
||||
packages/app-mobile/utils/setupNotifications.js
|
||||
packages/app-mobile/utils/shareHandler.js
|
||||
packages/app-mobile/utils/shim-init-react.js
|
||||
packages/app-mobile/utils/showMessageBox.js
|
||||
packages/app-mobile/utils/testing/createMockReduxStore.js
|
||||
packages/app-mobile/utils/types.js
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -700,6 +700,7 @@ packages/app-mobile/utils/polyfills/bufferPolyfill.js
|
||||
packages/app-mobile/utils/polyfills/index.js
|
||||
packages/app-mobile/utils/setupNotifications.js
|
||||
packages/app-mobile/utils/shareHandler.js
|
||||
packages/app-mobile/utils/shim-init-react.js
|
||||
packages/app-mobile/utils/showMessageBox.js
|
||||
packages/app-mobile/utils/testing/createMockReduxStore.js
|
||||
packages/app-mobile/utils/types.js
|
||||
|
@ -41,7 +41,7 @@ const { BackButtonService } = require('./services/back-button.js');
|
||||
import NavService from '@joplin/lib/services/NavService';
|
||||
import { createStore, applyMiddleware, Dispatch } from 'redux';
|
||||
import reduxSharedMiddleware from '@joplin/lib/components/shared/reduxSharedMiddleware';
|
||||
const { shimInit } = require('./utils/shim-init-react.js');
|
||||
import shimInit from './utils/shim-init-react';
|
||||
const { AppNav } = require('./components/app-nav.js');
|
||||
import Note from '@joplin/lib/models/Note';
|
||||
import Folder from '@joplin/lib/models/Folder';
|
||||
|
@ -1,18 +1,19 @@
|
||||
const shim = require('@joplin/lib/shim').default;
|
||||
import shim from '@joplin/lib/shim';
|
||||
const { GeolocationReact } = require('./geolocation-react.js');
|
||||
const PoorManIntervals = require('@joplin/lib/PoorManIntervals').default;
|
||||
const RNFetchBlob = require('rn-fetch-blob').default;
|
||||
const { generateSecureRandom } = require('react-native-securerandom');
|
||||
const FsDriverRN = require('./fs-driver/fs-driver-rn').default;
|
||||
const { Buffer } = require('buffer');
|
||||
const { Linking, Platform } = require('react-native');
|
||||
const showMessageBox = require('./showMessageBox.js').default;
|
||||
const mimeUtils = require('@joplin/lib/mime-utils.js');
|
||||
const { basename, fileExtension } = require('@joplin/lib/path-utils');
|
||||
const uuid = require('@joplin/lib/uuid').default;
|
||||
const Resource = require('@joplin/lib/models/Resource').default;
|
||||
const { getLocales } = require('react-native-localize');
|
||||
const { setLocale, defaultLocale, closestSupportedLocale } = require('@joplin/lib/locale');
|
||||
import PoorManIntervals from '@joplin/lib/PoorManIntervals';
|
||||
import RNFetchBlob from 'rn-fetch-blob';
|
||||
import { generateSecureRandom } from 'react-native-securerandom';
|
||||
import FsDriverRN from './fs-driver/fs-driver-rn';
|
||||
import { Buffer } from 'buffer';
|
||||
import { Linking, Platform } from 'react-native';
|
||||
import showMessageBox from './showMessageBox.js';
|
||||
import * as mimeUtils from '@joplin/lib/mime-utils';
|
||||
import { basename, fileExtension } from '@joplin/lib/path-utils';
|
||||
import uuid from '@joplin/lib/uuid';
|
||||
import Resource from '@joplin/lib/models/Resource';
|
||||
import { getLocales } from 'react-native-localize';
|
||||
import { setLocale, defaultLocale, closestSupportedLocale } from '@joplin/lib/locale';
|
||||
import type SettingType from '@joplin/lib/models/Setting';
|
||||
|
||||
const injectedJs = {
|
||||
webviewLib: require('@joplin/lib/rnInjectedJs/webviewLib'),
|
||||
@ -22,7 +23,7 @@ const injectedJs = {
|
||||
noteBodyViewerBundle: require('../lib/rnInjectedJs/noteBodyViewerBundle.bundle'),
|
||||
};
|
||||
|
||||
function shimInit() {
|
||||
export default function shimInit() {
|
||||
shim.Geolocation = GeolocationReact;
|
||||
shim.sjclModule = require('@joplin/lib/vendor/sjcl-rn.js');
|
||||
|
||||
@ -33,7 +34,7 @@ function shimInit() {
|
||||
return shim.fsDriver_;
|
||||
};
|
||||
|
||||
shim.randomBytes = async count => {
|
||||
shim.randomBytes = async (count: number) => {
|
||||
const randomBytes = await generateSecureRandom(count);
|
||||
const temp = [];
|
||||
for (const n in randomBytes) {
|
||||
@ -91,7 +92,7 @@ function shimInit() {
|
||||
|
||||
/* eslint-enable */
|
||||
|
||||
shim.detectAndSetLocale = (Setting) => {
|
||||
shim.detectAndSetLocale = (Setting: typeof SettingType) => {
|
||||
// [
|
||||
// {
|
||||
// "countryCode": "US",
|
||||
@ -179,7 +180,7 @@ function shimInit() {
|
||||
try {
|
||||
const response = await shim.fetchWithRetry(doFetchBlob, options);
|
||||
|
||||
// Returns an object that's roughtly compatible with a standard Response object
|
||||
// Returns an object that's roughly compatible with a standard Response object
|
||||
const output = {
|
||||
ok: response.respInfo.status < 400,
|
||||
path: response.data,
|
||||
@ -212,7 +213,7 @@ function shimInit() {
|
||||
trusty: options.ignoreTlsErrors,
|
||||
}).fetch(method, url, headers, RNFetchBlob.wrap(options.path));
|
||||
|
||||
// Returns an object that's roughtly compatible with a standard Response object
|
||||
// Returns an object that's roughly compatible with a standard Response object
|
||||
return {
|
||||
ok: response.respInfo.status < 400,
|
||||
data: response.data,
|
||||
@ -239,7 +240,7 @@ function shimInit() {
|
||||
shim.showMessageBox = showMessageBox;
|
||||
|
||||
shim.openUrl = url => {
|
||||
Linking.openURL(url);
|
||||
return Linking.openURL(url);
|
||||
};
|
||||
|
||||
shim.httpAgent = () => {
|
||||
@ -247,7 +248,7 @@ function shimInit() {
|
||||
};
|
||||
|
||||
shim.waitForFrame = () => {
|
||||
return new Promise((resolve) => {
|
||||
return new Promise<void>((resolve) => {
|
||||
requestAnimationFrame(() => {
|
||||
resolve();
|
||||
});
|
||||
@ -299,7 +300,7 @@ function shimInit() {
|
||||
|
||||
shim.injectedJs = function(name) {
|
||||
if (!(name in injectedJs)) throw new Error(`Cannot find injectedJs file (add it to "injectedJs" object): ${name}`);
|
||||
return injectedJs[name];
|
||||
return injectedJs[name as keyof typeof injectedJs];
|
||||
};
|
||||
|
||||
shim.setTimeout = (fn, interval) => {
|
||||
@ -320,4 +321,3 @@ function shimInit() {
|
||||
|
||||
}
|
||||
|
||||
module.exports = { shimInit };
|
@ -19,6 +19,13 @@ export interface PdfInfo {
|
||||
pageCount: number;
|
||||
}
|
||||
|
||||
interface FetchOptions {
|
||||
method?: string;
|
||||
headers?: Record<string, string>;
|
||||
body?: string;
|
||||
agent?: unknown;
|
||||
}
|
||||
|
||||
let isTestingEnv_ = false;
|
||||
|
||||
// We need to ensure that there's only one instance of React being used by all
|
||||
@ -239,11 +246,14 @@ const shim = {
|
||||
}
|
||||
},
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
||||
fetch: (_url: string, _options: any = null): any => {
|
||||
fetch: (_url: string, _options: FetchOptions|null = null): Promise<Response> => {
|
||||
throw new Error('Not implemented: fetch');
|
||||
},
|
||||
|
||||
debugFetch: (_url: string, _options: FetchOptions|null): Promise<unknown> => {
|
||||
throw new Error('Not implemented: debugFetch');
|
||||
},
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
||||
fetchText: async (url: string, options: any = null): Promise<string> => {
|
||||
const r = await shim.fetch(url, options || {});
|
||||
|
Loading…
Reference in New Issue
Block a user