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

Add GTK support #798

Open
wants to merge 24 commits into
base: dev
Choose a base branch
from
Open

Add GTK support #798

wants to merge 24 commits into from

Conversation

mierzynskim
Copy link

@mierzynskim mierzynskim commented Jan 16, 2019

This PR will add rendering support for GTK #797. PR also includes example for both native GTK and XF backend.
Implementation of drawing an individual pixel may look like a little bit odd but I think that's the most readable version that can be achieved with GTK.
I wasn't sure how to tackle nuspec files for GTK but I assumed we can use the same convention as Xamarin Forms GTK backend and use net45 as target framework (see here).

@mierzynskim mierzynskim changed the title Add GTK support Close #797 Add GTK support Jan 16, 2019
@knocte
Copy link
Contributor

knocte commented Jan 16, 2019

hey @mierzynskim you targetted the wrong branch, can you apply to 'dev' branch instead?

@mierzynskim mierzynskim changed the base branch from master to dev January 16, 2019 14:19
@mierzynskim
Copy link
Author

@knocte yes, sure. Now I targeted dev branch

@@ -0,0 +1,23 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
Copy link
Contributor

Choose a reason for hiding this comment

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

this is a file from your IDE, I think, please remove it from the PR

readme.md Outdated
@@ -4,7 +4,8 @@

![ZXing.Net.Mobile Logo](https://raw.github.com/Redth/ZXing.Net.Mobile/master/zxing.net.mobile_128x128.png)

ZXing.Net.Mobile is a C#/.NET library based on the open source Barcode Library: [ZXing (Zebra Crossing)](https://github.com/zxing/zxing), using the [ZXing.Net Port](https://github.com/micjahn/ZXing.Net). It works with Xamarin.iOS, Xamarin.Android, Xamarin.Mac, and Windows Phone. The goal of ZXing.Net.Mobile is to make scanning barcodes as effortless and painless as possible in your own applications. The new iOS7 AVCaptureSession barcode scanning is now also supported!

ZXing.Net.Mobile is a C#/.NET library based on the open source Barcode Library: [ZXing (Zebra Crossing)](https://github.com/zxing/zxing), using the [ZXing.Net Port](https://github.com/micjahn/ZXing.Net). It works with Xamarin.iOS, Xamarin.Android,Xamarin.Mac, GTK# and Windows Phone. The goal of ZXing.Net.Mobile is to make scanning barcodes as effortless and painless as possible in your own applications. The new iOS7 AVCaptureSession barcode scanning is now also supported!
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: missing a space before "Xamarin.Mac"

this.Show();
this.DeleteEvent += new global::Gtk.DeleteEventHandler(this.OnDeleteEvent);
}
}
Copy link
Contributor

@knocte knocte Jan 16, 2019

Choose a reason for hiding this comment

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

nit: use spaces instead of tabs in this file

Copy link
Author

Choose a reason for hiding this comment

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

I think we can change it because it's autogenerated file 😞

Copy link
Contributor

Choose a reason for hiding this comment

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

mkay

return null;
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

same nit here: spaces instead of tabs

Copy link
Author

Choose a reason for hiding this comment

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

same as above

@knocte
Copy link
Contributor

knocte commented Jan 16, 2019

Mmm, CI doesn't pass because of a weird NuGet error related to .sln or .csproj files:

Executing: "C:/projects/zxing-net-mobile/tools/NuGet.exe" restore "C:/projects/zxing-net-mobile/ZXing.Net.Mobile.Forms.sln" -NonInteractive
MSBuild auto-detection: using msbuild version '15.9.21.664' from 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\bin'.
Error parsing solution file at C:\projects\zxing-net-mobile\ZXing.Net.Mobile.Forms.sln: Exception has been thrown by the target of an invocation.  Error parsing the nested project section in solution file. A project with the GUID "{A7E26AE0-12AF-4CFD-9B1E-3101347CC6F4}" is listed as being nested under project "{2DC0C8D5-DF7F-4D96-886D-D7E83522C9BF}", but does not exist in the solution.  C:\projects\zxing-net-mobile\ZXing.Net.Mobile.Forms.sln
An error occurred when executing task 'libs'.
Error: System.AggregateException: One or more errors occurred. ---> Cake.Core.CakeException: NuGet: Process returned an error (exit code 1).

