{"action":"created","comment":{"url":"https://api.github.com/repos/resin-io/resin-wifi-connect/pulls/comments/83483189","pull_request_review_id":4323941,"id":83483189,"diff_hunk":"@@ -16,54 +13,97 @@ app.use(bodyParser.json())\n app.use(bodyParser.urlencoded(extended: true))\n app.use(express.static(__dirname + '/public'))\n \n-ssids = []\n+_ssids = []\n \n app.get '/ssids', (req, res) ->\n-\tres.json(ssids)\n+\tres.json(_ssids)\n \n app.post '/connect', (req, res) ->\n \tif not (req.body.ssid? and req.body.passphrase?)\n \t\treturn res.sendStatus(400)\n \n-\tconsole.log('Selected ' + req.body.ssid)\n-\n \tres.send('OK')\n \n-\tdata = \"\"\"\n-\t\t[service_home_ethernet]\n-\t\tType = ethernet\n-\t\tNameservers = 8.8.8.8,8.8.4.4\n-\n-\t\t[service_home_wifi]\n-\t\tType = wifi\n-\t\tName = #{req.body.ssid}\n-\t\tPassphrase = #{req.body.passphrase}\n-\t\tNameservers = 8.8.8.8,8.8.4.4\n-\n-\t\"\"\"\n-\n-\tPromise.all [\n-\t\tutils.durableWriteFile(config.connmanConfig, data)\n-\t\thotspot.stop()\n-\t]\n-\t# XXX: make it so this delay isn't needed\n-\t.delay(1000)\n-\t.then ->\n-\t\tconnman.waitForConnection(15000)\n+\thotspot.stop(manager)\n \t.then ->\n-\t\tutils.durableWriteFile(config.persistentConfig, data)\n+\t\tmanager.setCredentials(req.body.ssid, req.body.passphrase)\n \t.then ->\n-\t\tprocess.exit()\n-\t.catch (e) ->\n-\t\thotspot.start()\n+\t\trun()\n \n app.use (req, res) ->\n \tres.redirect('/')\n \n-wifiScan.scanAsync()\n-.then (results) ->\n-\tssids = results\n-\n-\thotspot.start()\n+run = ->\n+\tmanager.isSetup()\n+\t.then (setup) ->\n+\t\tif setup\n+\t\t\tconsole.log('Credentials found')\n+\t\t\thotspot.stop()\n+\t\t\t.then ->\n+\t\t\t\tconsole.log('Connecting')\n+\t\t\t\tmanager.connect(15000)\n+\t\t\t.then ->\n+\t\t\t\tconsole.log('Connected')\n+\t\t\t\tconsole.log('Exiting')\n+\t\t\t\tprocess.exit()\n+\t\t\t.catch (e) ->\n+\t\t\t\tconsole.log('Connecting failed')\n+\t\t\t\tif retry\n+\t\t\t\t\tconsole.log('Retrying')\n+\t\t\t\t\tconsole.log('Clearing credentials')\n+\t\t\t\t\tmanager.clearCredentials()\n+\t\t\t\t\t.then ->\n+\t\t\t\t\t\trun()\n+\t\t\t\t\t.catch (e) ->\n+\t\t\t\t\t\tconsole.log(e)\n+\t\t\t\t\t\tconsole.log('Exiting')\n+\t\t\t\t\t\tprocess.exit()\n+\t\t\t\telse\n+\t\t\t\t\tconsole.log('Not retrying')\n+\t\t\t\t\tconsole.log('Exiting')\n+\t\t\t\t\tprocess.exit()\n+\t\telse\n+\t\t\tconsole.log('Credentials not found')\n+\t\t\thotspot.start(manager)\n+\t\t\t.catch (e) ->\n+\t\t\t\tconsole.log(e)\n+\t\t\t\tconsole.log('Exiting')\n+\t\t\t\tprocess.exit()\n \n app.listen(80)\n+\n+retry = null\n+if process.argv[2] == '--retry=true'\n+\tconsole.log('Retry enabled')\n+\tretry = true\n+else if process.argv[2] == '--retry=false'\n+\tconsole.log('Retry disabled')\n+\tretry = false\n+else if typeof(process.argv[2]) == 'undefined'","path":"src/app.coffee","position":120,"original_position":120,"commit_id":"5278876076c55d548a28eec4a8991d02988b69f4","original_commit_id":"5278876076c55d548a28eec4a8991d02988b69f4","user":{"login":"Page-","id":360115,"avatar_url":"https://avatars.githubusercontent.com/u/360115?v=3","gravatar_id":"","url":"https://api.github.com/users/Page-","html_url":"https://github.com/Page-","followers_url":"https://api.github.com/users/Page-/followers","following_url":"https://api.github.com/users/Page-/following{/other_user}","gists_url":"https://api.github.com/users/Page-/gists{/gist_id}","starred_url":"https://api.github.com/users/Page-/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Page-/subscriptions","organizations_url":"https://api.github.com/users/Page-/orgs","repos_url":"https://api.github.com/users/Page-/repos","events_url":"https://api.github.com/users/Page-/events{/privacy}","received_events_url":"https://api.github.com/users/Page-/received_events","type":"User","site_admin":false},"body":"This would be nicer as\r\n```coffee\r\nelse if not process.argv[2]?\r\n```\r\n- the `?` existential operator is what we normally use to check for null/undefined","created_at":"2016-10-14T19:05:47Z","updated_at":"2016-10-14T19:05:47Z","html_url":"https://github.com/resin-io/resin-wifi-connect/pull/49#discussion_r83483189","pull_request_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/pulls/49","_links":{"self":{"href":"https://api.github.com/repos/resin-io/resin-wifi-connect/pulls/comments/83483189"},"html":{"href":"https://github.com/resin-io/resin-wifi-connect/pull/49#discussion_r83483189"},"pull_request":{"href":"https://api.github.com/repos/resin-io/resin-wifi-connect/pulls/49"}}},"pull_request":{"url":"https://api.github.com/repos/resin-io/resin-wifi-connect/pulls/49","id":88290993,"html_url":"https://github.com/resin-io/resin-wifi-connect/pull/49","diff_url":"https://github.com/resin-io/resin-wifi-connect/pull/49.diff","patch_url":"https://github.com/resin-io/resin-wifi-connect/pull/49.patch","issue_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/issues/49","number":49,"state":"open","locked":false,"title":"Network manager support","user":{"login":"josephroberts","id":1107385,"avatar_url":"https://avatars.githubusercontent.com/u/1107385?v=3","gravatar_id":"","url":"https://api.github.com/users/josephroberts","html_url":"https://github.com/josephroberts","followers_url":"https://api.github.com/users/josephroberts/followers","following_url":"https://api.github.com/users/josephroberts/following{/other_user}","gists_url":"https://api.github.com/users/josephroberts/gists{/gist_id}","starred_url":"https://api.github.com/users/josephroberts/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josephroberts/subscriptions","organizations_url":"https://api.github.com/users/josephroberts/orgs","repos_url":"https://api.github.com/users/josephroberts/repos","events_url":"https://api.github.com/users/josephroberts/events{/privacy}","received_events_url":"https://api.github.com/users/josephroberts/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-10-06T15:57:25Z","updated_at":"2016-10-14T19:10:03Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c7e55d008e92c91d4e8b3d19b293815cbb7cdd15","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/pulls/49/commits","review_comments_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/pulls/49/comments","review_comment_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/pulls/comments{/number}","comments_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/issues/49/comments","statuses_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/statuses/5278876076c55d548a28eec4a8991d02988b69f4","head":{"label":"resin-io:network-manager-support","ref":"network-manager-support","sha":"5278876076c55d548a28eec4a8991d02988b69f4","user":{"login":"resin-io","id":6157842,"avatar_url":"https://avatars.githubusercontent.com/u/6157842?v=3","gravatar_id":"","url":"https://api.github.com/users/resin-io","html_url":"https://github.com/resin-io","followers_url":"https://api.github.com/users/resin-io/followers","following_url":"https://api.github.com/users/resin-io/following{/other_user}","gists_url":"https://api.github.com/users/resin-io/gists{/gist_id}","starred_url":"https://api.github.com/users/resin-io/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/resin-io/subscriptions","organizations_url":"https://api.github.com/users/resin-io/orgs","repos_url":"https://api.github.com/users/resin-io/repos","events_url":"https://api.github.com/users/resin-io/events{/privacy}","received_events_url":"https://api.github.com/users/resin-io/received_events","type":"Organization","site_admin":false},"repo":{"id":37727198,"name":"resin-wifi-connect","full_name":"resin-io/resin-wifi-connect","owner":{"login":"resin-io","id":6157842,"avatar_url":"https://avatars.githubusercontent.com/u/6157842?v=3","gravatar_id":"","url":"https://api.github.com/users/resin-io","html_url":"https://github.com/resin-io","followers_url":"https://api.github.com/users/resin-io/followers","following_url":"https://api.github.com/users/resin-io/following{/other_user}","gists_url":"https://api.github.com/users/resin-io/gists{/gist_id}","starred_url":"https://api.github.com/users/resin-io/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/resin-io/subscriptions","organizations_url":"https://api.github.com/users/resin-io/orgs","repos_url":"https://api.github.com/users/resin-io/repos","events_url":"https://api.github.com/users/resin-io/events{/privacy}","received_events_url":"https://api.github.com/users/resin-io/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/resin-io/resin-wifi-connect","description":null,"fork":false,"url":"https://api.github.com/repos/resin-io/resin-wifi-connect","forks_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/forks","keys_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/keys{/key_id}","collaborators_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/teams","hooks_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/hooks","issue_events_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/issues/events{/number}","events_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/events","assignees_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/assignees{/user}","branches_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/branches{/branch}","tags_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/tags","blobs_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/git/refs{/sha}","trees_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/git/trees{/sha}","statuses_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/statuses/{sha}","languages_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/languages","stargazers_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/stargazers","contributors_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/contributors","subscribers_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/subscribers","subscription_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/subscription","commits_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/commits{/sha}","git_commits_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/git/commits{/sha}","comments_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/comments{/number}","issue_comment_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/issues/comments{/number}","contents_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/contents/{+path}","compare_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/compare/{base}...{head}","merges_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/merges","archive_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/downloads","issues_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/issues{/number}","pulls_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/pulls{/number}","milestones_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/milestones{/number}","notifications_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/labels{/name}","releases_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/releases{/id}","deployments_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/deployments","created_at":"2015-06-19T14:45:09Z","updated_at":"2016-10-12T18:48:17Z","pushed_at":"2016-10-14T14:55:40Z","git_url":"git://github.com/resin-io/resin-wifi-connect.git","ssh_url":"git@github.com:resin-io/resin-wifi-connect.git","clone_url":"https://github.com/resin-io/resin-wifi-connect.git","svn_url":"https://github.com/resin-io/resin-wifi-connect","homepage":null,"size":1028,"stargazers_count":25,"watchers_count":25,"language":"CoffeeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":28,"mirror_url":null,"open_issues_count":7,"forks":28,"open_issues":7,"watchers":25,"default_branch":"master"}},"base":{"label":"resin-io:master","ref":"master","sha":"27791820436526d6f1299c640ba259ac4c01f4de","user":{"login":"resin-io","id":6157842,"avatar_url":"https://avatars.githubusercontent.com/u/6157842?v=3","gravatar_id":"","url":"https://api.github.com/users/resin-io","html_url":"https://github.com/resin-io","followers_url":"https://api.github.com/users/resin-io/followers","following_url":"https://api.github.com/users/resin-io/following{/other_user}","gists_url":"https://api.github.com/users/resin-io/gists{/gist_id}","starred_url":"https://api.github.com/users/resin-io/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/resin-io/subscriptions","organizations_url":"https://api.github.com/users/resin-io/orgs","repos_url":"https://api.github.com/users/resin-io/repos","events_url":"https://api.github.com/users/resin-io/events{/privacy}","received_events_url":"https://api.github.com/users/resin-io/received_events","type":"Organization","site_admin":false},"repo":{"id":37727198,"name":"resin-wifi-connect","full_name":"resin-io/resin-wifi-connect","owner":{"login":"resin-io","id":6157842,"avatar_url":"https://avatars.githubusercontent.com/u/6157842?v=3","gravatar_id":"","url":"https://api.github.com/users/resin-io","html_url":"https://github.com/resin-io","followers_url":"https://api.github.com/users/resin-io/followers","following_url":"https://api.github.com/users/resin-io/following{/other_user}","gists_url":"https://api.github.com/users/resin-io/gists{/gist_id}","starred_url":"https://api.github.com/users/resin-io/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/resin-io/subscriptions","organizations_url":"https://api.github.com/users/resin-io/orgs","repos_url":"https://api.github.com/users/resin-io/repos","events_url":"https://api.github.com/users/resin-io/events{/privacy}","received_events_url":"https://api.github.com/users/resin-io/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/resin-io/resin-wifi-connect","description":null,"fork":false,"url":"https://api.github.com/repos/resin-io/resin-wifi-connect","forks_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/forks","keys_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/keys{/key_id}","collaborators_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/teams","hooks_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/hooks","issue_events_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/issues/events{/number}","events_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/events","assignees_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/assignees{/user}","branches_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/branches{/branch}","tags_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/tags","blobs_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/git/refs{/sha}","trees_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/git/trees{/sha}","statuses_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/statuses/{sha}","languages_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/languages","stargazers_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/stargazers","contributors_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/contributors","subscribers_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/subscribers","subscription_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/subscription","commits_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/commits{/sha}","git_commits_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/git/commits{/sha}","comments_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/comments{/number}","issue_comment_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/issues/comments{/number}","contents_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/contents/{+path}","compare_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/compare/{base}...{head}","merges_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/merges","archive_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/downloads","issues_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/issues{/number}","pulls_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/pulls{/number}","milestones_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/milestones{/number}","notifications_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/labels{/name}","releases_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/releases{/id}","deployments_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/deployments","created_at":"2015-06-19T14:45:09Z","updated_at":"2016-10-12T18:48:17Z","pushed_at":"2016-10-14T14:55:40Z","git_url":"git://github.com/resin-io/resin-wifi-connect.git","ssh_url":"git@github.com:resin-io/resin-wifi-connect.git","clone_url":"https://github.com/resin-io/resin-wifi-connect.git","svn_url":"https://github.com/resin-io/resin-wifi-connect","homepage":null,"size":1028,"stargazers_count":25,"watchers_count":25,"language":"CoffeeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":28,"mirror_url":null,"open_issues_count":7,"forks":28,"open_issues":7,"watchers":25,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/resin-io/resin-wifi-connect/pulls/49"},"html":{"href":"https://github.com/resin-io/resin-wifi-connect/pull/49"},"issue":{"href":"https://api.github.com/repos/resin-io/resin-wifi-connect/issues/49"},"comments":{"href":"https://api.github.com/repos/resin-io/resin-wifi-connect/issues/49/comments"},"review_comments":{"href":"https://api.github.com/repos/resin-io/resin-wifi-connect/pulls/49/comments"},"review_comment":{"href":"https://api.github.com/repos/resin-io/resin-wifi-connect/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/resin-io/resin-wifi-connect/pulls/49/commits"},"statuses":{"href":"https://api.github.com/repos/resin-io/resin-wifi-connect/statuses/5278876076c55d548a28eec4a8991d02988b69f4"}}}}
{"actor":{"display_login":"Page-"}}