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

Make Xamarin-based CocoaRunner the default on Mac #4802

Merged
merged 7 commits into from Mar 24, 2023

Conversation

dgileadi
Copy link
Contributor

@dgileadi dgileadi commented Aug 3, 2022

This gets the tray icon running for me on macOS 12.5 by changing CocoaRunner to use Xamarin.Mac and making it the default on Mac instead of RumpsRunner.

Huge thanks to @tgorgdotcom for the help with getting this to build. The dependency changes are all thanks to him.

@tgorgdotcom
Copy link

This seems to be working on my end in macOS 12.3.

@dgileadi
Copy link
Contributor Author

dgileadi commented Aug 4, 2022

The AppVeyor build failed due to warnings found by BackendToolTests. I added code to get the actual exception from a TargetInvocationException which resulted in:

Backend result warning:2022-08-04 16:38:52 +00 - [Warning-Duplicati.Library.DynamicLoader.DynamicLoader`1-SoftError]: Failed to load process type Duplicati.Library.Backend.MicrosoftGroup assembly C:\projects\duplicati\Duplicati\UnitTest\bin\Debug\Duplicati.Library.Backend.OneDrive.dll, error message: The type initializer for 'Duplicati.Library.Backend.MicrosoftGraphBackend' threw an exception.
Backend result warning:2022-08-04 16:38:52 +00 - [Warning-Duplicati.Library.DynamicLoader.DynamicLoader`1-SoftError]: Failed to load process type Duplicati.Library.Backend.OneDriveV2 assembly C:\projects\duplicati\Duplicati\UnitTest\bin\Debug\Duplicati.Library.Backend.OneDrive.dll, error message: The type initializer for 'Duplicati.Library.Backend.MicrosoftGraphBackend' threw an exception.
Backend result warning:2022-08-04 16:38:52 +00 - [Warning-Duplicati.Library.DynamicLoader.DynamicLoader`1-SoftError]: Failed to load process type Duplicati.Library.Backend.SharePointV2 assembly C:\projects\duplicati\Duplicati\UnitTest\bin\Debug\Duplicati.Library.Backend.OneDrive.dll, error message: The type initializer for 'Duplicati.Library.Backend.MicrosoftGraphBackend' threw an exception.

A local unit test run didn't fail. There are no other details about why MicrosoftGraphBackend threw an exception. I'm not sure where to go from here. Could someone on a Windows system perhaps try this branch out to try to help track down the issue?

@tgorgdotcom
Copy link

Rewriting and reposting because I didn't properly explain this:

I'm trying this on my Windows laptop, and I get the following exception when I run the debug, then try to access the server (http://localhost:8200/):

FileNotFoundException: Could not load file or assembly 'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

This is being triggered from the Duplicati\Library\Backend\OneDrive\MicrosoftGroup.cs, in the MicrosoftGroup object's initializer. Seems to be related to your errors above. If I continue the code execution, the same exception occurs in Duplicati\Library\Backend\OneDrive\OneDriveV2.cs. And if I continue that, another exception occurs in Duplicati\Library\Backend\OneDrive\SharePointV2.cs.

System.Net is indeed used in Duplicati\Library\Backend\OneDrive\MicrosoftGraphBackend.cs, in which the aforementioned code inherits, but I'm not sure why it would be throwing an error.

@tgorgdotcom
Copy link

Just to be sure, I pulled a fresh copy of the original repository and I getting the same errors. I'm thinking maybe we can ignore these then? Any thoughts from the maintainers?

@m-m-m-m-m-m-m-m-m-m-m-m
Copy link

m-m-m-m-m-m-m-m-m-m-m-m commented Sep 4, 2022

This seems to be working on my end in macOS 12.3.

How can I get the application?

@m-m-m-m-m-m-m-m-m-m-m-m
Copy link

This gets the tray icon running for me on macOS 12.5 by changing CocoaRunner to use Xamarin.Mac and making it the default on Mac instead of RumpsRunner.

Huge thanks to @tgorgdotcom for the help with getting this to build. The dependency changes are all thanks to him.

@dgileadi I would like to try your solution, but I dont understand how to build and test it. Could you help me?

@dgileadi
Copy link
Contributor Author

dgileadi commented Nov 2, 2022

@dgileadi I would like to try your solution, but I dont understand how to build and test it. Could you help me?

I'm no expert in building Duplicati since I'm quite new to its code, so I'm not much help. Basically what you'd want to do is get a local copy of my cocoa-mac branch and then build it using Visual Studio for Mac. That may sound simple (or not!) but it's the details and troubleshooting that I wouldn't be much help with.

@duplicatibot
Copy link

This pull request has been mentioned on Duplicati. There might be relevant details there:

https://forum.duplicati.com/t/supportability-of-newer-macos/15515/2

@dgileadi
Copy link
Contributor Author

Okay, for future reference I built Duplicati locally. Here's what I did:

  1. Ran ./make.sh to make duplicati. This creates a file named Installer/Makefile/duplicati.tar.gz
  2. Manually extract that file which creates a directory tree starting with usr
  3. Re-zip all the files under the extracted usr/lib/duplicati into a new .zip file which I called Duplicati-osxtray.zip
  4. Cd into Installer/OSX
  5. Edit make-dmg.sh in that directory to add a new line 203: hdiutil resize -size 128m "$WC_DMG" (just before the comment that says "# Make a mount point and mount the new dmg"). This fixes issues where files failed to copy because there was no more room on the .dmg.
  6. Run ./make-dmg.sh ../Duplicati-osxtray.zip (where the argument is the path where I put my .zip file)
  7. Enter my local machine's password to make sudo happy

After the above finishes a new file named Duplicati.dmg will exist inside Installer/OSX, and you can use that to install Duplicati. Note that Gatekeeper may give you trouble running it since it is unsigned. Right-clicking on the newly installed Duplicati.app and choosing Open worked for me.

@duplicatibot
Copy link

This pull request has been mentioned on Duplicati. There might be relevant details there:

https://forum.duplicati.com/t/is-duplicati-kind-of-abandoned/15791/2

@dgileadi
Copy link
Contributor Author

dgileadi commented Mar 1, 2023

I've made a test release for anyone wanting to try this out.

@duplicatibot
Copy link

This pull request has been mentioned on Duplicati. There might be relevant details there:

https://forum.duplicati.com/t/duplicati-not-starting-on-macos-monterey-12-3-on-m1/14096/19

@bob787
Copy link

bob787 commented Mar 2, 2023

Happy day! Thank you @dgileadi!

It works just like the pre-Monterey Duplicati versions. I will keep it on my bench and let it run a simple backup and restore loop for a few days to see if issues arise.

@gpatel-fr
Copy link
Contributor

Hello @dgileadi

I don't understand why your PR has changes in the AWS and IDrive backends - what is the relation to the TrayIcon ?

@dgileadi
Copy link
Contributor Author

dgileadi commented Mar 4, 2023

Hello @dgileadi

I don't understand why your PR has changes in the AWS and IDrive backends - what is the relation to the TrayIcon ?

The changes were necessary to get the project to build on macOS. Visual Studio on macOS originally generated a much messier set of changes but @tgorgdotcom helped make them more manageable.

@gpatel-fr
Copy link
Contributor

Hmm.. is this generated by the quirks of VS, or is it necessary for some mysterious reason. I have generated a build of your PR in my test repo, I think that I will generate another while removing these curious refs in IDrive and AWS backends to see how it goes.

@gpatel-fr
Copy link
Contributor

@dgileadi
I have actually done 2 builds, one without the backends:
https://github.com/gpatel-fr/testdupl/actions/runs/4336388168

and one without the backends AND bouncycastle reference:
https://github.com/gpatel-fr/testdupl/actions/runs/4336935079
never mind the test failure, it's obviously unrelated.

I have found that BouncyCastle lib was explicitly removed from Duplicati in 2021, so adding it back if it's not necessary would have 2 problems: adding some size to all downloads, and possibly involve license problem - so-called 'liberal' licenses involve publicity in their terms and if it's added to a project, there should be an aknowledgement somewhere - that could have been removed in 2021.
I have no idea why this ref has been added by your dev environment; either there is a real dependency on the Xamarin based CocaRunner on this lib (in this case the price has to be paid), or there is somewhere in the Duplicati internals a not so obvious ref to this library that is picked up ("helpfully") by the dev environment to add it back to the project. In this case it's not good.

Anyway, test of these Mac binaries would be very interesting, I don't know anything about dependencies on OSX, if there could be a library staying from a previous install that is picked up by a new install (in this case the binary could work on a already installed computer, but not on a 'new' one). If it is the case, well, a freshly installed computer would be the best to test if this works as intended.

@dgileadi
Copy link
Contributor Author

dgileadi commented Mar 6, 2023

Hi @gpatel-fr, for the BouncyCastle dependency see the discussion in issue #4668 (search for BouncyCastle in the comments) and the discussion in PR #4800. It appears the dependency is needed when Xamarin AppKit is used.

I tried both your builds and weirdly neither one showed a menu bar icon for me. The Activity Monitor app showed Duplicati briefly starting and then quitting. Maybe someone else can try them out?

@gpatel-fr
Copy link
Contributor

All right, then. This build was generated with the original PR:

https://github.com/gpatel-fr/testdupl/actions/runs/4332749394

From the log, it was compiled on a OSX 12.6 runner. Is the Mac binary in this build working as intended ? If yes, I'll take care of digging the old ref to BouncyCastle in the doc files and adding it back to satisfy the software license advertising clause.

@dgileadi
Copy link
Contributor Author

dgileadi commented Mar 6, 2023

@gpatel-fr this latest build has the same behavior for me as the other two builds—it briefly appears in Activity Monitor and then quits again, and never shows a menu bar icon. I'm not sure how to check what the trouble is—does anyone know where any logs might be found?

@gpatel-fr
Copy link
Contributor

gpatel-fr commented Mar 6, 2023

This is very annoying to say the least, since this build command file has been ripped out of the normal build file - this particular file runs only on the original Duplicati author's computer.
I will have to double check that I did not leave out something necessary.
Maybe running the command as mono Duplicati.Gui.TrayIcon.exe in a command terminal ? That's what I would try under Windows. Under Windows there is ProcessMonitor, I don't know what's the equivalent could be under OSX. Internet search suggests a tool called 'Glances'.

Edit: obviously something I left out is the notarising of the applicatlon. But it should be the same for your build I guess ? And other people have tested your build and it worked on their computer. What's the version of your computer and dev tools ?

@gpatel-fr
Copy link
Contributor

I think I have found the problem. Could you please try this build:

https://github.com/gpatel-fr/dupltest/actions/runs/4354235641

@dgileadi
Copy link
Contributor Author

dgileadi commented Mar 7, 2023

I think I have found the problem. Could you please try this build:

https://github.com/gpatel-fr/dupltest/actions/runs/4354235641

That one works for me. Nice job, whatever you did!

Edit: as for notarizing, you're right that neither your nor my build are notarized. As such you need to go through a dance of right-clicking on the application and choosing open a couple times before it'll let you run it. For a real distributable build it'd be really nice to get the GitHub actions nicely notarizing the Mac builds at some point.

@gpatel-fr
Copy link
Contributor

What I did is to look closely at the official build (the one running on the original author's computer), your build (based on the Linux build actually), and the build in the automatic build I am trying to setup on Github. I realized then that the installer build on Github is very similar to the other builds, except an additional parameter enabling Gtk. In all probability Gtk could never has been be useful to Duplicati for another thing than the Tray Icon, while there was absolutely no use for it in the automatic build on Github, since there is no graphical user interface for the runners.
I had then the suspicion that the inclusion of Gtk in the Github test builds was but a fossil of another epoch, something that was no use whatsoever as the Tray Icon can't be tested in a Github runner, the builds on Github could never has been actually run on an actual computer, or not since quite some time, but it had never become apparent since nobody had until now tried to create an installer based on them.

About the notarization, the secrets are on the original author computer, not on Github. My current priority is to get a new release that works, at the moment the actual notarized build will still come from this computer by the original author. That's awkward but there are more urgent problems IMO.

My immediate plan is to release a binary build on the forum with all the planned changes included this PR and asking for a feedback given the character of this release. Hopefully I'll get a test for each of the platforms at least, if nothing obviously bad is reported it will become a canary ASAP.

@bob787
Copy link

bob787 commented Mar 7, 2023

Happy to test the Mac versions. I will continue to monitor this thread

@gpatel-fr
Copy link
Contributor

@duplicatibot
Copy link

This pull request has been mentioned on Duplicati. There might be relevant details there:

https://forum.duplicati.com/t/preview-of-security-and-bugfix-release-canary-105/15925/32

@gpatel-fr gpatel-fr merged commit 9302aab into duplicati:master Mar 24, 2023
@earthsound
Copy link

With version 2.0.6.105, as mentioned in the forum, I'm seeing this error when running mono Duplicati.GUI.TrayIcon.exe --toolkit=cocoa:

2023-04-19 13:02:55.590 mono-sgen64[2793:41223] Could not find `appindicator-sharp` referenced by assembly `Duplicati.GUI.TrayIcon, Version=2.0.6.105, Culture=neutral, PublicKeyToken=null`.
Unexpected error: System.IO.FileNotFoundException: Could not load the file 'appindicator-sharp'.
File name: 'appindicator-sharp'
  at System.AppDomain.Load (System.Reflection.AssemblyName assemblyRef, System.Security.Policy.Evidence assemblySecurity) [0x0007a] in <b814b509d4ad406fb40c6c93e38929e7>:0 
  at (wrapper remoting-invoke-with-check) System.AppDomain.Load(System.Reflection.AssemblyName,System.Security.Policy.Evidence)
  at System.AppDomain.Load (System.Reflection.AssemblyName assemblyRef) [0x00000] in <b814b509d4ad406fb40c6c93e38929e7>:0 
  at (wrapper remoting-invoke-with-check) System.AppDomain.Load(System.Reflection.AssemblyName)
  at System.Reflection.Assembly.Load (System.Reflection.AssemblyName assemblyRef) [0x00005] in <b814b509d4ad406fb40c6c93e38929e7>:0 
  at ObjCRuntime.Runtime.CollectReferencedAssemblies (System.Collections.Generic.List`1[T] assemblies, System.Reflection.Assembly assembly) [0x000a0] in <e4522fda950a42e1a61f97b36f071593>:0 
  at ObjCRuntime.Runtime.RegisterEntryAssembly (System.Reflection.Assembly entry_assembly) [0x0002f] in <e4522fda950a42e1a61f97b36f071593>:0 
  at ObjCRuntime.Runtime.RegisterAssemblies () [0x00006] in <e4522fda950a42e1a61f97b36f071593>:0 
  at AppKit.NSApplication.Init () [0x00022] in <e4522fda950a42e1a61f97b36f071593>:0 
  at Duplicati.GUI.TrayIcon.CocoaRunner.Init (System.String[] args) [0x00001] in <e98c34ad898147e8a9669bdece28c5ac>:0 
  at Duplicati.GUI.TrayIcon.Program.StartTray (System.String[] _args, System.Collections.Generic.Dictionary`2[TKey,TValue] options, System.String toolkit, Duplicati.GUI.TrayIcon.HostedInstanceKeeper hosted, System.String password, System.Boolean saltedpassword) [0x000f9] in <e98c34ad898147e8a9669bdece28c5ac>:0 

Would you prefer I open an issue referencing this?

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.

None yet

7 participants