Did you edit these files manually instead of letting VS change them? :)

@mierzynskim
Copy link
Author

Hmm, I think CI doesn't have GTK installed... I thought it's shipped with Mono by default. I'll add it as external library

@knocte
Copy link
Contributor

knocte commented Jan 16, 2019

Not sure adding it as external lib is the best approach. Maybe download the .msi file that installs these libs and install it non-interactively from the cake files?

@knocte
Copy link
Contributor

knocte commented Jan 16, 2019

@mierzynskim
Copy link
Author

Hard to say. That's the approach XF chose https://github.com/xamarin/Xamarin.Forms/tree/master/Xamarin.Forms.Platform.GTK/Libs

@knocte
Copy link
Contributor

knocte commented Jan 16, 2019

ah ok! if that's the case, you could do the same I guess, just grab the exact same binaries

knocte pushed a commit to nblockchain/ZXing.Net.Xamarin that referenced this pull request Jan 24, 2019
@mierzynskim
Copy link
Author

@Redth I think we have a final version now. I also tested it and it looks like it works fine. Please have a look when you have some time.

@rblanca
Copy link

rblanca commented Sep 3, 2019

Any news? Thanks

@knocte
Copy link
Contributor

knocte commented Feb 25, 2020

@rblanca we have this merged in this fork in case you're interested: https://github.com/nblockchain/ZXing.Net.Xamarin (we also publish this fork on nuget)

@knocte
Copy link
Contributor

knocte commented Mar 15, 2020

@Redth can you include this in 3.0?

@Redth
Copy link
Owner

Redth commented Mar 15, 2020

@knocte I'm super hesitant to add this into the main package, mostly because https://github.com/Redth/ZXing.Net.Mobile/pull/798/files?file-filters%5B%5D=.nuspec#diff-978f915984ac9573cd5e42dfc0550c3fR82-R83

The TFM of net45 isn't really appropriate to use in the main package if the binaries are specifically for GTK apps.

What we maybe could do is release a separate package of ZXing.Net.Mobile.GTK with these binaries in it.

@Redth
Copy link
Owner

Redth commented Mar 15, 2020

@knocte any interest in trying to rebase this PR's work on current master?

@knocte
Copy link
Contributor

knocte commented Mar 15, 2020

The TFM of net45 isn't really appropriate to use in the main package if the binaries are specifically for GTK apps.

What do you mean? what's the issue exactly? I've been using this code for a while now and works perfectly. The proof is this fork we publish on nuget: https://github.com/nblockchain/ZXing.Net.Xamarin and the app that consumes it: https://github.com/nblockchain/geewallet

@Redth
Copy link
Owner

Redth commented Mar 15, 2020

The problem is if I ship code that depends on GTK into an assembly which is in the net45 TFM, and someone tries to install and use the package in say a windows console app, they aren’t going to have a good time of it. Because there is no TFM that exists to pivot on GTK support directly, there’s limited options.

  1. Ship it in a separate nuget package such as ZXing.Net.Mobile.GTK (and use net45 for that) - this is a bit more explicit since you have to opt in by installing the nuget package intentionally which means you likely understand what you are doing and won’t try and use it in the wrong type of app.

  2. See if there’s any sort of MSBuild property that is exposed when an app uses GTK and use a .targets file in the main nuget package to pivot on which assembly gets referenced. This is kind of weird if there isn’t any other non-GTK implementation shipping (which there currently is not).

Basically 1 is less discoverable but much easier to implement than 2.

