Files
mattermostest/src/common/utils/util.ts
Devin Binnie 59e4e7e516 [MM-14058] Add support for i18n (#2190)
* Add language files

* Add react-intl, mmjstool, setup for adding translations

* Translated main module

* Translations for renderer

* A few minor fixes

* More fixes

* Add CI, add missing menu translations, other cleanup

* Added setting to manually select the language of the app

* Force English for E2e

* Unit tests

* Fix mmjstool

* Move set language to before update menu

* PR feedback
2022-07-14 11:04:18 -04:00

73 lines
2.1 KiB
TypeScript

// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
// Copyright (c) 2015-2016 Yuya Ochiai
import {screen} from 'electron';
import {DEVELOPMENT, PRODUCTION} from './constants';
function getDisplayBoundaries() {
const displays = screen.getAllDisplays();
return displays.map((display) => {
return {
maxX: display.workArea.x + display.workArea.width,
maxY: display.workArea.y + display.workArea.height,
minX: display.workArea.x,
minY: display.workArea.y,
maxWidth: display.workArea.width,
maxHeight: display.workArea.height,
};
});
}
function runMode() {
return process.env.NODE_ENV === PRODUCTION ? PRODUCTION : DEVELOPMENT;
}
const DEFAULT_MAX = 20;
function shorten(string: string, max?: number) {
const maxLength = (max && max >= 4) ? max : DEFAULT_MAX;
if (string.length >= maxLength) {
return `${string.slice(0, maxLength - 3)}...`;
}
return string;
}
function isVersionGreaterThanOrEqualTo(currentVersion: string, compareVersion: string): boolean {
if (currentVersion === compareVersion) {
return true;
}
// We only care about the numbers
const currentVersionNumber = (currentVersion || '').split('.').filter((x) => (/^[0-9]+$/).exec(x) !== null);
const compareVersionNumber = (compareVersion || '').split('.').filter((x) => (/^[0-9]+$/).exec(x) !== null);
for (let i = 0; i < Math.max(currentVersionNumber.length, compareVersionNumber.length); i++) {
const currentVersion = parseInt(currentVersionNumber[i], 10) || 0;
const compareVersion = parseInt(compareVersionNumber[i], 10) || 0;
if (currentVersion > compareVersion) {
return true;
}
if (currentVersion < compareVersion) {
return false;
}
}
// If all components are equal, then return true
return true;
}
export function t(s: string) {
return s;
}
export default {
getDisplayBoundaries,
runMode,
shorten,
isVersionGreaterThanOrEqualTo,
};