<commit_before>import cozy, { LocalStorage as Storage } from 'cozy-client-js'
import localforage from 'localforage'

export const SETUP = 'SETUP'
export const SET_URL = 'SET_URL'
export const SET_STATE = 'SET_STATE'
export const ERROR = 'ERROR'

export class OnBoardingError extends Error {
  constructor (message) {
    super(message)
    this.name = 'OnBoardingError'
  }
}

export function setUrl (url) {
  return async dispatch => {
    let __ALLOW_HTTP__ = __ALLOW_HTTP__ || false
    let scheme = 'https://'
    if (__ALLOW_HTTP__) {
      scheme = 'http://'
      console.warn('development mode: we don\'t check SSL requirement')
    }
    if (/(.*):\/\/(.*)/.test(url) && !url.startsWith(scheme)) {
      dispatch({ type: ERROR, error: 'mobile.onboarding.server_selection.wrong_address' })
      throw new OnBoardingError(`The only supported protocol is ${scheme}`)
    }
    if (!url.startsWith(scheme)) {
      url = `${scheme}${url}`
    }
    return dispatch({ type: SET_URL, url: url })
  }
}

export const registerDevice = (router, location) => {
  return async (dispatch, getState) => {
    await dispatch(setUrl(getState().mobile.serverUrl))

    let oauth
    if (window.cordova && window.cordova.InAppBrowser) {
      oauth = {
        storage: new Storage(),
        clientParams: {
          redirectURI: 'http://localhost',
          softwareID: 'io.cozy.mobile.files',
          clientName: 'Mobile Cozy Files',
          scopes: ['io.cozy.files:GET']
        },
        onRegistered: (client, url) => {
          if (window.cordova && window.cordova.InAppBrowser) {
            const { InAppBrowser } = window.cordova
            const target = '_blank'
            const options = 'location=yes,hidden=no'
            const inAppBrowser = InAppBrowser.open(url, target, options)

            return new Promise((resolve) => {
              inAppBrowser.addEventListener('loadstop', ({url}) => {
                const accessCode = /\?access_code=(.+)$/.test(url)
                const state = /\?state=(.+)$/.test(url)

                if (accessCode || state) {
                  resolve(url)
                }
              })
            })
            .then(
              (url) => {
                inAppBrowser.close()
                return url
              },
              (err) => {
                inAppBrowser.close()
                dispatch(error(err))
                throw err<commit_msg>Fix :bug: on ios, after oauth is fine<commit_after>import cozy, { LocalStorage as Storage } from 'cozy-client-js'
import localforage from 'localforage'

export const SETUP = 'SETUP'
export const SET_URL = 'SET_URL'
export const SET_STATE = 'SET_STATE'
export const ERROR = 'ERROR'

export class OnBoardingError extends Error {
  constructor (message) {
    super(message)
    this.name = 'OnBoardingError'
  }
}

export function setUrl (url) {
  return async dispatch => {
    let __ALLOW_HTTP__ = __ALLOW_HTTP__ || false
    let scheme = 'https://'
    if (__ALLOW_HTTP__) {
      scheme = 'http://'
      console.warn('development mode: we don\'t check SSL requirement')
    }
    if (/(.*):\/\/(.*)/.test(url) && !url.startsWith(scheme)) {
      dispatch({ type: ERROR, error: 'mobile.onboarding.server_selection.wrong_address' })
      throw new OnBoardingError(`The only supported protocol is ${scheme}`)
    }
    if (!url.startsWith(scheme)) {
      url = `${scheme}${url}`
    }
    return dispatch({ type: SET_URL, url: url })
  }
}

export const registerDevice = (router, location) => {
  return async (dispatch, getState) => {
    await dispatch(setUrl(getState().mobile.serverUrl))

    let oauth
    if (window.cordova && window.cordova.InAppBrowser) {
      oauth = {
        storage: new Storage(),
        clientParams: {
          redirectURI: 'http://localhost',
          softwareID: 'io.cozy.mobile.files',
          clientName: 'Mobile Cozy Files',
          scopes: ['io.cozy.files:GET']
        },
        onRegistered: (client, url) => {
          if (window.cordova && window.cordova.InAppBrowser) {
            const { InAppBrowser } = window.cordova
            const target = '_blank'
            const options = 'location=yes,hidden=no'
            const inAppBrowser = InAppBrowser.open(url, target, options)

            return new Promise((resolve) => {
              inAppBrowser.addEventListener('loadstart', ({url}) => {
                const accessCode = /\?access_code=(.+)$/.test(url)
                const state = /\?state=(.+)$/.test(url)

                if (accessCode || state) {
                  resolve(url)
                }
              })
            })
            .then(
              (url) => {
                inAppBrowser.close()
                return url
              },
              (err) => {
                inAppBrowser.close()
                dispatch(error(err))
                throw err
{'fraction_non_alphanumeric': 0.13296455644335178, 'fraction_numerical': 0.0, 'mean_word_length': 2.070440251572327, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6315462', 'n_tokens_mistral': 1427, 'n_tokens_neox': 1394, 'n_words': 334}