Ejemplo n.º 1
0
def generate_web_manifest(manifest, start_url):
    """Generates a progressive web app manifest based on a Chrome App manifest.

  Args:
    manifest: Chrome App manifest dictionary.
    start_url: URL of start page.

  Returns:
    Web manifest JSON dictionary.
  """
    web_manifest = {}
    web_manifest['name'] = manifest['name']
    web_manifest['short_name'] = manifest.get('short_name', manifest['name'])
    web_manifest['lang'] = manifest.get('default_locale', 'en')
    web_manifest['splash_screens'] = []
    # TODO(alger): Guess display mode from chrome.app.window.create calls
    web_manifest['display'] = 'minimal-ui'
    web_manifest['orientation'] = 'any'
    # TODO(alger): Guess start_url from chrome.app.window.create calls
    web_manifest['start_url'] = start_url
    # TODO(alger): Guess background/theme colour from the main page's CSS.
    web_manifest['theme_color'] = 'white'
    web_manifest['background_color'] = 'white'
    web_manifest['related_applications'] = []
    web_manifest['prefer_related_applications'] = False
    web_manifest['icons'] = []
    if 'icons' in manifest:
        for icon_size in manifest['icons']:
            web_manifest['icons'].append({
                'src': manifest['icons'][icon_size],
                'sizes': '{0}x{0}'.format(icon_size)
            })

    # TODO(alger): I've only looked at some of the manifest members here; probably
    # a bad idea to ignore the ones that don't copy across. Should give a warning.

    return web_manifest
Ejemplo n.º 2
0
def generate_web_manifest(manifest, start_url):
  """Generates a progressive web app manifest based on a Chrome App manifest.

  Args:
    manifest: Chrome App manifest dictionary.
    start_url: URL of start page.

  Returns:
    Web manifest JSON dictionary.
  """
  web_manifest = {}
  web_manifest['name'] = manifest['name']
  web_manifest['short_name'] = manifest.get('short_name', manifest['name'])
  web_manifest['lang'] = manifest.get('default_locale', 'en')
  web_manifest['splash_screens'] = []
  # TODO(alger): Guess display mode from chrome.app.window.create calls
  web_manifest['display'] = 'minimal-ui'
  web_manifest['orientation'] = 'any'
  # TODO(alger): Guess start_url from chrome.app.window.create calls
  web_manifest['start_url'] = start_url
  # TODO(alger): Guess background/theme colour from the main page's CSS.
  web_manifest['theme_color'] = 'white'
  web_manifest['background_color'] = 'white'
  web_manifest['related_applications'] = []
  web_manifest['prefer_related_applications'] = False
  web_manifest['icons'] = []
  if 'icons' in manifest:
    for icon_size in manifest['icons']:
      web_manifest['icons'].append({
        'src': manifest['icons'][icon_size],
        'sizes': '{0}x{0}'.format(icon_size)
      })

  # TODO(alger): I've only looked at some of the manifest members here; probably
  # a bad idea to ignore the ones that don't copy across. Should give a warning.

  return web_manifest
Ejemplo n.º 3
0
 def test_get(self):
     """Tests that get returns the correct app manifest."""
     minimal_path = os.path.join(os.path.dirname(ROOT_DIR), 'tests',
                                 'test_app_minimal')
     manifest = chrome_app_manifest.get(minimal_path)
     self.assertEqual(
         manifest, {
             'app': {
                 'background': {
                     'scripts': ['a_background_script.js']
                 }
             },
             'manifest_version': 2,
             'name': 'Minimal App',
             'version': '1.0.0'
         })
Ejemplo n.º 4
0
 def test_get(self):
   """Tests that get returns the correct app manifest."""
   minimal_path = os.path.join(
       os.path.dirname(ROOT_DIR), 'tests', 'test_app_minimal')
   manifest = chrome_app_manifest.get(minimal_path)
   self.assertEqual(manifest,
     {
     'app': {
       'background': {
         'scripts': ['a_background_script.js']
       }
     },
     'manifest_version': 2,
     'name': 'Minimal App',
     'version': '1.0.0'
   })