Skip to content

Commit

Permalink
Merge pull request #1593 from atsign-foundation/regular-window-macos
Browse files Browse the repository at this point in the history
chore: Regular window macos
  • Loading branch information
CurtlyCritchlow authored Dec 5, 2024
2 parents 790d7ff + d943d65 commit 476d10e
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ class _OnboardingButtonState extends State<OnboardingButton> {
bool shouldOnboard = await selectAtsign();
if (shouldOnboard && context.mounted) {
var atsignInformation = context.read<OnboardingCubit>().state;
onboard(atsign: atsignInformation.atSign, rootDomain: atsignInformation.rootDomain);
onboard(
atsign: atsignInformation.atSign,
rootDomain: atsignInformation.rootDomain);
}
},
icon: PhosphorIcon(PhosphorIcons.arrowUpRight()),
Expand All @@ -73,8 +75,10 @@ class _OnboardingButtonState extends State<OnboardingButton> {
),
iconAlignment: IconAlignment.end,
),
_OnboardingButtonStatus.picking => Text(strings.onboardingButtonStatusPicking),
_OnboardingButtonStatus.processingFile => Text(strings.onboardingButtonStatusProcessingFile),
_OnboardingButtonStatus.picking =>
Text(strings.onboardingButtonStatusPicking),
_OnboardingButtonStatus.processingFile =>
Text(strings.onboardingButtonStatusProcessingFile),
};
}

Expand Down Expand Up @@ -105,8 +109,12 @@ class _OnboardingButtonState extends State<OnboardingButton> {
return results ?? false;
}

