emscripten Humble Cloud interface
Edward Rudd
2014-08-22 f22885361e8befd42d5a8c718772a62c93e5fa6c

rework things so we JUST have user_data in the test app and add in some "Fallback" code in the shell sample to use IDBFS is the cloud provider isn’t available.

2 files modified
47 ■■■■ changed files
client/test/main.cpp 2 ●●●●● patch | view | raw | blame | history
client/test/shell.html 45 ●●●●● patch | view | raw | blame | history
client/test/main.cpp
@@ -11,7 +11,6 @@
}
std::string userDataPath = "/user_data";
std::string userCloudPath = "/user_cloud";
void list_subfolder(const std::string& folder, const std::string& short_folder, const std::string& prefix = "")
{
@@ -43,7 +42,6 @@
void test_list_files()
{
    list_folder(userDataPath);
    list_folder(userCloudPath);
}
int main(int argc, char * argv[])
client/test/shell.html
@@ -1212,7 +1212,7 @@
         <span><input type="button" value="List Files" onclick="call_test_function('test_list_files')"></span>
         <span><input type="button" value="Fetch from Cloud" onclick="fetch_from_cloud()"></span>
         <span><input type="button" value="Push to Cloud" onclick="push_to_cloud()"></span>
         <span><input type="button" value="Populate local Cloud" onclick="populate_user_cloud()"></span>
         <span><input type="button" value="Populate local data" onclick="populate_user_data()"></span>
      </span>
      <canvas class="emscripten" id="canvas" oncontextmenu="event.preventDefault()"></canvas>
    </div>
@@ -1298,22 +1298,27 @@
        };
      };
      Module['preRun'].push(function() {
          var provider_name = '@TEST_CLOUD_PROVIDER@';
          addRunDependency('CLOUDFS_setup');
          FS.createFolder('/', 'user_data', true, true);
          FS.mount(IDBFS, {}, '/user_data');
          FS.createFolder('/', 'user_cloud', true, true);
          FS.mount(CLOUDFS, {
              // a list of regexes or string prefixes to synchronize
              sync: [
              ],
              // which provider engine to use.. Looks for a provider in the CLOUD_PROVIDERS object
              provider: '@TEST_CLOUD_PROVIDER@',
              // configuration sent to the provider
              cloud: {
                  applicationtoken: 'deadbeef'
              }
          }, '/user_cloud');
          FS.createFolder('/', 'user_data', true, true);
          // If the provider isn't available then fallback to using IDBFS
          if (CLOUDFS.validateProvider(provider_name)) {
              FS.mount(CLOUDFS, {
                  // a list of regexes or string prefixes to synchronize
                  sync: [
                  ],
                  // which provider engine to use.. Looks for a provider in the CLOUD_PROVIDERS object
                  provider: provider_name,
                  // configuration sent to the provider
                  cloud: {
                      applicationtoken: 'deadbeef'
                  }
              }, '/user_data');
          } else { // Cloud provider not available
              FS.mount(IDBFS, {}, '/user_data');
          }
          FS.syncfs(true, function(err) {
              if(err) console.log('ERROR!', err);
@@ -1343,12 +1348,12 @@
              Module.print('Sync to Remote', e);
          });
      }
      function populate_user_cloud()
      function populate_user_data()
      {
          FS.createPath('/user_cloud', 'test/two', true, true);
          FS.writeFile('/user_cloud/test.txt', 'This is a test');
          FS.writeFile('/user_cloud/test/file2.txt', 'This is another test');
          FS.writeFile('/user_cloud/test/two/file3.txt', 'This is another test');
          FS.createPath('/user_data', 'test/two', true, true);
          FS.writeFile('/user_data/test.txt', 'This is a test');
          FS.writeFile('/user_data/test/file2.txt', 'This is another test');
          FS.writeFile('/user_data/test/two/file3.txt', 'This is another test');
      }
    </script>
    <script async type="text/javascript" src="TestApp.js"></script>