How to change sharedpreferences in fxos App - firefox-os

I need to change a shared preference on fxos (firefoxOS 1.3 or newer).
The APIs C Code is reading the preference like this:
switch (Preferences::GetInt("dom.fmradio.band", BAND_87500_108000_kHz)) {
case BAND_76000_90000_kHz:
mUpperBoundInKHz = 90000;
mLowerBoundInKHz = 76000;
break;
case BAND_76000_108000_kHz:
mUpperBoundInKHz = 108000;
mLowerBoundInKHz = 76000;
break;
case BAND_87500_108000_kHz:
default:
mUpperBoundInKHz = 108000;
mLowerBoundInKHz = 87500;
break;
}
Now I want to change "dom.fmradio.band" to "BAND_76000_108000_kHz" from within my App. Is there a WebAPI for manipulating shared preferences? If not, is there a way to edit prefs myself (I`m root on my device).

No, this is not possible from within an app. You can however edit it straight on your rooted device through:
adb shell stop b2g
adb pull /data/b2g/mozilla/*.default/prefs.js prefs.js
Open prefs.js in a text editor, and add the pref
Push it back: adb push prefs.js /data/b2g/mozilla/*.default/prefs.js
adb shell start b2g
Pref syntax will be something like:
user_pref("dom.fmradio.band", 3);

Related

Dart and Process.run

I have three issues with Process.run that I don't understand.
when I use ps aux in my Linux shell I get a nicely formatted list of processes, when I do it inside Visual Studio I get that as one huge string, I would like to create a data class, so I can map those values.
ie MEM CPU, so later I can do myobjec.CPU and I can see how much CPU the process uses with certain PID.
Second problem I would like to monitor this data so that it's updated every 0.5s. But with this technique of me fetching string, formatting string and then outputting that in UI, and doing that every 0.5 seconds sounds insane.
executing something like ps -U \$USER u in Process.run does not work since it outputs an actual string $USER instead of the name of the current user
so far I have two attempts
Future<List<List<String>>> processPlayground() async {
// This works on Windows/Linux/Mac
var shell = Shell(workingDirectory: "/");
List<List<String>> main = [];
List<Data> dataList = [];
Data? dt;
await shell.run('''
ps -U moonlight u
''').then((value) {
for (var element in value.outLines) {
main.add(element.replaceAll(_whitespaceRE, " ").split(" ").toList());
}
});
return main;
}
}
this works somewhat I have data class where I define, mem, CPU, user and so on and then I format this and present it in flutter UI, but it's very slow, and doing this every 0.5 is inefficient, UI lags.
I have also this :
test() async {
var process = await Process.start("ps", ["aux"]);
process.stdout.transform(utf8.decoder).forEach((element) {
sideList.add(element);
});
}
tz() {
print(sideList[0]);
mainList.add(sideList[0].replaceAll(_whitespaceRE, " ").split(" ").toList());
print(mainList[0]);
}
But here formatting somehow does not work, but here I also don't run these commands in a shell, don't know if that does make a difference.
TLDR
I need a way to get the list of processes, that gets updated every 0.5 seconds with current values, and I need later to have a way to put that in a table for further manipulation. In a similar way that Task Manager on Windows does, or System Monitor on Gnome does.
or should I use a different approach?

Having trouble finding my core-data file on my macbook

I'm running my app using Xcode 12.4 and I'm using persisting my data using Core Data.
When I try to fetch the data and print it inside of a list, it prints the data correctly, but I'm having trouble finding the actual DB file on my mac.
Normally I would run print("Documents Directory: ", FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).last ?? "Not Found!")and that would lead me to the correct file, but when I go to the destination now, the documents folder is empty.
Any ideas how I can retrieve the file?
If you're using NSPersistentContainer, try asking the container for the path it's using. You can do this any time after calling loadPersistentStores(completionHandler:):
print("Path to store file: \(container.persistentStoreCoordinator.persistentStores.first?.url?.path ?? "not found")")
Or you can put this in the completion closure you pass to loadPersistentStores(completionHandler:):
print("Loaded persistent store at \(storeDescription.url!.path)")
Keep in mind that the path will change every time you run the app, so be sure you have the current path. There are a couple of UUIDs in the path-- one of them doesn't change unless you delete the app, but the other changes all the time. For example once it might be this (wrapped here for readability)
/Users/[you]/Library/Developer/CoreSimulator/Devices/
445F0055-2A61-478A-9BA9-7F44CE038242/data/Containers/Data/Application/
4B21151B-4148-470B-88AC-F323CB88434D/Library/
Application Support/[AppName].sqlite
Then the next time it's this
/Users/[you]/Library/Developer/CoreSimulator/Devices/
445F0055-2A61-478A-9BA9-7F44CE038242/data/Containers/Data/Application/
E8889B57-41CB-4F14-AAB2-A02142DC47FF/Library/
Application Support/[AppName].sqlite
Which is kind of a pain, but you do need to check it every time.
I wrote the below to copy the location of core data database to the clipboard. If you are coding for IOS14 then you can comment out the appDelegate line and also swap the dbName line for the one commented.
func printCoreDataPath(){
let appDelegate = UIApplication.shared.delegate as! AppDelegate // remove if IOS14
let path = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.applicationSupportDirectory, FileManager.SearchPathDomainMask.userDomainMask, true)
let dbName = appDelegate.persistentContainer.name
// let dbName = PersistenceController.shared.container.name
let pasteboard = UIPasteboard.general
pasteboard.string = (path[0] + "/\(dbName).sqlite")
print (path[0] + "/\(dbName).sqlite")
}

JMonkeyEngine FullScreen Script

I'm pretty new to Java scripting I was wondering if any of you could tell me what's wrong with these lines:
GraphicsDevice device = GraphicsEnviroment.
getLocalGraphicEnviroment().getDefaultScreenDevice();
settings.setResolution(modes[0].getWidth(), modes][0].getHeight());
settings.setFrequency(mdoe{[0].getFrequencyRate());
settings.setDepthBits(modes[0].getBitDepth());
settings.setFullscreen(device.isFullScreenSupported());
I'm sure we could debate the meaning of the word 'script', but that is Java, not a Java script (and certainly not javascript)...
You have several problems with extra punctuation, missing variable declarations, and misspelled method names. The code you want can be found on the jME3 website:
public void toggleToFullscreen() {
GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
DisplayMode[] modes = device.getDisplayModes();
int i=0; // note: there are usually several, let's pick the first
settings.setResolution(modes[i].getWidth(),modes[i].getHeight());
settings.setFrequency(modes[i].getRefreshRate());
settings.setBitsPerPixel(modes[i].getBitDepth());
settings.setFullscreen(device.isFullScreenSupported());
app.setSettings(settings);
app.restart(); // restart the context to apply changes
}

Do these hotkeys exist for Flash Pro CS6?

1) when you are in edit mode for one symbol, go into edit for the next symbol in library
2) automatically put cursor in the instance name box for selected movieClip
As far as I know there are is no way to put shorcuts for moving around "inside of the library panel"
A duplicate and edit shortcut would sure be nice though. I can't even find where you would do it in custom shortcuts.
The examples you have listed do not have shortcut keys because they are not default tasks inside of the IDE. That being said you can create ways to do those examples using JSFL to first create a command and then assign a keyboard shortcut to that command. As an example I will include a script for the second item in your list.
2) automatically put cursor in the instance name box for selected
movieClip
There currently isn't a way to tell the IDE to send the cursor to the instance name box in the properties panel, but you can get around that by using JSFL. Let's make our own instance name box pop up.
Here is the code required to do this:
// Assign Instance Name - Andrew Doll
/* This code will provide a prompt for the user to assign an instance name to a selected symbol on the stage. The great thing about using a
// prompt is that the focus is already in the input field of the prompt. To speed up your workflow I recommend assigning a keyboard
// shortcut to this command.
*/
// Check to see if there is a file open first.
var dom = fl.getDocumentDOM();
if (dom == null)
{
alert("Please open a file.");
}
else
{
// Make sure to only select one symbol on the stage at a time.
if (dom.selection.length > 1)
{
alert("You can only select one symbol to assign an instance name to. Please make only a single selection on the stage.");
}
// Make sure that you have at least one symbol selected.
else if (dom.selection.length == 0)
{
alert("You need to select a symbol on the stage to assign an instance name.");
}
// Make sure that the symbol you have selected is a movie clip or a button.
else if (dom.selection[0].symbolType == "graphic" || dom.selection[0].elementType != "instance")
{
alert("Your selection needs to be a button or a movie clip symbol.");
}
else
{
// Pop up a prompt for the user to assign an instance name with.
var iName = prompt("Assign an instance name to the selected symbol.");
// If the user cancels then do nothing.
if (iName == null)
{
// Do Nothing.
}
else
{
// Assign the instance name to the selected symbol.
dom.selection[0].name = iName;
}
}
}
Save this command as a JSFL script in the commands folder in your Flash config directory and then assign a keyboard shortcut to it.

question on Implementing IQueryCancelAutoPlay in a windows service

I am implementing IQueryCancelAutoPlay COM interface and registering it with the Running Objects Table from a Windows Service*.
My problem is that it never gets called when I insert a mass storage device (or any device really). Here's some more information:
My code for registering with the ROT:
Text::string clsIdString = Text::to_string(Com::CLSID_QCAListener);
// remove curly braces
clsIdString = clsIdString.substr(1, clsIdString.length() - 2);
// set registry key to make sure we get notifications from windows
Reg::SetValue(HKEY_LOCAL_MACHINE,
_T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\AutoplayHandlers\\CancelAutoplay\\CLSID"),
clsIdString, _T(""));
HRESULT result = S_OK;
// create class moniker ...
CComPtr<IMoniker> moniker;
result = CreateClassMoniker(Com::CLSID_QCAListener, &moniker);
if( !ValidateResult(result, "Error creating class moniker") )
return;
DBG << _T("Getting IRunningObjectTable pointer ...") << std::endl;
// get running oject table ...
CComPtr<IRunningObjectTable> runningObjectTable;
result = GetRunningObjectTable(0, &runningObjectTable);
if( !ValidateResult(result, "Error getting running object table") )
return;
// create an instance of the QCAListener class ...
Com::QCAListener * listenerInstance = new Com::QCAListener();
if(!ValidateResult( listenerInstance != 0,
"Error creating QueryCancelAutoplayListener"))
return;
// ... and set the pointer in the _qcaListener variable
CComPtr<IQueryCancelAutoPlay> qcaListener;
listenerInstance->QueryInterface(IID_IQueryCancelAutoPlay, reinterpret_cast<void**>(&qcaListener));
DBG << _T("Registering IQueryCancelAutoPlay with ROT ...") << std::endl;
result = runningObjectTable->Register(
ROTFLAGS_REGISTRATIONKEEPSALIVE,
listenerInstance,
moniker,
&_qcaRegistration);
ValidateResult(result, "Error registering QueryCancelAutoplayListener with the ROT");
runningObjectTable->Register returns S_OK, and at the end of the code block's execution the ref-count for listenerInstance is 1 (if I remove the call to runningObjectTable->Register completely, the ref-count remains 0 when qcaListener goes out of scope so this means an instance of my class remains active in the ROT).
More details: In development, my service runs with my account credentials (local administrator). Although this will probably change, it should work as it is with the current configuration.
Can anyone shed any light on this?
*- I know the documentation says I shouldn't implement IQueryCancelAutoPlay in a service but I need to do this for various reasons (business requirement, etc).
I figured it out (for those who stumble upon this answer when having a similar problem):
The service runs under a different window station and a different desktop. When the IQueryCalcelAutoPlay implementation is registered in the ROT this is done for a different desktop.
The current user's desktop shell (explorer) will not find this registration when a new USB device is inserted (as it is not registered with the current desktop).

Resources