{"action":"created","comment":{"url":"https://api.github.com/repos/resin-io/resin-wifi-connect/pulls/comments/36729683","id":36729683,"diff_hunk":"@@ -58,6 +64,32 @@ startServer = (wifi) ->\n \t\t\t\t\tthrow err if err?\n \t\t\t\t\tconsole.log('Server listening')\n \n+connectOrStartServer = (wifi, retryCallback) ->\n+\tif connectionsFromFile?\n+\t\tconsole.log('Trying to join previously known networks')\n+\t\tPromise.each connectionsFromFile, (conn) ->\n+\t\t\twifi.joinAsync(conn.ssid, conn.passphrase)\n+\t\t\t.then ->\n+\t\t\t\tconsole.log('Joined! Exiting.')\n+\t\t\t\tretryCallback()\n+\t\t\t.catch(ignore)\n+\t\t.then ->\n+\t\t\tstartServer(wifi)\n+\telse\n+\t\tstartServer(wifi)\n+\n+saveToFile = (ssid, passphrase) ->\n+\tif connectionsFromFile?\n+\t\tconnectionsFromFile.push({ ssid, passphrase })\n+\telse\n+\t\tconnectionsFromFile = [ { ssid, passphrase } ]\n+\treturn new Promise (resolve, reject) ->\n+\t\tfs.writeFile connectionFile, JSON.stringify(connectionsFromFile), (err) ->\n+\t\t\treturn reject(err) if err?\n+\t\t\texec 'sync', (err) ->","path":"src/app.coffee","position":51,"original_position":51,"commit_id":"c5ed22de013f49a1f61738061bdb833200e1b167","original_commit_id":"c5ed22de013f49a1f61738061bdb833200e1b167","user":{"login":"petrosagg","id":939420,"avatar_url":"https://avatars.githubusercontent.com/u/939420?v=3","gravatar_id":"","url":"https://api.github.com/users/petrosagg","html_url":"https://github.com/petrosagg","followers_url":"https://api.github.com/users/petrosagg/followers","following_url":"https://api.github.com/users/petrosagg/following{/other_user}","gists_url":"https://api.github.com/users/petrosagg/gists{/gist_id}","starred_url":"https://api.github.com/users/petrosagg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/petrosagg/subscriptions","organizations_url":"https://api.github.com/users/petrosagg/orgs","repos_url":"https://api.github.com/users/petrosagg/repos","events_url":"https://api.github.com/users/petrosagg/events{/privacy}","received_events_url":"https://api.github.com/users/petrosagg/received_events","type":"User","site_admin":false},"body":"It's probably better to just `fsync()` the file https://nodejs.org/api/fs.html#fs_fs_fsync_fd_callback","created_at":"2015-08-11T10:11:52Z","updated_at":"2015-08-11T10:11:52Z","html_url":"https://github.com/resin-io/resin-wifi-connect/pull/9#discussion_r36729683","pull_request_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/pulls/9","_links":{"self":{"href":"https://api.github.com/repos/resin-io/resin-wifi-connect/pulls/comments/36729683"},"html":{"href":"https://github.com/resin-io/resin-wifi-connect/pull/9#discussion_r36729683"},"pull_request":{"href":"https://api.github.com/repos/resin-io/resin-wifi-connect/pulls/9"}}},"pull_request":{"url":"https://api.github.com/repos/resin-io/resin-wifi-connect/pulls/9","id":42060560,"html_url":"https://github.com/resin-io/resin-wifi-connect/pull/9","diff_url":"https://github.com/resin-io/resin-wifi-connect/pull/9.diff","patch_url":"https://github.com/resin-io/resin-wifi-connect/pull/9.patch","issue_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/issues/9","number":9,"state":"open","locked":false,"title":"Use file to save connections","user":{"login":"pcarranzav","id":2223590,"avatar_url":"https://avatars.githubusercontent.com/u/2223590?v=3","gravatar_id":"","url":"https://api.github.com/users/pcarranzav","html_url":"https://github.com/pcarranzav","followers_url":"https://api.github.com/users/pcarranzav/followers","following_url":"https://api.github.com/users/pcarranzav/following{/other_user}","gists_url":"https://api.github.com/users/pcarranzav/gists{/gist_id}","starred_url":"https://api.github.com/users/pcarranzav/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pcarranzav/subscriptions","organizations_url":"https://api.github.com/users/pcarranzav/orgs","repos_url":"https://api.github.com/users/pcarranzav/repos","events_url":"https://api.github.com/users/pcarranzav/events{/privacy}","received_events_url":"https://api.github.com/users/pcarranzav/received_events","type":"User","site_admin":false},"body":"Connman can be a bit mysterious and not save connections every now and then. So we keep our own list.\r\n\r\nDepends on #8 ","created_at":"2015-08-10T20:11:03Z","updated_at":"2015-08-11T10:11:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2634cccdc0db6ae2b7cfabe69c298c05bb0d1312","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/pulls/9/commits","review_comments_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/pulls/9/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/9/comments","statuses_url":"https://api.github.com/repos/resin-io/resin-wifi-connect/statuses/c5ed22de013f49a1f61738061bdb833200e1b167","head":{"label":"resin-io:connection-file","ref":"connection-file","sha":"c5ed22de013f49a1f61738061bdb833200e1b167","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":"","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}","created_at":"2015-06-19T14:45:09Z","updated_at":"2015-08-06T07:04:46Z","pushed_at":"2015-08-10T20:12:25Z","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":1147,"stargazers_count":3,"watchers_count":3,"language":"CoffeeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":2,"forks":1,"open_issues":2,"watchers":3,"default_branch":"master"}},"base":{"label":"resin-io:master","ref":"master","sha":"cfbea26083d136f4231ca09e2ad5cc7b9ca1ba02","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":"","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}","created_at":"2015-06-19T14:45:09Z","updated_at":"2015-08-06T07:04:46Z","pushed_at":"2015-08-10T20:12:25Z","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":1147,"stargazers_count":3,"watchers_count":3,"language":"CoffeeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":2,"forks":1,"open_issues":2,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/resin-io/resin-wifi-connect/pulls/9"},"html":{"href":"https://github.com/resin-io/resin-wifi-connect/pull/9"},"issue":{"href":"https://api.github.com/repos/resin-io/resin-wifi-connect/issues/9"},"comments":{"href":"https://api.github.com/repos/resin-io/resin-wifi-connect/issues/9/comments"},"review_comments":{"href":"https://api.github.com/repos/resin-io/resin-wifi-connect/pulls/9/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/9/commits"},"statuses":{"href":"https://api.github.com/repos/resin-io/resin-wifi-connect/statuses/c5ed22de013f49a1f61738061bdb833200e1b167"}}}}