How can I lock the window size of a .NET MAUI app? - .net-maui

I need a solution for locking the window size of a .NET MAUI app. I don't want to allow users to change the app's height and width.(For Windows app)

This can be achieved by using WinUIEx package for the Windows.
Step 1:Install WinUIEx NuGet package.
Step 2:Update Maui.Program.cs to set your initial window size and position.
using Microsoft.Maui.LifecycleEvents;
#if WINDOWS
using WinUIEx;
#endif
namespace MauiApp01;
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});
#if WINDOWS
builder.ConfigureLifecycleEvents(events =>
{
events.AddWindows(wndLifeCycleBuilder =>
{
wndLifeCycleBuilder.OnWindowCreated(window =>
{
//Set size and center on screen using WinUIEx extension method
window.CenterOnScreen(1920,1080);
});
});
});
#endif
return builder.Build();
}
}
Reference link.

Related

Phaser 3 ScaleManager exception

I am trying to enable fullscreen in my game written in Phaser 3.
I am doing it from Scene class via
this.game.scale.startFullScreen();
but getting error in f12 browser console
Uncaught TypeError: this.game.scale.startFullScreen is not a function
at TitleScene.<anonymous> (TitleScene.js:23)
at InputPlugin.emit (phaser.js:2025)
at InputPlugin.processDownEvents (phaser.js:167273)
...
In docs ScaleManager class has startFullScreen method.
Why console tells me it doesn't?
This is the full code of TitleScene.js:
export class TitleScene extends Phaser.Scene {
constructor ()
{
const config =
{
key: 'TitleScene'
}
super(config);
}
preload ()
{
this.load.image('Title', 'assets/Title.png');
}
create ()
{
this.background = this.add.image(960, 540, 'Title');
this.input.manager.enabled = true;
this.input.once('pointerdown', function () {
this.scene.start('MainScene');
this.game.scale.startFullScreen(); // here is the error
}, this);
}
}
There are two problems prevented me from resolving this problem:
I followed examples from here
https://www.phaser.io/examples/v2
But I am using the third version Phaser. And everyone who uses the same must follow examples from here
https://www.phaser.io/examples/v3
You must pay attention to url while using their site with examples. Both pages are the same from the first look. But urls are different. Also there are warning after each example using the second (old) version of engine.
And finally this function name is not startFullScreen but startFullscreen :)

Is there a way to control the nuxt cache when deploying?

When using Nuxt, I ask questions.
When I distributed the site I built, the cache problem caused it to malfunction.
There are two cases below. Is there any way to solve them?
If built, the file names of js and css will be renamed to hash values, but it was not reflected by viewing old cache in browser.
Create applications using vue-native webview The webview in the application looked up the old cache. To apply the changed js, css, how do I remove the cache from the past?
https://github.com/nuxt/nuxt.js/issues/4764#issuecomment-713469389
Implementation of this one:
Add a plugin filename route.client.js
Include in nuxt.config.json
function getClientAppVersion() {
return localStorage.getItem('APP_VERSION') ?? 0
}
function setClientAppVersion(version) {
return localStorage.setItem('APP_VERSION', version)
}
export default ({ app }) => {
app.router.afterEach((to, from) => {
fetch("/version.json").then((serverPromise) =>
serverPromise.json().then((response) => {
const latestVersion = response.version
const clientStoredVersion = getClientAppVersion()
if (clientStoredVersion != latestVersion) {
window.location.reload(true)
setClientAppVersion(latestVersion)
}
else return
}))
})}
Add version.jon file
{
"version": "9.1"
}

How to launch another Android app using cocos2d-x?

I'm making a game with cocos2d-x for Android using C++. Now I'm looking for a way to open another Android App (likes YouTube, Google Play Store, ...) using their package name from inside my game through a button . I have searched around and found that it could be done in Java code with something like this:
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.package.address");
if (launchIntent != null) {
startActivity(launchIntent);//null pointer check in case package name was not found
}
My question is: Is it possible to open another Android App in my native code (.cpp files) or I have to put them in java side (.java files)? If I have to do it in .java files, where should I put it? I always work with .cpp files in Visual Studio, compile with cmd and run with emulator on Android Studio, I have never worked with .java files that generated by cocos2d-x in Android Studio, the engine just makes everything ready for me so I got a little confused here.
Update 1:
Abhishek Aryan's advice works but my Game crashed on resume when I'm in another App. I'm trying to performs some actions before opening others app and they might cause the crash because I could run it without any problem if I remove those action and leave openApp function alone.
My expect: Press the button => pause my game and open You Tube on Android => Press Back Button => pause You Tube and resume my game.
What happens: I could open You Tube but my App crashed when I press back button. I got the following error code from Android Studio:
A/libc: Fatal signal 11 (SIGSEGV) at 0x0004fb18 (code=1), thread 1975 (Thread-55)
Any idea how could I fix it?
My code :
auto imageOpeningAction = CallFunc::create([&]() {
mOpeningImage->setEnabled(true);
mOpeningImage->setOpacity(255);
mOpeningImage->setPosition(menuItem->getPosition());
mOpeningImage->runAction(fullScale);
});
auto imageClosingAction = CallFunc::create([&]() {
mOpeningImage->runAction(reverseScale);
mOpeningImage->setOpacity(0);
mOpeningImage->setEnabled(false);
});
auto openAnotherApp = CallFunc::create([&]() { // Open YouTube app
HelloWorld::openApp(packageName);
});
runAction(Sequence::create(imageOpeningAction->clone(), DelayTime::create(0.5f), openAnotherApp->clone(), nullptr));
Your attention and help is very much appreciated.
You need to use JNI for your requirement.
Create a method that open any app in your AppActivity.
public class AppActivity extends Cocos2dxActivity {
private static Activity activity;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
activity=this;
}
public static void openOtherApp(String packageName){
Intent launchIntent = activity.getPackageManager().getLaunchIntentForPackage(packageName);
if (launchIntent != null) {
activity.startActivity(launchIntent);
}
}
}
Done !
Not yet, now only I need to call openOtherApp method from c++ so I create a method in my .cpp file.
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
#include "platform/android/jni/JniHelper.h"
#endif
void openApp(std::string packageName){
#if(CC_TARGET_PLATFORM==CC_PLATFORM_ANDROID)
JniMethodInfo methodInfo;
const char* class_name="org/cocos2dx/cpp/AppActivity";
const char* method_name="openOtherApp";
const char* parameter= "(Ljava/lang/String;)V";
if (! cocos2d::JniHelper::getStaticMethodInfo(methodInfo, class_name, method_name ,parameter )) {
return;
}
jstring jStringParam = methodInfo.env->NewStringUTF(packageName.c_str());
methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID,jStringParam);
methodInfo.env->DeleteLocalRef(methodInfo.classID);
#endif
}
Want to open facebook call openApp(com.facebook.katana);