Future<void> onboard({required String atsign, required String rootDomain, bool isFromInitState = false}) async {
var atSigns = await KeyChainManager.getInstance().getAtSignListFromKeychain();
Future<void> onboard(
{required String atsign,
required String rootDomain,
bool isFromInitState = false}) async {
var atSigns =
await KeyChainManager.getInstance().getAtSignListFromKeychain();
var apiKey = await Constants.appAPIKey;
var config = AtOnboardingConfig(
atClientPreference: await loadAtClientPreference(rootDomain),
Expand Down Expand Up @@ -155,7 +163,8 @@ class _OnboardingButtonState extends State<OnboardingButton> {
SnackBar(
backgroundColor: Colors.red,
content: Text(
onboardingResult?.message ?? AppLocalizations.of(context)!.onboardingError,
onboardingResult?.message ??
AppLocalizations.of(context)!.onboardingError,
),
),
);
Expand All @@ -165,7 +174,8 @@ class _OnboardingButtonState extends State<OnboardingButton> {
}
}

Future<AtOnboardingResult?> handleAtsignByStatus(String atsign, NoPortsOnboardingUtil util) async {
Future<AtOnboardingResult?> handleAtsignByStatus(
String atsign, NoPortsOnboardingUtil util) async {
AtStatus status;

try {
Expand All @@ -180,6 +190,7 @@ class _OnboardingButtonState extends State<OnboardingButton> {

switch (status.status()) {
// Automatically start activation with the already entered atSign
case AtSignStatus.unavailable:
case AtSignStatus.teapot:
final apiKey = await Constants.appAPIKey;

Expand All @@ -190,9 +201,12 @@ class _OnboardingButtonState extends State<OnboardingButton> {
break;
}
AtOnboardingConstants.setApiKey(apiKey);
AtOnboardingConstants.rootDomain = util.config.atClientPreference.rootDomain;
AtOnboardingConstants.rootDomain =
util.config.atClientPreference.rootDomain;

await AtOnboardingLocalizations.load(LanguageUtil.getLanguageFromLocale(Locale(Platform.localeName)).locale);
await AtOnboardingLocalizations.load(
LanguageUtil.getLanguageFromLocale(Locale(Platform.localeName))
.locale);
if (!mounted) return null;
Map<String, String> apis = {
"root.atsign.org": "my.atsign.com",
Expand All @@ -218,15 +232,17 @@ class _OnboardingButtonState extends State<OnboardingButton> {

if (result is AtOnboardingResult) {
//Update primary atsign after onboard success
if (result.status == AtOnboardingResultStatus.success && result.atsign != null) {
if (result.status == AtOnboardingResultStatus.success &&
result.atsign != null) {
var onboardingService = OnboardingService.getInstance();
bool res = await onboardingService.changePrimaryAtsign(atsign: result.atsign!);
bool res = await onboardingService.changePrimaryAtsign(
atsign: result.atsign!);
if (!res) {
result = AtOnboardingResult.error(message: strings.errorSwitchAtSignFailed);
result = AtOnboardingResult.error(
message: strings.errorSwitchAtSignFailed);
}
}
}
// TODO: finalize onboarding
case AtSignStatus.activated:
// NOTE: for now this is hard coded to do atKey file upload
// Later on, we can add the APKAM flow, and will need to make some
Expand All @@ -237,10 +253,6 @@ class _OnboardingButtonState extends State<OnboardingButton> {
result = AtOnboardingResult.error(
message: strings.errorAtSignNotExist,
);
case AtSignStatus.unavailable:
result = AtOnboardingResult.error(
message: strings.errorAtServerUnavailable,
);
case null: // This case should never happen, treat it as an error
case AtSignStatus.error:
result = AtOnboardingResult.error(
Expand All @@ -250,7 +262,8 @@ class _OnboardingButtonState extends State<OnboardingButton> {
return result;
}

Future<AtOnboardingResult?> handleFileUploadStatusStream(Stream<FileUploadStatus> statusStream, String atsign) async {
Future<AtOnboardingResult?> handleFileUploadStatusStream(
Stream<FileUploadStatus> statusStream, String atsign) async {
AtOnboardingResult? result;
outer:
await for (FileUploadStatus status in statusStream) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import 'dart:io';

import 'package:flutter/scheduler.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:npt_flutter/app.dart';
import 'package:npt_flutter/features/favorite/favorite.dart';
import 'package:npt_flutter/features/onboarding/cubit/onboarding_cubit.dart';
import 'package:npt_flutter/features/profile/profile.dart';
import 'package:npt_flutter/features/profile_list/profile_list.dart';
import 'package:npt_flutter/features/settings/settings.dart';
Expand All @@ -23,7 +26,8 @@ class TrayManager extends StatefulWidget {
State<TrayManager> createState() => _TrayManagerState();
}

class _TrayManagerState extends State<TrayManager> with TrayListener, WindowListener {
class _TrayManagerState extends State<TrayManager>
with TrayListener, WindowListener {
/// Must strongly type [context] here or Dart will infer the wrong type for
/// the [.read()] extension which causes an error
void reloadTray(BuildContext context, Loggable state) async {
Expand All @@ -36,7 +40,8 @@ class _TrayManagerState extends State<TrayManager> with TrayListener, WindowList
case ProfilesRunningState _:
cubit.reload(profilesRunningState: state);
case SettingsLoadedState _:
var localizations = await AppLocalizations.delegate.load(state.settings.language.locale);
var localizations = await AppLocalizations.delegate
.load(state.settings.language.locale);
cubit.reload(localizations: localizations);
case ProfileState _:
cubit.reload(profileState: state);
Expand Down Expand Up @@ -78,12 +83,14 @@ class _TrayManagerState extends State<TrayManager> with TrayListener, WindowList
listener: reloadTray,
// Only call listener when the language changes in settings
listenWhen: (prev, next) {
if (prev is SettingsLoadedState && next is SettingsLoadedState) {
if (prev is SettingsLoadedState &&
next is SettingsLoadedState) {
return prev.settings.language != next.settings.language;
}
// This may cause some extra reloading (very occasionally, settings shouldn't change often)
// but it should catch all of the edge cases
return prev is SettingsLoadedState || next is SettingsLoadedState;
return prev is SettingsLoadedState ||
next is SettingsLoadedState;
}),

/// Yeah I really hate this... an indefinite list of listeners
Expand Down Expand Up @@ -114,6 +121,7 @@ class _TrayManagerState extends State<TrayManager> with TrayListener, WindowList
trayManager.addListener(this);
super.initState();
windowManager.setPreventClose(true);
windowManager.setVisibleOnAllWorkspaces(true);
var dispatcher = SchedulerBinding.instance.platformDispatcher;

// This callback is called every time the brightness changes.
Expand Down Expand Up @@ -143,6 +151,12 @@ class _TrayManagerState extends State<TrayManager> with TrayListener, WindowList

@override
void onWindowClose() async {
await windowManager.hide();
var onboardingCubit = App.navState.currentContext?.read<OnboardingCubit>();
if (onboardingCubit?.state.status == OnboardingStatus.onboarded) {
await windowManager.hide();
} else {
await windowManager.destroy();
exit(0);
}
}
}
7 changes: 5 additions & 2 deletions packages/dart/npt_flutter/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:npt_flutter/constants.dart';
import 'package:window_manager/window_manager.dart';
Expand All @@ -7,10 +9,11 @@ import 'app.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();

var windowOptions = const WindowOptions(
var windowOptions = WindowOptions(
title: "NoPorts Desktop",
minimumSize: Constants.kWindowsMinWindowSize,
skipTaskbar: true,
skipTaskbar: Platform.isWindows,
alwaysOnTop: true,
);
windowManager.ensureInitialized();
windowManager.waitUntilReadyToShow(windowOptions);
Expand Down

0 comments on commit 476d10e

Please sign in to comment.