diff --git a/package.json b/package.json index 4fe8e6f41..e1ccda897 100644 --- a/package.json +++ b/package.json @@ -215,10 +215,11 @@ "afterSign": "build/notarize.js", "afterPack": "build/afterPackHook.js", "artifactName": "${name}-${os}-${arch}-${version}.${ext}", - "extraResources": { + "extraResources": [{ "from": "./build/launcher-script.sh", "to": "./launcher-script.sh" }, + "mmdb/GeoLite2-Country.mmdb"], "mac": { "category": "public.app-category.social-networking", "icon": "build/icon-mac.icns", @@ -350,9 +351,6 @@ "!node_modules/libsession_util_nodejs/src/*", "ts/webworker/workers/node/libsession/*.node", "!dev-app-update.yml" - ], - "extraFiles": [ - "mmdb/GeoLite2-Country.mmdb" ] } } diff --git a/ts/components/dialog/OnionStatusPathDialog.tsx b/ts/components/dialog/OnionStatusPathDialog.tsx index 4fcf42f78..08161c007 100644 --- a/ts/components/dialog/OnionStatusPathDialog.tsx +++ b/ts/components/dialog/OnionStatusPathDialog.tsx @@ -5,7 +5,9 @@ import { useDispatch } from 'react-redux'; import useHover from 'react-use/lib/useHover'; import styled from 'styled-components'; +import { isEmpty, isTypedArray } from 'lodash'; import { CityResponse, Reader } from 'maxmind'; +import { useMount } from 'react-use'; import { Snode } from '../../data/data'; import { onionPathModal } from '../../state/ducks/modalDialog'; import { @@ -16,8 +18,6 @@ import { } from '../../state/selectors/onions'; import { Flex } from '../basic/Flex'; -import { isEmpty, isTypedArray } from 'lodash'; -import { useMount } from 'react-use'; import { SessionWrapperModal } from '../SessionWrapperModal'; import { SessionSpinner } from '../basic/SessionSpinner'; import { SessionIcon, SessionIconButton } from '../icon'; @@ -78,7 +78,6 @@ const OnionCountryDisplay = ({ labelText, snodeIp }: { snodeIp?: string; labelTe }; let reader: Reader<CityResponse> | null; -const lang = 'en'; const OnionPathModalInner = () => { const onionPath = useFirstOnionPath(); @@ -89,7 +88,7 @@ const OnionPathModalInner = () => { const glowDuration = onionPath.length + 2; useMount(() => { - ipcRenderer.once('load-maxmind-data-reply', (_event, content) => { + ipcRenderer.once('load-maxmind-data-complete', (_event, content) => { const asArrayBuffer = content as Uint8Array; if (asArrayBuffer && isTypedArray(asArrayBuffer) && !isEmpty(asArrayBuffer)) { reader = new Reader<CityResponse>(Buffer.from(asArrayBuffer.buffer)); @@ -136,8 +135,16 @@ const OnionPathModalInner = () => { </StyledLightsContainer> <Flex container={true} flexDirection="column" alignItems="flex-start"> {nodes.map((snode: Snode | any) => { + const country = reader?.get(snode.ip || '0.0.0.0')?.country; + const locale = (window.i18n as any).getLocale() as string; + + // typescript complains that the [] operator cannot be used with the 'string' coming from getLocale() + const countryNamesAsAny = country?.names as any; const countryName = - reader?.get(snode.ip || '0.0.0.0')?.country?.names[lang] || + snode.label || // to take care of the "Device" case + countryNamesAsAny?.[locale] || // try to find the country name based on the user local first + // eslint-disable-next-line dot-notation + countryNamesAsAny?.['en'] || // if not found, fallback to the country in english window.i18n('unknownCountry'); return ( diff --git a/ts/mains/main_node.ts b/ts/mains/main_node.ts index fecd495bb..2b62f04e6 100644 --- a/ts/mains/main_node.ts +++ b/ts/mains/main_node.ts @@ -1077,12 +1077,14 @@ ipc.on('close-debug-log', () => { ipc.on('save-debug-log', saveDebugLog); ipc.on('load-maxmind-data', async (event: IpcMainEvent) => { try { - const appRoot = app.isPackaged ? process.resourcesPath : app.getAppPath(); + const appRoot = + app.isPackaged && process.resourcesPath ? process.resourcesPath : app.getAppPath(); const fileToRead = path.join(appRoot, 'mmdb', 'GeoLite2-Country.mmdb'); + console.info(`loading maxmind data from file:"${fileToRead}"`); const buffer = await readFile(fileToRead); - event.reply('load-maxmind-data-reply', new Uint8Array(buffer.buffer)); + event.reply('load-maxmind-data-complete', new Uint8Array(buffer.buffer)); } catch (e) { - event.reply('load-maxmind-data-reply', null); + event.reply('load-maxmind-data-complete', null); } }); diff --git a/yarn.lock b/yarn.lock index 3d97f8ba5..c66931ebc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5363,13 +5363,13 @@ matcher@^3.0.0: dependencies: escape-string-regexp "^4.0.0" -maxmind@^4.3.6: - version "4.3.16" - resolved "https://registry.yarnpkg.com/maxmind/-/maxmind-4.3.16.tgz#2bc0cef9e55f439933a256d14ac731fcfe1819b4" - integrity sha512-bfmiULzt9vO3tZ0SvQOX6cMZMqPCWtncbtNUefeSspoScf8S7n6qB66uOFQN00IWaJUr9oLjtlx3d6M8/KatuQ== +maxmind@^4.3.18: + version "4.3.18" + resolved "https://registry.yarnpkg.com/maxmind/-/maxmind-4.3.18.tgz#ad83f38d718ca5395c5d722933a109b7cb009226" + integrity sha512-5b9utU7ZxcGYTBaO7hCF0FXyfw3IpankLn+FnLW4RZS1zi97RBeSdfXJFJlk5UxNsMiFZlsdMT3lzvD+bD8MLQ== dependencies: - mmdb-lib "2.0.2" - tiny-lru "11.2.3" + mmdb-lib "2.1.0" + tiny-lru "11.2.5" mdn-data@2.0.14: version "2.0.14" @@ -5541,10 +5541,10 @@ mkdirp@~0.5.1: dependencies: minimist "^1.2.6" -mmdb-lib@2.0.2: - version "2.0.2" - resolved "https://registry.yarnpkg.com/mmdb-lib/-/mmdb-lib-2.0.2.tgz#fe60404142c0456c19607c72caa15821731ae957" - integrity sha512-shi1I+fCPQonhTi7qyb6hr7hi87R7YS69FlfJiMFuJ12+grx0JyL56gLNzGTYXPU7EhAPkMLliGeyHer0K+AVA== +mmdb-lib@2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/mmdb-lib/-/mmdb-lib-2.1.0.tgz#c2456caaf4c7ffa056f77575da6d40988e9e878b" + integrity sha512-tdDTZmnI5G4UoSctv2KxM/3VQt2XRj4CmR5R4VsAWsOUcS3LysHR34wtixWm/pXxXdkBDuN92auxkC0T2+qd1Q== mocha@10.0.0: version "10.0.0" @@ -7516,10 +7516,10 @@ through2@^4.0.0: resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5" integrity sha512-w89qg7PI8wAdvX60bMDP+bFoD5Dvhm9oLheFp5O4a2QF0cSBGsBX4qZmadPMvVqlLJBBci+WqGGOAPvcDeNSVg== -tiny-lru@11.2.3: - version "11.2.3" - resolved "https://registry.yarnpkg.com/tiny-lru/-/tiny-lru-11.2.3.tgz#9dc04c9bd48b1e196e999e11eee71bc249466145" - integrity sha512-mF9jPTrvN7UHk0bekOk3RlFdFwfyS4CJYVsGc7nInL3pVgUCYj5r9X6GpZBFQgLr0TKJo8Dp+F3oRvYzxU9xiA== +tiny-lru@11.2.5: + version "11.2.5" + resolved "https://registry.yarnpkg.com/tiny-lru/-/tiny-lru-11.2.5.tgz#b138b99022aa26c567fa51a8dbf9e3e2959b2b30" + integrity sha512-JpqM0K33lG6iQGKiigcwuURAKZlq6rHXfrgeL4/I8/REoyJTGU+tEMszvT/oTRVHG2OiylhGDjqPp1jWMlr3bw== tmp-promise@^3.0.2: version "3.0.3"