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