I’m leaning towards option 1.

@knocte
Copy link
Contributor

knocte commented Mar 15, 2020

and use the package in say a windows console app,

But this is not supported by ZXing.Net.Mobile anyway AFAIU, why not just put a warning about this on the Readme?

@Redth
Copy link
Owner

Redth commented Mar 15, 2020

It's not supported today, but it could be one day. That alone may not be a good enough reason, but generally the practice we use at Microsoft is to use a separate package name for GTK stuff. Take Xamarin.Forms.Platform.GTK for instance.

I think the right thing to do here is the separate package (and one for the Forms implementation too). This means separate .csproj's which I don't love, but I think this is the right choice

@knocte
Copy link
Contributor

knocte commented Mar 15, 2020

It's not supported today, but it could be one day.

One day? AFAIU net45 is the old framework; and these days in the .NET community people are even advocating to stop supporting it because "legacy" and just support .NETCore, why would anyone go in the other direction?

Anyway I understand the point of view (I use GTK myself with Xamarin.Forms) but it looks a bit ugly (because the other nonGTK platforms don't have a separate nuget package).

@Redth
Copy link
Owner

Redth commented Mar 15, 2020

Yes, net45 is old, however net5 is coming, the same problem will exist there. There will be no platform TFM for GTK pivoting. The point is more about unintentionally expressing support for a TFM which you do not actually support. Yes this is still true of a .GTK package but as I said, it's a bit more explicit by naming and the intentional additional install helps to avoid confusion.

Yeah more nuget refs in a project stinks, but I definitely think the trade off is ok in this case.

@knocte
Copy link
Contributor

knocte commented Mar 16, 2020

any interest in trying to rebase this PR's work on current master?

I have interest :) What I'm not sure is if I have time. Especially considering that even if I did the effort of rebasing it, I couldn't adopt the new 3.x verison of ZXing.Net.Mobile right away, because I just realised that you introduced Xamarin.Essentials as a dependency :( What was the motivation for that? It basically would break our setup because XamEssentials doesn't support macOS and Linux+GTK platforms.

knocte added a commit to nblockchain/ZXing.Net.Xamarin that referenced this pull request Sep 17, 2020
knocte added a commit to nblockchain/ZXing.Net.Xamarin that referenced this pull request Sep 17, 2020
knocte added a commit to nblockchain/ZXing.Net.Xamarin that referenced this pull request Sep 17, 2020
knocte added a commit to nblockchain/ZXing.Net.Xamarin that referenced this pull request Sep 17, 2020
knocte added a commit to nblockchain/ZXing.Net.Xamarin that referenced this pull request Sep 17, 2020
knocte added a commit to nblockchain/ZXing.Net.Xamarin that referenced this pull request Sep 17, 2020
knocte added a commit to nblockchain/ZXing.Net.Xamarin that referenced this pull request Sep 17, 2020
knocte added a commit to nblockchain/ZXing.Net.Xamarin that referenced this pull request Sep 17, 2020
knocte added a commit to nblockchain/ZXing.Net.Xamarin that referenced this pull request Sep 17, 2020
knocte added a commit to nblockchain/ZXing.Net.Xamarin that referenced this pull request Aug 14, 2022
knocte added a commit to nblockchain/ZXing.Net.Xamarin that referenced this pull request Aug 14, 2022
knocte added a commit to nblockchain/ZXing.Net.Xamarin that referenced this pull request Aug 14, 2022
knocte pushed a commit to nblockchain/ZXing.Net.Xamarin that referenced this pull request Aug 14, 2022
knocte pushed a commit to nblockchain/ZXing.Net.Xamarin that referenced this pull request Aug 14, 2022
knocte pushed a commit to nblockchain/ZXing.Net.Xamarin that referenced this pull request Aug 14, 2022
knocte pushed a commit to nblockchain/ZXing.Net.Xamarin that referenced this pull request Aug 14, 2022
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

4 participants