Skip to content

Commit

Permalink
fullscreen workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
ErBWs committed Dec 3, 2024
1 parent 5a73eb2 commit 43dc948
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 16 deletions.
28 changes: 12 additions & 16 deletions lib/utils/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -423,30 +423,26 @@ class Utils {
}

static Future<void> enterWindowsFullscreen() async {
if (Platform.isWindows) {
const platform = MethodChannel('com.predidit.kazumi/intent');
try {
await platform.invokeMethod('enterFullscreen');
} on PlatformException catch (e) {
print("Failed to enter native window mode: '${e.message}'.");
}
const platform = MethodChannel('com.predidit.kazumi/intent');
try {
await platform.invokeMethod('enterFullscreen');
} on PlatformException catch (e) {
print("Failed to enter native window mode: '${e.message}'.");
}
}

static Future<void> exitWindowsFullscreen() async {
if (Platform.isWindows) {
const platform = MethodChannel('com.predidit.kazumi/intent');
try {
await platform.invokeMethod('exitFullscreen');
} on PlatformException catch (e) {
print("Failed to exit native window mode: '${e.message}'.");
}
const platform = MethodChannel('com.predidit.kazumi/intent');
try {
await platform.invokeMethod('exitFullscreen');
} on PlatformException catch (e) {
print("Failed to exit native window mode: '${e.message}'.");
}
}

// 进入全屏显示
static Future<void> enterFullScreen({bool lockOrientation = true}) async {
if (Platform.isWindows) {
if (Platform.isWindows || Platform.isOhos) {
await enterWindowsFullscreen();
return;
}
Expand All @@ -471,7 +467,7 @@ class Utils {

//退出全屏显示
static Future<void> exitFullScreen({bool lockOrientation = true}) async {
if (Platform.isWindows) {
if (Platform.isWindows || Platform.isOhos) {
await exitWindowsFullscreen();
}
if (Platform.isLinux || Platform.isMacOS) {
Expand Down
24 changes: 24 additions & 0 deletions ohos/entry/src/main/ets/entryability/MethodCall.ets
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { FlutterPlugin, FlutterPluginBinding, MethodCall, MethodChannel, MethodR
import { common, Want } from "@kit.AbilityKit";
import { BusinessError } from "@kit.BasicServicesKit";
import uri from "@ohos.uri";
import { window } from "@kit.ArkUI";

export default class MethodCallPlugin implements FlutterPlugin {
private channel?: MethodChannel;
Expand All @@ -17,6 +18,14 @@ export default class MethodCallPlugin implements FlutterPlugin {
this.openWithMime(url, mimeType);
result.success("");
break;
case "enterFullscreen":
this.enterFullScreen();
result.success("");
break;
case "exitFullscreen":
this.exitFullScreen();
result.success("");
break;
default:
result.notImplemented();
break;
Expand All @@ -39,6 +48,21 @@ export default class MethodCallPlugin implements FlutterPlugin {
});
}

private enterFullScreen(): void {
let context = getContext(this) as common.UIAbilityContext;
window.getLastWindow(context).then((lastWindow)=> {
lastWindow.setPreferredOrientation(window.Orientation.LANDSCAPE);
lastWindow.setWindowSystemBarEnable([]);
})
}

private exitFullScreen(): void {
let context = getContext(this) as common.UIAbilityContext;
window.getLastWindow(context).then((lastWindow)=> {
lastWindow.setPreferredOrientation(window.Orientation.PORTRAIT);
})
}

getUniqueClassName(): string {
return "MethodCallPlugin"
}
Expand Down

0 comments on commit 43dc948

Please sign in to comment.