Using cef for win64 - How to enable fullscreen

I'm using CEF and have built the cefsimple.exe. I can include any html file to the simple_app.cpp which will start after the doubleclick. But how is it possible to start this cefsimple.exe in fullscreen mode? Which build do I need? I work with VS2013 on a win64 system.
SimpleApp::SimpleApp() {
}
void SimpleApp::OnContextInitialized() {
CEF_REQUIRE_UI_THREAD();
// Information used when creating the native window.
CefWindowInfo window_info;
#if defined(OS_WIN)
// On Windows we need to specify certain flags that will be passed to
// CreateWindowEx().
window_info.SetAsPopup(NULL, "cefsimple");
// my first try: *************************************
/* RECT winrect;
winrect.bottom = 0;
winrect.left = 0;
winrect.right = 0;
winrect.top = 0;
window_info.SetAsChild(NULL, winrect);*/
#endif
// SimpleHandler implements browser-level callbacks.
CefRefPtr<SimpleHandler> handler(new SimpleHandler());
// Specify CEF browser settings here.
CefBrowserSettings browser_settings;
std::string url;
// Check if a "--url=" value was provided via the command-line. If so, use
// that instead of the default URL.
CefRefPtr<CefCommandLine> command_line =
CefCommandLine::GetGlobalCommandLine();
url = command_line->GetSwitchValue("url");
if (url.empty())
url = "file:///C:/Projekte/BOF-WENDT-HTML5/Fullscreen.html";
// Create the first browser window.
CefBrowserHost::CreateBrowser(window_info, handler.get(), url,
browser_settings, NULL);
}
Not yet implemented in CEF, see:
https://code.google.com/p/chromiumembedded/issues/detail?id=562
Update: Changes for this feature have landed https://bitbucket.org/chromiumembedded/cef/issue/562

Playing wav/mp3 from Windows 7 service

I need to play a sound file (wav or mp3 is fine) from a service in Windows 7/2008... the way we did it in WinXP doesn't work anymore. I've followed this question Play wave file from a Windows Service (C#) with no success, in various combinations. The sound plays fine through the debugger but once I install it as a service it doesn't play, and event logs prove the call is being made. I've also followed the http://bresleveloper.blogspot.co.il/2012/06/c-service-play-sound-with-naudio.html link with the same result.
Code snippet follows below. It is a C# service with VS 2010, .Net 4.0, NAudio 1.5.4.0. I am using
InstallUtil to install/remove the service.
WRT the code, I comment out the Wav or MP3 stuff and one of the methods each time... they all play the sound sucessfully.
static class Program
{
[DllImport("kernel32.dll")]
public static extern Boolean AllocConsole();
static void Main(string[] args)
{
m_eventLog = new EventLog();
m_eventLog.Source = "EventLoggerSource";
if(args.Length > 0 && args[0].ToLower() == "/console")
{
AllocConsole();
EventLoggerApp app = new EventLoggerApp();
app.Start();
m_eventLog.WriteEntry("INFO (Calling Player)");
string fileFullPath=#"c:\aaasound\bunny_troubles.wav",fileFullPath2=#"c:\aaasound\dreams.mp3";
// Wav file
IWavePlayer wavePlayer=new WaveOutEvent(); // Method 1
IWavePlayer wavePlayer=new WasapiOut(NAudio.CoreAudioApi.AudioClientShareMode.Shared,false,100); // Method 2
AudioFileReader audioFile=new AudioFileReader(fileFullPath);
audioFile.Volume = (float)1.0;
wavePlayer.Init(audioFile);
// MP3 file
IWavePlayer wavePlayer=new WasapiOut(NAudio.CoreAudioApi.AudioClientShareMode.Shared,true,100); // Method 1- EventSync/not both work
IWavePlayer wavePlayer=new WasapiOut(NAudio.CoreAudioApi.AudioClientShareMode.Exclusive,false,100); // Method 2- EventSync must be false or throws an exception
WaveStream mp3Reader = new Mp3FileReader(fileFullPath2);
WaveChannel32 inputStream=new WaveChannel32(mp3Reader);
WaveStream wavStream=new WaveChannel32(inputStream);
wavePlayer.Init(wavStream);
//this.wavePlayer.PlaybackStopped += new EventHandler(wavePlayer_PlaybackStopped);
wavePlayer.Play();
while(wavePlayer.PlaybackState == PlaybackState.Playing)
{
Thread.Sleep(100);
}

Resources