how to add own native service in Gluon app - gluon-mobile

I would like to add sms and email native services (similar to Dialer service) to a Gluon application.
I have seen some information regarding the previous version "gluon charms down", but nothing for the later version "gluon attach" ...
Is it still possible to add my own native services in a gluon app using "gluon attach"?
I am using maven with com.gluonhq:client-maven-plugin:0.1.32

Alright, so the only way I found was to generate my own version of attach, with the additional service. There are 2 steps (in bold) which are unexpected:
A.Make a copy of https://github.com/gluonhq/attach
create a new module 'e.g.mynative' as a copy of an existing one. in the new module rename files and ids accordingly
in settings.gradle add lines:
include 'mynative'
...
project(':mynative...
In ./util/src/main/native/android/c/util.c,
add the lines:
static jclass jMynativeServiceClass;
...
jclass substrateGetRinkainativeServiceClass() {
return GETREGISTERCLASS(jMynativeServiceClass,
"com/gluonhq/helloandroid/DalvikMynativeService");
}
install
./gradlew publishToMavenLocal
B. Make a copy of https://github.com/gluonhq/client-maven-plugin
In ./src/main/java/com/gluonhq/attach/AttachService.java add 'MYNATIVE' enum value
install:
mvn clean package install
C. Consume service in your gluon mobile app
update version for client-maven-plugin plugin and attach dependency to the ones used in the steps above i.e. xxx-SNAPSHOT
in com.gluonhq:client-maven-plugin configuration add mynative to attachlist
use as other attach services, e.g
Services.get(MynativeService.class).ifPresent(service -> {
System.err.println("connected:"+service.connectedProperty().get());
});
Then to run on android:
mvn -o -P android clean client:build client:package client:install client:run
I have not tried it on IOS

Related

iOS Sourcery with Flutter build

Im trying to build my flutter app for iOS it has a google maps key that I want to protect and not check in to source control it needs to be buildable from azure, to achieve this I'm storing my maps key as a secret variable in azure and as a system environment variable locally, I'm using Sourcery https://github.com/krzysztofzablocki/Sourcery to generate a class for me that contains this key, it all works but only the second time I build, the first build always fails.
So I'm building using this command
flutter build ios --flavor dev --verbose
Which the first run will give me the error
error: Build input file cannot be found:
'/Users/martin/xxx/xxx/xxx/ios/Runner/Credentials.generated.swift' (in target
'Runner'
Then issuing the same command again
** BUILD SUCCEEDED **
this is my run script its called before compile sources and after the flutter run script
this calls my script which calls another script to export the map api key and runs sourcery command using a .yml file as its config heres the script, (it also does some logging)
#!/bin/bash
echo "Generate Credentials Code"
CREDENTIALS_DIR="$SRCROOT/credentials"
# Set credentials if local script for adding environment variables exist
if [ -f "$CREDENTIALS_DIR/add_credentials_to_env.sh" ]; then
echo "Add credentials to environement"
source "$CREDENTIALS_DIR/add_credentials_to_env.sh"
echo "finished running add_credentials_to_env.sh"
fi
echo "RUN SOURCERY"
$SRCROOT/Pods/Sourcery/bin/sourcery --config "$SRCROOT/config.yml"
echo "FINISHED RUNNING SOURCERY"
for file in "$SRCROOT/Runner"/*; do
echo "$file"
done
and here is my config file
sources:
- .
project:
file: Runner.xcodeproj
target:
name: Runner
module: Runner
templates:
- credentials/Credentials.stencil
output:
path: ./Runner/
link:
project: Runner.xcodeproj
target: Runner
args:
mapsApiKey: ${MAPS_API_KEY_IOS}
this generates my class correctly on the first build and seems to be added correctly to the target (edited out my key) but the app will only compile if I run the build command again.
// Generated using Sourcery 1.4.2 — https://github.com/krzysztofzablocki/Sourcery
// DO NOT EDIT
public struct Credentials {
let mapsApiKey: String
}
public let credentials = Credentials(mapsApiKey:
"xxxxxxxxxxMY_KEYxxxxxxxxxxx")
Any ideas?
xcode 12.5 m1 macbook pro, swift 5
Looks like you generate the file too late. I'll suggest move your script to Aggregate and add it as a dependency to your target
Add Aggregate
Move your script to 'Run script' section
Add 'PreBuildScriptsRunner' as a dependency to your application target, make sure 'Dependencies' section on top of all other sections
Manually setting environment variables is an annoying thing developers would have to do on their own machines, and there are nicer/ more common ways of setting up private keys. After a few years of using environment variables/ bash, it still causes issues which are not easily detectable. You may want to automate/ document it, but then you have to consider developers using zsh, fish vs. bash? Also, I try to avoid using Xcode build phases where possible.
Solution? (This is what I have)
Why don't you use your CI (Azure pipeline?, I use Github workflows) to write a Xcode build configuration file (not a Swift file). The sensitive keys could be in a file Secrets.xcconfig, which is added to your Xcode as a build configuration. Then, in your Info.plist of your application, and your code can load them.
Create a file, Secrets.xcconfig:
SECRET_API_KEY = 12312rfiwhvde.wvascafsf.df325
Add it to your Xcode project, and then to the project's build configuration:
Add Secrets.xcconfig to your .gitignore
Make sure to git ignore the file before committing it to the repo. You can also keep an Example.Secrets.xcconfig which users can use. In the readme, tell users to run cp Example.Secrets.xcconfig Secrets.xcconfig and then to update values in it. Now you can clearly see what keys the application is using (its clearly in the directory). As a bonus, you can add this file the Xcode project, so that when the file is missing, it shows up in red (indicating to the user they really should acquire this file somehow):
In Info.plist, reference the variable:
<dict>
<key>SECRET_API_KEY</key>
<string>$(SECRET_API_KEY)</string>
</dict>
In your code, load the variable that was stored in Info.plist:
let key = Environment.infoDictionary["SECRET_API_KEY"] as? String
In your CI/ Azure pipeline:
Run echo "SECRET_API_KEY = $SECRET_API_KEY_SAVED_IN_CONTINUOUS_INTEGRATION" >> Secrets.xcconfig
Then you can just .gitignore the file instead of setting environment variables. When you work with other developers, you just give them this file, and nothing else needs to be done to build locally.
So I have answered your question not by solving your direct problem, but giving you a more common/ canonical way of solving this problem that many developers have faced before.

Milo - Run configuration settings

I am interested create an Client Interface for a simulation software. So I have downloaded Milo and I went through the examples. I was able to build successfully when I executed mvn clean package. I would like to know how to set the run configuration for executing the Client Example.java.
In the client-examples project. Look into the ClientExample.java source file. In this file
update the method getEndpointUrl for server Endpoints. By default this method has a loop back Endpoints i.e :"opc.tcp://localhost:12686/milo".

How to install waf?

I have cloned and built the waf script using:
./waf-light configure
Then to build my project (provided by Gomspace) I need to add waf and the eclipse.py to my path. So far I haven't found better than this setenv script:
WAFROOT=~/git/waf/
export PYTHONPATH=$WAFROOT/waflib/extras/:$PYTHONPATH
export PATH=~/git/waf/:$PATH
Called with:
source setenv
This is somehow a pretty ugly solution. Is there a more elegant way to install waf?
You don't install waf. The command you found correctly builds waf: /waf-light configure build Then for each project you create, you put the built waf script into that projects root directory. I can't find a reference, but this is the way in which waf:s primary author Thomas Nagy wants the tool to be used. Projects that repackage waf to make the tool installable aren't "officially sanctioned."
There are advantages and disadvantages with non-installation:
Disadvantages:
You have to add the semi-binary 100kb large waf file to your repository.
Because the file contains binary code, people can have legal objections to distributing it.
Advantages:
It doesn't matter if new versions of waf break the old API.
Users don't need to install waf before compiling the project -- having Python on the system is enough.
Fedora (at least Fedora 22) has a yum package for waf, so you could see that it's possible to do a system install of waf, albeit with a hack.
After you run something like python3 ./waf-light configure build, you'll get a file called waf that's actually a Python script with some binary data at the end. If you put it into /usr/bin and run it as non-root, you'll get an error because it fails to create a directory in /usr/bin. If you run it as root, you'll get the new directory and /usr/bin/waf runs normally.
Here's the trick that I learned from examining the find_lib() function in the waf Python script.
Copy the waf to /usr/bin/waf
As root, run /usr/bin/waf. Notice that it creates a directory. You'll see something like /usr/bin/.waf-2.0.19-b2f63c807a4215294bf6005410c74c18
mv that directory to /usr/lib, dropping the . in the directory name, e.g. mv /usr/bin/.waf-2.0.19-b2f63c807a4215294bf6005410c74c18 /usr/lib/waf-2.0.19-b2f63c807a4215294bf6005410c74c18
If you want to use waf with Python3, repeat Steps 2-3 running the Python script /usr/bin/waf under Python3. Under Python3, the directory names will start with .waf3-/waf3- instead instead of .waf-/waf-.
(Optional) Remove the binary data at the end of /usr/bin/waf.
Now, non-root should be able to just use /usr/bin/waf.
That said, here's something to consider, like what another answer said: I believe waf's author intended waf to be embedded in projects so that each project can use its own version of waf without fear that a project will fail to build when there are newer versions of waf. Thus, the one-global-version use case seems to be not officially supported.

Compile and build chromium browser for electron

So I am developing an electron application. I know electron is running a chromium browser in its core.
One of the use cases I am currently working on involves changing the source code of Chromium. I have cloned the Chromium project and made the changes. Now is it possible to use my version of Chromium to build my electron application?
If yes, how can I do it? If no, what are the alternatives?
So I had to basically rebuild the entire electron code.
Get the libchromium source from here
To modify the code in content module of electron we have to write a patch in libchromium/patches.
And then build libchromiumcontent :
./scripts/bootstrap
./scripts/update
Compile and package libchromiumcontent with the following commands:
./script/build
./script/create-dist
After the build is done, take note of the hash from the libchromiumcontent commit that includes your patch and perform the following commands, replacing your operating system and architecture as appropriate:
# Use either win|linux|osx to reference the platform
mkdir -p osx/x64/<commit>
mv libchromiumcontent* osx/x64/<commit>
And then build Electron with our custom libchromiumcontent :
Clone electron if you have not done already
git clone https://github.com/atom/electron && cd electron
Bootstrap Electron with our custom libchromiumcontent:
./script/bootstrap.py -v --url file:///path/to/libchromiumcontent
And finally build Electron:
./script/build.py -c D

use Google spreadsheet connector wso2

I would like to use the google spreadsheet connector at https://github.com/wso2/esb-connectors/tree/048e223c037b447c3f77c2b7e72338dc26ea5c46/googlespreadsheet. But it is not found in wso2 store. I would like to know how I can compile it and use the connector from github. Please help
Generally git wont allow you to get a folder. so you need to go with svn approach. follow bellow instruction as it is. (assumtion on you are woking in linux / mac enviorment. if not make the command the way works on windows.
create new directory where ever you want and navigate inside that
wget https://raw.githubusercontent.com/wso2/esb-connectors/048e223c037b447c3f77c2b7e72338dc26ea5c46/pom.xml
mkdir wso2
cd wso2
mkdir esbconnector
cd esbconnector/
mkdir googlespreadhseet
cd googlespreadhseet/
svn checkout https://github.com/wso2/esb-connectors/trunk/googlespreadsheet/googlespreadsheet-connector/googlespreadsheet-connector-2.0.0/org.wso2.carbon.connector
cd org.wso2.carbon.connector/
mvn clean install
it may take little time as its required to download few artifacts. if its ended up with error that integration test not found get the integration test Base from the same repo and build that first. then rebuild the connector
Recently Google spreadsheet Version2 connector has been created with REST API and added to WSO2 store. The Connector zip file can be downloaded from here. Go to the link and click the 'download connector' button and follow the documentation for the configuration.
You can checkout the connector source from the https://github.com/wso2/esb-connectors/blob/master/googlespreadsheet and built it.
Then add the connector to the ESB from the UI according to the https://docs.wso2.com/display/ESB481/Managing+Connectors+in+Your+ESB+Instance

Resources