Port Settings
and OS
to TypeScript
This commit is contained in:
parent
38b23c6627
commit
a102016ed8
6 changed files with 36 additions and 23 deletions
|
@ -1,7 +0,0 @@
|
|||
/* eslint-env node */
|
||||
|
||||
exports.isMacOS = () => process.platform === 'darwin';
|
||||
|
||||
exports.isLinux = () => process.platform === 'linux';
|
||||
|
||||
exports.isWindows = () => process.platform === 'win32';
|
|
@ -1,3 +0,0 @@
|
|||
const OS = require('../os');
|
||||
|
||||
exports.isAudioNotificationSupported = () => !OS.isLinux();
|
|
@ -200,7 +200,7 @@ window.Signal.Migrations.Migrations1DatabaseWithoutAttachmentData = require('./j
|
|||
|
||||
window.Signal.Migrations.upgradeMessageSchema = upgradeMessageSchema;
|
||||
window.Signal.Notifications = require('./ts/notifications');
|
||||
window.Signal.OS = require('./js/modules/os');
|
||||
window.Signal.OS = require('./ts/OS');
|
||||
window.Signal.Settings = require('./js/modules/settings');
|
||||
window.Signal.Startup = require('./js/modules/startup');
|
||||
|
||||
|
@ -211,7 +211,7 @@ window.Signal.Types.Errors = require('./js/modules/types/errors');
|
|||
|
||||
window.Signal.Types.Message = Message;
|
||||
window.Signal.Types.MIME = require('./ts/types/MIME');
|
||||
window.Signal.Types.Settings = require('./js/modules/types/settings');
|
||||
window.Signal.Types.Settings = require('./ts/types/Settings');
|
||||
window.Signal.Util = require('./ts/util');
|
||||
|
||||
window.Signal.Views = {};
|
||||
|
|
15
ts/OS.ts
Normal file
15
ts/OS.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
import is from '@sindresorhus/is';
|
||||
import os from 'os';
|
||||
import semver from 'semver';
|
||||
|
||||
export const isMacOS = () => process.platform === 'darwin';
|
||||
export const isLinux = () => process.platform === 'linux';
|
||||
export const isWindows = (minVersion?: string) => {
|
||||
const isPlatformValid = process.platform === 'win32';
|
||||
const osRelease = os.release();
|
||||
const isVersionValid = is.undefined(minVersion)
|
||||
? true
|
||||
: semver.gte(osRelease, minVersion);
|
||||
|
||||
return isPlatformValid && isVersionValid;
|
||||
};
|
|
@ -1,7 +1,8 @@
|
|||
const sinon = require('sinon');
|
||||
const { assert } = require('chai');
|
||||
import os from 'os';
|
||||
import sinon from 'sinon';
|
||||
import { assert } from 'chai';
|
||||
|
||||
const Settings = require('../../../js/modules/types/settings');
|
||||
import * as Settings from '../../../ts/types/Settings';
|
||||
|
||||
describe('Settings', () => {
|
||||
const sandbox = sinon.createSandbox();
|
||||
|
@ -22,16 +23,19 @@ describe('Settings', () => {
|
|||
});
|
||||
|
||||
context('on Windows', () => {
|
||||
beforeEach(() => {
|
||||
sandbox.stub(process, 'platform').value('win32');
|
||||
});
|
||||
context('version 8+', () => {
|
||||
beforeEach(() => {
|
||||
sandbox.stub(process, 'platform').value('win32');
|
||||
sandbox.stub(os, 'release').returns('8.0.0');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
sandbox.restore();
|
||||
});
|
||||
afterEach(() => {
|
||||
sandbox.restore();
|
||||
});
|
||||
|
||||
it('should return true', () => {
|
||||
assert.isTrue(Settings.isAudioNotificationSupported());
|
||||
it('should return true', () => {
|
||||
assert.isTrue(Settings.isAudioNotificationSupported());
|
||||
});
|
||||
});
|
||||
});
|
||||
|
4
ts/types/Settings.ts
Normal file
4
ts/types/Settings.ts
Normal file
|
@ -0,0 +1,4 @@
|
|||
import * as OS from '../OS';
|
||||
|
||||
export const isAudioNotificationSupported = () =>
|
||||
OS.isWindows() || OS.isMacOS();
|
Loading…
Add table
Reference in a new issue