* User config file doesn't exists * therefore open soundcloud authentication page
()
| 38 | * therefore open soundcloud authentication page |
| 39 | */ |
| 40 | function authenticateUser() { |
| 41 | let contents; |
| 42 | |
| 43 | authenticationWindow = new BrowserWindow({ |
| 44 | width: 600, |
| 45 | height: 600, |
| 46 | frame: false, |
| 47 | webPreferences: { |
| 48 | nodeIntegration: false, |
| 49 | webSecurity: false |
| 50 | } |
| 51 | }); |
| 52 | authenticationWindow.loadURL(SCconnect); |
| 53 | authenticationWindow.show(); |
| 54 | |
| 55 | contents = authenticationWindow.webContents; |
| 56 | |
| 57 | contents.on('did-get-redirect-request', (event, oldUrl, newUrl) => { |
| 58 | const access_tokenStr = 'access_token='; |
| 59 | const expires_inStr = '&expires_in'; |
| 60 | let accessToken; |
| 61 | |
| 62 | if (newUrl.indexOf('access_token=') < 0) { |
| 63 | return false; |
| 64 | } |
| 65 | |
| 66 | accessToken = newUrl.substring(newUrl.indexOf(access_tokenStr) + 13, newUrl.indexOf(expires_inStr)); |
| 67 | |
| 68 | setUserData(accessToken); |
| 69 | authenticationWindow.destroy(); |
| 70 | }); |
| 71 | } |
| 72 | |
| 73 | function setUserData(accessToken) { |
| 74 | fs.writeFileSync(configuration.getPath(), JSON.stringify({ |
no test coverage detected