Skip to content
This repository has been archived by the owner on Jul 8, 2020. It is now read-only.

create cordova hooks #171

Closed
MathiasTim opened this issue Apr 20, 2015 · 12 comments
Closed

create cordova hooks #171

MathiasTim opened this issue Apr 20, 2015 · 12 comments

Comments

@MathiasTim
Copy link
Contributor

To solve some problems like manipulation the plist, we need to use cordova hooks.

We should write a colletion of most used cordova hooks and maybe integrate them then into generator-m.

@stefanjauker
Copy link
Member

why would you manipulate the plist file?

@MathiasTim
Copy link
Contributor Author

For example to add the supported languages on iOS to the app. In this way labels on buttons from native plugins will be translated.
i.e.: the camera plugin will always display 'use photo' although your are on a device that has german as language. That can be solved if you add the 'supported languages' to the app. Then iOS will translate system labels in the correct language.

@MathiasTim
Copy link
Contributor Author

I talked to Frank today, he used this hook, for my described usecase above:

https://github.com/diegonetto/generator-ionic/blob/master/templates/hooks/after_prepare/update_platform_config.js

I like it, and I think we should think about a way to scaffold this with the generator-m (at least ask the user)

@FrankStierle
Copy link

This Hook can also add all kind of entries to the AndroidManifest.xml if specified in the config.xml.

Very useful

@gruppjo
Copy link
Contributor

gruppjo commented May 8, 2015

Maybe we can provide an m:hook subgenerator.

related #184, #183

@gruppjo gruppjo added this to the 1.2.0 milestone May 22, 2015
@gruppjo
Copy link
Contributor

gruppjo commented Jun 5, 2015

#188 (add badges on app icons)

@gruppjo
Copy link
Contributor

gruppjo commented Jul 1, 2015

@gruppjo gruppjo modified the milestones: 1.2.0, 1.3.0 Jul 2, 2015
@gruppjo
Copy link
Contributor

gruppjo commented Aug 20, 2015

Agreements as of today:

update platform config

Nice to have in the future: provide hooks as node module.

splash & icons (Gulp, no hook!)

based on: https://generator-m.slack.com/files/mathias/F0873DD8W/setup_splash_and_icons.js
folder structure

res/
  |- android
    | default files
    | current - files are copied here by task
    | config1
    | config2
    | ....

the task then copies all files to the current/ directory. The links to the splashscreens and icons in the config.xml should point to this directory.

The task is started when cordova run, emulate, build, prepare are called.
Different assets can be chosen like this: gulp --cordova 'run ios' --res=badge1.

It's the developer's responsibility to correctly link to the resource files in the config.xml.

@gruppjo
Copy link
Contributor

gruppjo commented Aug 21, 2015

Adding

  <platform name="android">
    <hook type="after_prepare" src="hooks/update_platform_config.js"/>
  </platform>
  <platform name="ios">
    <hook type="after_prepare" src="hooks/update_platform_config.js"/>
  </platform>

to the config.xml results in the following error when running gulp --cordova 'run ios'

ERROR running one or more of the platforms: TypeError: invalid data
You may not have the required environment or OS to run this project

I'm reverting to adding the hook using the directory after_prepare:

For future reference, this is the code for the gulp config task:

if (options.addHook && options.type && options.src) {
  result.widget.platform = result.widget.platform || [];
  result.widget.platform.push({
    $: { name: 'android' },
    hook: {
      $: {
        type: options.type,
        src: options.src
      }
    }
  });
  result.widget.platform.push({
    $: { name: 'ios' },
    hook: {
      $: {
        type: options.type,
        src: options.src
      }
    }
  });
}

and the gulp tasks could have been called in the app/index.js like this: https://github.com/mwaylabs/generator-m/blob/0.2.7/app/index.js#L371-L383

@gruppjo
Copy link
Contributor

gruppjo commented Aug 27, 2015

closed with 9a36328

@gruppjo gruppjo closed this as completed Aug 27, 2015
@MathiasTim
Copy link
Contributor Author

I thought we will not support the deprecated method with using the hooks folder for cordova hooks?

Although the demo has it. Is there any reason why?

@gruppjo
Copy link
Contributor

gruppjo commented Sep 7, 2015

Yes! See the comment above. #171 (comment)
Feel free to try this and let me know if you get the same error, when using the config.xml method.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants