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

After Package; Shouldn't path/"pwd" be in resources? path/"pwd" is currently home directory. #1422

Closed
MichaelDimmitt opened this issue May 5, 2017 · 12 comments
Milestone

Comments

@MichaelDimmitt
Copy link
Contributor

MichaelDimmitt commented May 5, 2017

When I make a package "pwd" is the home directory.
"pwd" is not Resources or app's Current location.

code: simple test.rb

Shoes.app do
    @s = stack {}
      button "go!" do
        @out = `PWD`
        @s.clear { para @out }
      end
end

screen shot 2017-05-05 at 3 43 58 pm



Example when I click the "go" button:

When I do not make a package it tells where I ran the script from, which is fine:
screen shot 2017-05-06 at 11 17 32 am

When I make the package it does not tell where I ran the .app from.
screen shot 2017-05-05 at 3 43 47 pm

The program also does not move images to resources folder.
However, I should be able to manually move them to resources folder.
I just need the path to be at Resources inside the Test.app or the path to Test.app.
Having the app be a self contained entity will allow me to run it from other people's computers.

I am aware there are open issues on Packaging.
I did not see an issue solely committed to path location.
If I find the solution to my problem I will comment below.

Thanks for your time reading this issue.
Let me know if you need any further details.

@MichaelDimmitt
Copy link
Contributor Author

MichaelDimmitt commented May 5, 2017

Some notes so that you know what environment is causing this problem:
note: using mac environment

note: in order to get program working I had to add gem 'furoshiki', github: 'shoes/furoshiki'
note: issue #291 helped me figure out to add gem 'furoshiki'; made pull request #1423.

@jasonrclark
Copy link
Member

Hi @MichaelDimmitt! So I'm working on packaging at the moment, so thanks for the report. I haven't had a chance to try and replicate what you're describing in the main issue yet, but I've added it to the backlog I'm trying to tackle in the next month and will chime back with what I find. Will chat more about furoshiki over on the PR you made.

@jasonrclark
Copy link
Member

You're right about the working directory not getting set. Before we push on that, though, it sounds like your concern there is locating images. Is that right?

Rather than putting things in the Mac app Resources, we actually embedding them into the jar alongside the Ruby code. You shouldn't have to copy anything manually, and I've confirmed things are currently being included into the package.

But, we have a bug with #676 which is that basically you can't actually get a sensible path to that file. This is my next bug to squash, and I think once I get that, I'll be able to provide you a nice clean way to reference images that works both inside the package and outside.

Does that make sense and cover what you're looking for?

@MichaelDimmitt
Copy link
Contributor Author

MichaelDimmitt commented May 9, 2017

@jasonrclark glad your fixing the image's and path, nice! 👍 🥇
let me know when the changes are ready to be tested and confirmed.
and I will clone back down shoes 4 and give some feedback.
I think you are right on the money in understanding what I am looking to get out of shoes.

  1. pending path fix on shoes4.
  2. when path is fixed I should be able to access images.

There is a 3rd thing (not sure if possible) relates to (#1184 Bundler.with_clean_env)
note: should I open an issue for this or you want it here?
script execution fix on shoes4. for packaged apps. works unpackaged but not when packaged.
3) pending script execution fix on shoes4 works unpackaged but not when packaged.

I made two practical repositories that I think when new shoes4 changes are applied will serve as examples as something shoes4 being shippable and useful. relates to #1415
I do not mention them for publicity, I think you could find them useful:
(the note at the beginning of install_uninstall_shoes4 is like a checklist, not a critique.)
(the checklist will be removed when shoes4 changes resolve it, 😄 )
https://github.com/MichaelDimmitt/test_shoes4_packaging
https://github.com/MichaelDimmitt/install_uninstall_shoes4

let me know it you have any questions; Hope you enjoy the install_uninstall_shoes4 repo!
I made the two repo's 4 days ago when I made this issue.
At the time because path was in trouble, I needed to clone it into home directory.

@PragTob
Copy link
Member

PragTob commented May 9, 2017

@MichaelDimmitt generally speaking, focussed smaller issues often make for easier management and more a feeling of "yes I accomplished something, it can be closed" + stuff tends not to get lost, e.g. this issue might get closed once we fix the path stuff and if we're not careful enough to open follow up tickets other stuff might get lost :)

@MichaelDimmitt
Copy link
Contributor Author

MichaelDimmitt commented Jun 7, 2017

I was thinking of this as a workaround. Hoping it will not be needed with pre 10 shoes. 😄
@jasonrclark, wondering if this could be of use:

Inside the ruby file:
File.expand_path(File.dirname(__FILE__))
Or using backticks to kernal run bash in the ruby file:
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

Neither were working when I packaged.
However, going off memory I believe DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" is also in path: packagedApp/Content/MacOS/appExecutable.sh

If the result of that script could be passed to the .rb file that I am packaging. (Which I am not sure how to do) that could be a potential workaround gaining sensible paths to files.

@jasonrclark jasonrclark modified the milestones: 4.0.0.pre10, 4.0.0.pre11 Jun 17, 2017
@jasonrclark
Copy link
Member

Hey @MichaelDimmitt! So pre10 is out, and I had a look at your two repos.

In https://github.com/MichaelDimmitt/install_uninstall_shoes4, I found that you can just replace those image calls with image "app/images/install.png" and they now get properly loaded.

As far as the working directory, there isn't a consistent place for us to point with packages, especially cross-OS. The reason is that the spot we should point is where your Ruby code lives... but that isn't actually in a normal directory. It's embedded inside of a JAR file that JRuby knows how to work inside of. Even where that JAR is placed differs from Mac to Windows to Linux, so there's no one place we can point at startup that would be the same across apps.

That said, we can still get to what you're looking to accomplish with executing scripts. To achieve that install/uninstall behavior, here's what you can do:

  • Read the script file contents with a relative file path in Ruby like this:
script = File.read(File.join(__FILE__, "../app/install_driver.sh"))
  • Once you have that script, write it out to a temporary file that you mark executable
  • Execute your newly created script from that new location

(As a side-note, there's also a new value available at Shoes.configuration.app_dir which points where your app is starting that you can do relative paths from... but in a packaged app it is still an embedded location, so you can't directly shell execute files from there)

Hope that makes sense and happy to follow up if any of it isn't clear. FWIW, I'm not seeing other reasonable changes Shoes can make to simplify this now, so hoping that if this path works for you we can close this issue out.

Thanks again for the report and the repos!

@MichaelDimmitt
Copy link
Contributor Author

MichaelDimmitt commented Jun 20, 2017

@jasonrclark, Awesome feedback. Thanks for the work on pre 10. 😸
for packaging:

  1. Images working like a charm!
  2. Able to read the file using the code you suggested
  3. pending... redirecting into a file making that file executable and running that file.
    Stay tuned for final confirmation. 😄

When complete, I will update the example repositories to incorporate the change.
So that others can use shoes4 as a gui for installing and uninstalling a program.

@MichaelDimmitt
Copy link
Contributor Author

MichaelDimmitt commented Jul 4, 2017

@jasonrclark,
instead of script = File.read(File.join(__FILE__, "../app/install_driver.sh"))

If I convert from shell script to a ruby script. then ... inside the Shoes.rb upon a decision,
User Click = load 'shoes-app/app/uninstall_driver.rb'

With that addition my packaged application can run ruby scripts, but that is fine for my purposes. Scripts in other languages and executables I was unable to program the solution suggested..

Example that contains my solution (ruby scripts) for packaging:

https://github.com/MichaelDimmitt/install_uninstall_shoes4

@jasonrclark
Copy link
Member

Hey @MichaelDimmitt! Wanted to make sure I knew what I was talking about, so cooked up a small sample over in this repo.

Since you've worked around things for now and have that sample you could look to, I'm going to close this out at this point. Feel free to open other issues if you hit specific problems proceeding, though, and thanks for all the reports and help! ✨

@MichaelDimmitt
Copy link
Contributor Author

MichaelDimmitt commented Jul 10, 2017

@jasonrclark, Much thanks on the code assist 🔥 🔥 🔥

  1. shell scripts work.
  2. ruby scripts work.

I ran into trouble opening a mac application.
To solve my problem my install and uninstall clone the application to the home directory and open the mac applications via bash script. Below I am going to show 3 examples.

Example 1: the commit where install_uninstall_shoes4 scripts work correctly,
https://github.com/MichaelDimmitt/install_uninstall_shoes4/tree/865ab584f9c8d808b9abf67bca33837aa61e1055

Example 2: Repository containing solely the packaged project. The project changes mac desktop background. It clones and runs the executables from another github repository. It does not contain any of the packaging code.
https://github.com/MichaelDimmitt/aerial_desktop_with_shoes/tree/packaged

Example 3: Same as example 2 with packaging code and without the packaged project,
https://github.com/MichaelDimmitt/aerial_desktop_with_shoes

Did you enjoy any of these examples? Would you like for me to contribute any thing to shoes4? Would be happy to update these examples in anyway or further add functionality in this area. I am going to look into the Shoes4 size issue next. The packaged app referenced in this comment... example2 is super generic. It clones all of the files it needs from another repository on github and app.jar is 62 mb. I have a few ideas on how to cut it down. Thanks for the great support as I progressed to where I have finally reached my finish line. It may be slow to clone a foreign repository down. But it does seem the simplest solution. Since I do not have to rewrite all 4 of my mac applications and the scripts related to them from the packaged jar file.

Would appreciate your thoughts. What does the shoes4 community think the better practice for installing and uninstalling? A script that clones down and then executes the code or converting the code out of the jar file and then executing it?
Regards, Michael Dimmitt.

@MichaelDimmitt
Copy link
Contributor Author

MichaelDimmitt commented Jul 10, 2017

I know this shouldn't be here but I wanted to mention it. @jasonrclark @PragTob
Wrote a nifty script. My install uninstall packages are fairly simple. So I removed all of the gems that I could from the jar file. Shrunk the Jar file down from 63mb to 35mb with program retaining functionality. https://github.com/MichaelDimmitt/aerial_desktop_with_shoes/blob/fb4fa115d0825db72e4df03b2a6d3d5bb9df948c/script.sh

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

No branches or pull requests

3 participants