Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat(app): add capacitor support, fixes #4388 #4475

Conversation

nklayman
Copy link
Contributor

@nklayman nklayman commented Jun 25, 2019

What kind of change does this PR introduce? (check at least one)

  • Feature

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

The PR fulfills these requirements:

  • It's submitted to the dev branch and not the master branch
  • When resolving a specific issue, it's referenced in the PR's title (e.g. fix: #xxx[,#xxx], where "xxx" is the issue number)
  • It's been tested on a Cordova (iOS, Android) app
  • It's been tested on a Electron app
  • Any necessary documentation has been added or updated in the docs (for faster update click on "Suggest an edit on GitHub" at bottom of page) or explained in the PR's description.

Other information:
Have not tested on mac or windows. To test:

  1. Clone fork, cd into app, install deps, link with yarn link
  2. create new project with quasar create capacitor-quasar (use yarn), or use existing project (backup first!)
  3. link in project with yarn link @quasar/app
  4. add mode with quasar mode add capacitor, and choose your platforms
  5. dev with quasar dev -m capacitor --target [android|ios]
  6. build with quasar build -m capacitor --target [android|ios]

@rstoenescu
Copy link
Member

Hi Noah,

Excellent work! Few things:

  1. In order to be consistent with the folder structure, can you place the new folders in a /src-capacitor instead?
  2. Is there a way for us not to hard-code paths to capacitor executable? I'm worried about working with monorepos as this would break it.

@nklayman
Copy link
Contributor Author

  1. I don't think Capacitor has support for a different folder location, other than the root. It would be pretty complicated to get around it. You could open an issue in the capacitor repository to try and solve this.
  2. execa has support for executing locally installed binaries. I'm not sure that it would support yarn workspaces either, but it might.

@lucasfernog
Copy link
Contributor

Cant' you use "src-capacitor" as root, calling capacitor commands using appPaths.capacitor as cwd @nklayman ?

@lucasfernog
Copy link
Contributor

About the execution of locally installed capacitor, can't you use something like what Electron is doing: https://github.com/quasarframework/quasar/blob/dev/app/lib/electron/index.js#L161 ?

@nklayman
Copy link
Contributor Author

nklayman commented Jun 26, 2019

@lucasfernog using src-capacitor as the root could work, but capacitor would try to install npm deps there. This could possibly be prevented, but I'm not sure how to do that. As for executing the binaries, that's a great idea. I'll go ahead and implement it now. Using execa is still a good option, though, as it has a bunch of extra improvements over child_process.

@nklayman
Copy link
Contributor Author

I added the require.resolve binary locating method, as well as a fallback to the old method as require.resolve doesn't work when using yarn link @quasar/app.

Copy link
Contributor

@nothingismagick nothingismagick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On MacOS
yarn cap add ios =>
[error] cocoapods is not installed. For information: https://guides.cocoapods.org/using/getting-started.html#installation

Cocoapods requires ruby. Installed with:
brew install ruby
Ruby brings these deps:
==> Installing dependencies for ruby: libyaml, openssl and readline

CocoaPods installed with:
sudo gem install cocoapods
CocoaPods brings these deps:
thread_safe, tzinfo, concurrent-ruby, i18n, activesupport, nap, fuzzy_match, cocoapods-core, claide, cocoapods-deintegrate, cocoapods-downloader, cocoapods-plugins, cocoapods-search, cocoapods-stats, netrc, cocoapods-trunk, cocoapods-try, molinillo, atomos, CFPropertyList, colored2, nanaimo, xcodeproj, escape, fourflusher, gh_inspector, ruby-macho

After installing all deps and rerunning the cmd, this is the error:
[error] Capacitor could not find the web assets directory "/[redacted]/capacitor-quasar/dist/capacitor".

So I then run:
quasar build -m capacitor --target ios

Which does create the assets, but still throws an error:
[error] ios" platform has not been created. Use "npx cap add ios" to add the platform project.

So then I run yarn cap add ios and this works now.
It spends a bit of time (in my case still running the update loop after more than 15 minutes...) to update iOS native dependencies. Unfortunately this is all I see:

Updating iOS native dependencies with "pod install" (may take several minutes)

So there is ZERO information about what is being installed on my system, whether the cmd has hung etc. This is a little worrisome from a security standpoint, because I had to install cocoapods with sudo. Maybe it will tell me what it did at the end of its loop (if it ends)...

Will report back when it finally finishes. Note - I have not yet had the opportunity to run quasar dev -m capacitor --target ios

I stopped waiting and cancelled. Now, regardless of whether I try dev or build it hangs at Updating iOS native dependencies.

So I cd into ios/App and run $ pod install
It is downloading a really MASSIVE spec (ca 750MB) from here:
https://github.com/CocoaPods/Specs.git

CocoaPods is a dependency manager for Swift and Objective-C Cocoa projects. It has over 63 thousand libraries and is used in over 3 million apps. CocoaPods can help you scale your projects elegantly.

See this about saving time and storage:
http://blog.cocoapods.org/CocoaPods-1.7.2/


It did finally spawn xcode, but the xcode build failed on both dev and build. Can't triage at the moment.

@lucasfernog
Copy link
Contributor

@nklayman About the src-capacitor issue, would this work? ionic-team/capacitor#691 (comment)

Sorry i don't know much about it beucase i never used Capacitor, i'm just blindly searching for a solution.

@lucasfernog
Copy link
Contributor

lucasfernog commented Jun 27, 2019

I'm testing this and I found that capacitor init prompts me about using NPM or Yarn. It would be nice if you detected it before calling the command and uses the flag "--npm-client" from the command.

And we need to add the platform automatically when using quasar dev -m capacitor -T android|ios

@lucasfernog
Copy link
Contributor

The default Android Studio path from Capacitor is not the one I have on my Arch Linux machine.. should we try to read it for users, and change the capacitor.config.json with it?

}
}
await this.__runCapacitorCommand(['open', cfg.ctx.targetName])
if (!/^192/.test(url)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is not always true.. Quasar picked up my local network IP as url... I dont know

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rstoenescu what is the best way to test if the Quasar dev server url is on the network or just a localhost url?

@lucasfernog
Copy link
Contributor

I think we can use our own templates for the android/ and ios/ folders... it would be SUPER COOL, it would be nice to use lodash templates and get rid of the cleartext validation

@lucasfernog
Copy link
Contributor

Screenshot_1561670998

Android worked easily on an emulator (already had Android installed)... Amazing job @nklayman !!

@nklayman
Copy link
Contributor Author

@nothingismagick the cocoapods issue is with capacitor (ionic-team/capacitor#626 (comment)). You could open an issue on their repo to provide more helpful output when running the command. Not much I can do since I don't have a Mac.

@lucasfernog I made pr on capacitor to fix the npm-client prompt issue, since I added support for yarn to capacitor in the first place. It was already merged, and should be part of the next release. What do you mean by "using your own template for android and ios"? Android studio path detection on Linux has been discussed on capacitor at ionic-team/capacitor#560. I could try and fix it and open a PR to capacitor. Also, go Arch/Linux 👍!

@lucasfernog
Copy link
Contributor

The contents that gets copied to /android is inside capacitor/android-template... can we use a custom one? It would be cool

@nklayman
Copy link
Contributor Author

@lucasfernog You probably could. Instead of running yarn cap add android, just copy in your custom template and possibly yarn add -D @capacitor/android.

@lucasfernog
Copy link
Contributor

Maybe we should have one template of our own.. so we can set it up in a better way

@nklayman
Copy link
Contributor Author

At that point we might as well make quapacitor

@eladcandroid
Copy link

@nklayman Great job!! You can use "npx cap add ios --verbose" to see what's going on..

@eladcandroid
Copy link

@nklayman Please tell me if you need any help

@nklayman
Copy link
Contributor Author

nklayman commented Jul 4, 2019

@eladcandroid or anyone else, can you try using a capacitor/cordova plugin? Make sure to pull the latest version and create a new project.

@nothingismagick
Copy link
Contributor

@eladcandroid - we'd love some help putting together the docs for this as your time permits.

Copy link
Contributor

@lucasfernog lucasfernog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a _gitignore file to templates/capacitor with that content

@@ -81,6 +81,8 @@ class Mode {
],
appPaths.capacitorDir
)
// Add copied package.json to .gitignore as it is auto-generated
fse.writeFileSync(appPaths.resolve.capacitor('.gitignore'), 'package.json')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be part of the template/capacitor directory?

@eladcandroid
Copy link

@nklayman I've followed your instructions to test the repo on mac, and got this message:
Screen Shot 2019-07-09 at 17 45 32

@nklayman
Copy link
Contributor Author

nklayman commented Jul 9, 2019

@eladcandroid I forgot to mention that you need to switch branches before linking. Run git checkout feat(app)--add-capacitor-support in the quasar/app folder.

@eladcandroid
Copy link

@nklayman
Checked here on Mac Mojave 10.14.5, Node version 12.6.0 and it works great including live reload! Thanks!
What's next?

@nklayman
Copy link
Contributor Author

nklayman commented Aug 4, 2019

@eladcandroid can you try using a plugin on IOS? If that works, then we can merge this.

@eladcandroid
Copy link

eladcandroid commented Aug 9, 2019

@eladcandroid can you try using a plugin on IOS? If that works, then we can merge this.

Plugins work great out of the box!

Here's a screenshot using Device.getInfo() capacitor plugin

Simulator Screen Shot - iPhone 8 - 2019-08-09 at 14 07 31

<template>
  <q-page class="flex flex-center">
    <q-list bordered separator>
      <q-item v-for="(value, key) in info" :key="key" clickable v-ripple>
        <q-item-section>
          <q-item-label>{{ key }}</q-item-label>
          <q-item-label caption>{{ value }}</q-item-label>
        </q-item-section>
      </q-item>
    </q-list>
  </q-page>
</template>

<style></style>

<script>
import { Plugins } from "@capacitor/core";

const { Device } = Plugins;

export default {
  name: "PageIndex",
  data() {
    return {
      info: {}
    };
  },
  async mounted() {
    this.info = await Device.getInfo();
  }
};
</script>

@eladcandroid
Copy link

@nklayman Any additional tasks for me? 👻

@nklayman nklayman changed the title [WIP] Feat(app): add capacitor support, fixes #4388 Feat(app): add capacitor support, fixes #4388 Aug 20, 2019
@hugetiny
Copy link
Contributor

Although Capacitor is not currently compatible with some Cordova plugins.
Quapacitor is a perfect solution. I am looking forward to it

@eladcandroid
Copy link

@nklayman Do you need any help to finish with PR?

@nklayman
Copy link
Contributor Author

Right now I am just waiting on review from razvan. He is extremely busy, but he should get a chance soon. If you are not deploying your app to production now you can use the fork to develop your capacitor app, and then once this gets merged you can switch off the fork and deploy your capacitor app.

@eeerrrttty
Copy link

Hello people! I do have a cordova app in production and, uol... It would be GREAT to use capacitor.

I do use some plugins:

For firebase (notifications and analytics)
Camera.

Would it be compatible?
Will the app now be native?

@nklayman
Copy link
Contributor Author

nklayman commented Oct 6, 2019

If the plugins are compatible with capacitor they should work just fine. I know camera will work, but I'm not sure about firebase, is it a cordova or capacitor plugin? Your app will be "hybrid", meaning it is a native app, but all of your code will run in a webview.

@rstoenescu rstoenescu changed the base branch from dev to capacitor-review October 6, 2019 12:06
@rstoenescu rstoenescu merged commit 424f821 into quasarframework:capacitor-review Oct 6, 2019
@mesqueeb
Copy link
Contributor

Lol, the name quapacitor is so awesome. 🤣

mesqueeb pushed a commit to mesqueeb/quasar that referenced this pull request Feb 2, 2020
…ramework#4475)

* feat(app): add support for building with Capacitor

* feat(app/capacitor): add dev support

* fix(app/capacitor): support yarn workspaces

* fix(app/capacitor): fix dev server host location detection

* feat(app/capacitor): use src-capacitor dir

* fix(app/capacitor): copy package.json on build/dev

* fix(app/mode): crashes if add/remove function returns null

* feat(app/capacitor): require at least one platform to be added

* feat(app/capacitor): automatically install platform if missing

* fix(app/capacitor): rm proper dir on remove

* feat(app/capacitor): add generated package.json to .gitignore

* feat(docs): add instructions for using capacitor

* feat(app/dev): support async mode add

* docs(cli/developing-cordova-apps): remove old folder

* docs(cli/developing-capacitor-apps): rename folder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants