I am developing a flutter desktop app for windows. I want to use dart-defines to configure the text shown in the window title. To do it in Dart code is not a problem, but thats too late, because the window title is already set in the native c++ part, before the Dart code executes.
I start my application with flutter run --dart-define=APP_TITLE=AwesomeApp. If I access the environment variable APP_TITLE within Dart code it works as I expect:
const appTitle= String.fromEnvironment('APP_TITLE', defaultValue: 'Not Found');
debugPrint("App Title: " + appTitle); // -> App Title: AwesomeApp
But if I try to access the environment variable from the main.cpp where the window title is defined, I cannot access it.
#include <iostream>
#include <cstdlib>
std::string getVariable(std::string const& name) {
size_t size;
getenv_s(&size, nullptr, 0, name.c_str());
if (size > 0) {
char* tmpvar = new char[size];
errno_t result = getenv_s(&size, tmpvar, size, name.c_str());
std::string var = (result == 0 ? std::string(tmpvar) : "");
delete[] tmpvar;
return var;
}
return "";
}
int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
_In_ wchar_t *command_line, _In_ int show_command) {
...
std::string appTitle = getVariable("APP_TITLE");
if(appTitle != "")
std::cout << "App Title: " << appTitle << std::endl;
else
std::cout << "App Title: " << "Not Found" << std::endl; // -> App Title: Not Found
...
}
For most usecases access of environment variables within Dart code is sufficient. But the window title need to be defined in the native main.cpp optimally.
Am I doing a mistake or is it just not possible to access the dart-defines at native level? What is the suggested way of configuring a flutter desktop application for different envrionments like dev or prod.
Related
I would need a simple working example (using Gtkmm 3) of a ShortcutsWindow with just one ShortcutsShortcut that does not use a Gtk::Builder.
I have not been able to find such an example online. I am able to show window however shortcuts do not show.
Here is a very simple example. You can build from it:
#include <gtkmm.h>
#include <iostream>
class MyShortcutsWindow : public Gtk::ShortcutsWindow
{
public:
MyShortcutsWindow();
private:
Gtk::ShortcutsShortcut m_shortcut;
Gtk::ShortcutsGroup m_group;
Gtk::ShortcutsSection m_section;
};
MyShortcutsWindow::MyShortcutsWindow()
{
// Prints Gtkmm version:
std::cout << "Gtkmm version : "
<< gtk_get_major_version() << "."
<< gtk_get_minor_version() << "."
<< gtk_get_micro_version()
<< std::endl;
// 1. Create shorcut:
// -------------------------------------------------------------
// Set title:
auto shortcutTitle = m_shortcut.property_title();
shortcutTitle.set_value("Hit that to search");
// Set type:
auto shortcutType = m_shortcut.property_shortcut_type();
shortcutType.set_value(Gtk::SHORTCUT_ACCELERATOR);
// Set accelerator:
auto shortcutAccelerator = m_shortcut.property_accelerator();
shortcutAccelerator.set_value("<Ctrl>f");
// 2. Create shortcut group:
// -------------------------------------------------------------
m_group.add(m_shortcut);
// 3. Create shortcut section:
// -------------------------------------------------------------
m_section.add(m_group);
// Make sure your section is visible. I have found if this is
// not called, your section won't show until you have tried a
// search first (weird):
auto sectionVisibility = m_section.property_visible();
sectionVisibility.set_value(true);
// 4. Add the section to the window:
// -------------------------------------------------------------
add(m_section);
}
int main(int argc, char *argv[])
{
auto app = Gtk::Application::create(argc, argv, "so.question.q66123196");
MyShortcutsWindow window;
window.show_all();
return app->run(window);
}
It works with Gtkmm version 3.22.30 in my case. You need at most version 3.20 according to the docs.
Following up on BobMorane's answer: Calling show_all() on your Gtk::ShortcutsSection object will provide the same result as setting property_visible to true.
In the example provided:
m_section.add(m_group);
m_section.show_all();
// 4. Add the section to the window:
// -------------------------------------------------------------
add(m_section);
I got the api sauce and I'm editing it.
When you inject the api, the console comes out and tells you to enter the command there.
I just want to erase the console that comes out by injecting api, inject and execute what I wrote as a command into the C# text box, but it didn't go well.
So I fixed the code in the console window, aenter image description herend Roblox crashed.
Tell me how to solve this problem.
And I will show you the status code with the console coming out and the code with the error after fixing it without the console coming out. Make sure the console doesn't come out, and if the command you wrote down in the text box presses the Execute button, let Roblox run it.
Code before modification (state with console)
void main()
{
ShowWindow(GetConsoleWindow(), 0);
CONSOLEBYPASS();
freopen("CONOUT$", "w", stdout);
freopen("CONIN$", "r", stdin);
HWND ConsoleHandle = GetConsoleWindow();
SetWindowPos(ConsoleHandle, HWND_TOPMOST, 50, 20, 0, 0, SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
ShowWindow(ConsoleHandle, 1);
SetConsoleTitle("Sxploit // Credits to Aero // Updated by L");
XHosted::Run(XHosted::GetVersion());
//XHosted::XDumper();
RobloxState = XHosted::GetRState();
VanillaState = luaL_newstate();
BreakPointsInit();
luaL_openlibs(VanillaState);
luaL_newmetatable(VanillaState, "garbagecollector");
lua_pushcfunction(VanillaState, UserDataGC);
lua_setfield(VanillaState, -2, "gc");
lua_pushvalue(VanillaState, -1);
lua_setfield(VanillaState, -2, "index");
WrapGlobals(RobloxState, VanillaState);
SetLevel(RobloxState, 7);
RegisterShittyFunc(VanillaState);
lua_newtable(VanillaState);
lua_setglobal(VanillaState, "_G");
CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)input, NULL, NULL, NULL);
std::string i;
Execute("warn('Connect to Roblox')");
while (true) {
getline(std::cin, i);
Execute(i.c_str());
i = "";
}
}
BOOL WINAPI CONSOLEBYPASS()
{
DWORD nOldProtect;
if (!VirtualProtect(FreeConsole, 1, PAGE_EXECUTE_READWRITE, &nOldProtect))
return FALSE;
(BYTE)(FreeConsole) = 0xC3; //opcode time
if (!VirtualProtect(FreeConsole, 1, nOldProtect, &nOldProtect))
return FALSE;
AllocConsole();
}
Code after modification (the console does not come out, but the Inject causes the Roblox to crash)
void main()
{
BreakPointsInit();
luaL_openlibs(VanillaState);
luaL_newmetatable(VanillaState, "garbagecollector");
lua_pushcfunction(VanillaState, UserDataGC);
lua_setfield(VanillaState, -2, "gc");
lua_pushvalue(VanillaState, -1);
lua_setfield(VanillaState, -2, "index");
WrapGlobals(RobloxState, VanillaState);
SetLevel(RobloxState, 6);
RegisterShittyFunc(VanillaState);
lua_newtable(VanillaState);
lua_setglobal(VanillaState, "_G");
CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)input, NULL, NULL, NULL);
std::string i;
Execute("warn('Connect to Roblox')");
}
The picture over there is the console window I want to erase.
You cant remove that console app from here, this console is used to push lua script that given by pipes from your exploit to roblox, the only way how to teke out that console is to hide it.
As i understand this is a c++ code right?
void HideConsole()
{
::ShowWindow(::GetConsoleWindow(), SW_HIDE);
}
You're using Axon Source i can see, you can give the code pls?
//Necesary for hide console
#include <Windows.h>
//Hide Console
void HideConsole()
{
::ShowWindow(::GetConsoleWindow(), SW_HIDE);
}
//Check Is Console Visible
bool IsConsoleVisible()
{
return ::IsWindowVisible(::GetConsoleWindow()) != FALSE;
}
Axon is currently entirely patched, I would suggest checking out Imperious Transpiler with more stability and actually working!
Check it here: https://v3rmillion.net/showthread.php?pid=7615717
(Also if you don't know the basic fix for that, I don't think you will be able to update addys every Wednesday.)
I would like to create a custom SWT PrintDialog. However it seems not possible.
In SWT PrintDialog one can click "preferences" to open the native printer driver preferences dialog. Is it possible to open the "native printer driver preferences dialog" without using org.eclipse.swt.printing.PrintDialog and read the drivers preferences (PrinterData)?
PrintDialog is very platform specific. The Mac version, for example, does not have a Preferences option. The class contains a lot of undocumented low level code interfacing to a particular platform. It is possible to use the low level code in your own class but this is not supported and you would need some experience of the platform API.
Just to illustrate the difference, here is the first few lines of the open method on Windows:
public PrinterData open() {
/* Get the owner HWND for the dialog */
Control parent = getParent();
int style = getStyle();
long /*int*/ hwndOwner = parent.handle;
long /*int*/ hwndParent = parent.handle;
and the Mac OS X code:
public PrinterData open() {
PrinterData data = null;
NSPrintPanel panel = NSPrintPanel.printPanel();
NSPrintInfo printInfo = new NSPrintInfo(NSPrintInfo.sharedPrintInfo().copy());
if (printerData.duplex != SWT.DEFAULT) {
long /*int*/ settings = printInfo.PMPrintSettings();
and Linux:
public PrinterData open() {
if (OS.GTK_VERSION < OS.VERSION (2, 10, 0)) {
return Printer.getDefaultPrinterData();
} else {
byte [] titleBytes = Converter.wcsToMbcs (null, getText(), true);
long /*int*/ topHandle = getParent().handle;
while (topHandle != 0 && !OS.GTK_IS_WINDOW(topHandle)) {
topHandle = OS.gtk_widget_get_parent(topHandle);
}
I implemented a native File Picker on BlackBerry 10, after a bit of messing around it finally recognised the class, it opens fine and returns the file Address on the console but it looks like two signals are not working properly, baring in mind this is pretty much a straight copy of code from BlackBerry 10 docs.
using namespace bb::cascades::pickers;
void Utils::getFile() const{
FilePicker* filePicker = new FilePicker();
filePicker->setType(FileType::Music);
filePicker->setTitle("Select Sound");
filePicker->setMode(FilePickerMode::Picker);
filePicker->open();
// Connect the fileSelected() signal with the slot.
QObject::connect(filePicker,
SIGNAL(fileSelected(const QStringList&)),
this,
SLOT(onFileSelected(const QStringList&)));
// Connect the canceled() signal with the slot.
QObject::connect(filePicker,
SIGNAL(canceled()),
this,
SLOT(onCanceled()));
}
I wanted it to return the file url to qml with this (works fine with QFileDialog but that wouldn't recognise on my SDK) var test=utils.getFile()
if(test=="") console.debug("empty")
else console.debug(test)
But I'm getting these messages from the console: Object::connect: No such slot Utils::onFileSelected(const QStringList&) in ../src/Utils.cpp:27
Object::connect: No such slot Utils::onCanceled() in ../src/Utils.cpp:33
It is returning undefined from the else in the qml function when it opens,
Does anyone know where I cocked up or how I could get QFileDialog class to be found by the SDK?
I just wanted to give you a bit of an explanation in case you're still having some troubles. The concept's in Qt were a little foreign to me when I started in on it as well.
There are a couple ways you can do this. The easiest would probably be the pure QML route:
import bb.cascades 1.2
import bb.cascades.pickers 1.0
Page {
attachedObjects: [
FilePicker {
id: filePicker
type: FileType.Other
onFileSelected: {
console.log("selected files: " + selectedFiles)
}
}
]
Container {
layout: DockLayout {
}
Button {
id: launchFilePicker
text: qsTr("Open FilePicker")
onClicked: {
filePicker.open();
}
}
}
}
When you click the launchFilePicker button, it will invoke a FilePicker. Once a file is selected, the fileSelected signal will be fired. The slot in this case is the onFileSelected function (predefined), which logs the filepaths of the files that were selected (a parameter from the signal) to the console.
The C++ route is a little more work, but still doable.
If your class file was called Util, then you'd have a Util.h that looks something like this:
#ifndef UTIL_H_
#define UTIL_H_
#include <QObject>
class QStringList;
class Util : public QObject
{
Q_OBJECT
public:
Util(QObject *parent = 0);
Q_INVOKABLE
void getFile() const;
private Q_SLOTS:
void onFileSelected(const QStringList&);
void onCanceled();
};
#endif /* UTIL_H_ */
Note the Q_INVOKABLE getFile() method. Q_INVOKABLE will eventually allow us to call this method directly from QML.
The corresponding Util.cpp would look like:
#include "Util.h"
#include <QDebug>
#include <QStringList>
#include <bb/cascades/pickers/FilePicker>
using namespace bb::cascades;
using namespace bb::cascades::pickers;
Util::Util(QObject *parent) : QObject(parent)
{
}
void Util::getFile() const
{
FilePicker* filePicker = new FilePicker();
filePicker->setType(FileType::Other);
filePicker->setTitle("Select a file");
filePicker->setMode(FilePickerMode::Picker);
filePicker->open();
QObject::connect(
filePicker,
SIGNAL(fileSelected(const QStringList&)),
this,
SLOT(onFileSelected(const QStringList&)));
QObject::connect(
filePicker,
SIGNAL(canceled()),
this,
SLOT(onCanceled()));
}
void Util::onFileSelected(const QStringList &stringList)
{
qDebug() << "selected files: " << stringList;
}
void Util::onCanceled()
{
qDebug() << "onCanceled";
}
To make your Q_INVOKABLE getFile() method available to QML, you'd need to create an instance and set it as a ContextProperty. I do so in my applicationui.cpp like so:
Util *util = new Util(app);
QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);
qml->setContextProperty("_util", util);
Then, you can call this Q_INVOKABLE getFile() method from QML:
Page {
Container {
layout: DockLayout {}
Button {
id: launchFilePicker
text: qsTr("Open FilePicker")
onClicked: {
_util.getFile();
}
}
}
}
Like Richard says, most of the documentation covers how to create signals/slots, so you could review that, but also have a look at some Cascades-Samples on Git.
Hope that helps!!!
I'm trying to follow the instructions in XCode - Code Coverage? and Code Coverage on Xcode 4.4.1
The .gcno files are generated in DerivedData, but I can't get it to generate the .gcda files. When I press the home button the logs say:
Detected an attempt to call a symbol in system libraries that is not present on the iPhone:
fopen$UNIX2003 called from function llvm_gcda_start_file in image MyApp.
(lldb)
As per Xcode Code Coverage and fopen$UNIX2003 and Code coverage with Xcode 4.2 - Missing files
Add the following as a .m file to your project:
#include <stdio.h>
FILE *fopen$UNIX2003( const char *filename, const char *mode )
{
return fopen(filename, mode);
}
size_t fwrite$UNIX2003( const void *a, size_t b, size_t c, FILE *d )
{
return fwrite(a, b, c, d);
}