Skip to content

Commit

Permalink
fix(utils): use correct mobile detection
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-heimbuch committed Jul 19, 2020
1 parent b61e9a3 commit 3b87286
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
1 change: 0 additions & 1 deletion apps/player/src/components/speed-control/SpeedControl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ export default {
},
methods: {
setRate() {
console.log(this.nextRate)
store.dispatch(setRate(this.nextRate))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export default {
toHumanTime,
selectEpisode() {
console.log(this.episode)
if (!this.episode.active) {
return store.dispatch(selectEpisode({ index: this.index, play: true }))
}
Expand Down
14 changes: 8 additions & 6 deletions packages/utils/useragent.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
import MobileDetect from 'mobile-detect'

export const getPlatform = () => {
let platf = window.navigator.platform.toLowerCase()
const device = new MobileDetect(window.navigator.userAgent)

if (platf.match(/mac/i) !== null) {
if (device.match('mac')) {
return 'osx'
}

if (platf.match(/(ipod|ipad|iphone)/i) !== null) {
if (device.match('ipod|ipad|iphone')) {
return 'ios'
}

if (platf.match(/android/i) !== null) {
if (device.match('android')) {
return 'android'
}

if (platf.match(/(linux|openbsd|freebsd|netbsd)/i) !== null) {
if (device.match('linux|openbsd|freebsd|netbsd')) {
return 'unix'
}

if (platf.match(/(windows|win)/i) !== null) {
if (device.match('windows|win')) {
return 'windows'
}
}
10 changes: 5 additions & 5 deletions packages/utils/useragent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const platforms = {
platforms.osx.forEach(el => {
describe('Test getPlatform on osx', () => {
beforeEach(() => {
Object.defineProperty(window.navigator, 'platform', {
Object.defineProperty(window.navigator, 'userAgent', {
writable: true,
value: el
})
Expand All @@ -25,7 +25,7 @@ platforms.osx.forEach(el => {
platforms.ios.forEach(el => {
describe('Test getPlatform on ios', () => {
beforeEach(() => {
Object.defineProperty(window.navigator, 'platform', {
Object.defineProperty(window.navigator, 'userAgent', {
writable: true,
value: el
})
Expand All @@ -38,7 +38,7 @@ platforms.ios.forEach(el => {
platforms.android.forEach(el => {
describe('Test getPlatform on android', () => {
beforeEach(() => {
Object.defineProperty(window.navigator, 'platform', {
Object.defineProperty(window.navigator, 'userAgent', {
writable: true,
value: el
})
Expand All @@ -51,7 +51,7 @@ platforms.android.forEach(el => {
platforms.unix.forEach(el => {
describe('Test getPlatform on unix', () => {
beforeEach(() => {
Object.defineProperty(window.navigator, 'platform', {
Object.defineProperty(window.navigator, 'userAgent', {
writable: true,
value: el
})
Expand All @@ -64,7 +64,7 @@ platforms.unix.forEach(el => {
platforms.windows.forEach(el => {
describe('Test getPlatform on windows', () => {
beforeEach(() => {
Object.defineProperty(window.navigator, 'platform', {
Object.defineProperty(window.navigator, 'userAgent', {
writable: true,
value: el
})
Expand Down

0 comments on commit 3b87286

Please sign in to comment.