Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #222

Merged
merged 20 commits into from
Sep 25, 2024
Merged

Dev #222

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions .github/workflows/build-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ jobs:
run: echo "prerelease=true" >> $GITHUB_ENV

- name: Setup Flutter
uses: subosito/[email protected]
# Specify the Flutter version to work around bug in new version:
# https://github.com/flutter/flutter/issues/144873
with:
flutter-version: '3.19.6'
uses: subosito/flutter-action@v2

- name: Checkout code
uses: actions/checkout@v3
Expand Down
6 changes: 1 addition & 5 deletions .github/workflows/build-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ jobs:
run: echo "prerelease=true" >> $GITHUB_ENV

- name: Setup Flutter
uses: subosito/[email protected]
# Specify the Flutter version to work around bug in new version:
# https://github.com/flutter/flutter/issues/144873
with:
flutter-version: '3.19.6'
uses: subosito/flutter-action@v2

- name: Checkout code
uses: actions/checkout@v3
Expand Down
8 changes: 2 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ jobs:
os: [ubuntu-latest, windows-latest]
steps:
- uses: actions/checkout@v3
- uses: subosito/[email protected]
# Specify the Flutter version to work around bug in new version:
# https://github.com/flutter/flutter/issues/144873
with:
flutter-version: '3.19.6'
- uses: subosito/flutter-action@v2

- name: Get Linux dependencies
if: runner.os == 'Linux'
Expand All @@ -33,7 +29,7 @@ jobs:
flutter pub get

- name: Verify formatting
run: dart format -o none --set-exit-if-changed .
run: dart format -o none --set-exit-if-changed --line-length=90 .

- name: Run code generation
run: flutter pub run build_runner build --delete-conflicting-outputs
Expand Down
10 changes: 8 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,11 @@
"git.ignoredRepositories": [
"packaging/linux/flatpak/shared-modules"
],
"git.detectSubmodules": false
}
"git.detectSubmodules": false,
"dart.lineLength": 90,
"[dart]": {
"editor.rulers": [
90
]
}
}
Binary file modified assets/icons/codes.merritt.Nyrna.ico
Binary file not shown.
Binary file modified assets/icons/codes.merritt.Nyrna.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 7 additions & 12 deletions assets/icons/codes.merritt.Nyrna.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
159 changes: 159 additions & 0 deletions assets/icons/src/codes.merritt.Nyrna.Source.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/screenshots/linux/screenshot1-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/screenshots/linux/screenshot1-light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
89 changes: 51 additions & 38 deletions lib/active_window/src/active_window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,28 @@ import '../../argument_parser/argument_parser.dart';
import '../../logs/logs.dart';
import '../../native_platform/native_platform.dart';
import '../../storage/storage_repository.dart';
import '../../window/app_window.dart';

/// Manage the active window.
///
/// We use extra logging here in order to debug issues since this has
/// no user interface.
class ActiveWindow {
final AppWindow _appWindow;
final NativePlatform _nativePlatform;
final ProcessRepository _processRepository;
final StorageRepository _storageRepository;

const ActiveWindow(
this._appWindow,
this._nativePlatform,
this._processRepository,
this._storageRepository,
);

/// Maximum number of retries to suspend the active window.
static const int _maxRetries = 3;

/// Toggle suspend / resume for the active, foreground window.
Future<bool> toggle() async {
log.i('Toggling active window.');
Expand Down Expand Up @@ -79,53 +85,60 @@ class ActiveWindow {
Future<bool> _suspend() async {
log.i('Suspending');

final window = await _nativePlatform.activeWindow();
for (int attempt = 0; attempt < _maxRetries; attempt++) {
final window = await _nativePlatform.activeWindow();
final String executable = window.process.executable;

final String executable = window.process.executable;
if (executable == 'nyrna' || executable == 'nyrna.exe') {
log.w('Active window is Nyrna, not suspending.');
return false;
}
if (executable == 'nyrna' || executable == 'nyrna.exe') {
log.w('Active window is Nyrna, hiding and retrying.');
await _appWindow.hide();
await Future.delayed(const Duration(milliseconds: 500));
continue;
}

log.i('Active window: $window');
log.i('Active window: $window');

if (defaultTargetPlatform == TargetPlatform.windows) {
// Once in a blue moon on Windows we get "explorer.exe" as the active
// window, even when no file explorer windows are open / the desktop
// is not the active element, etc. So we filter it just in case.
if (window.process.executable == 'explorer.exe') {
log.e('Only got explorer as active window!');
return false;
if (defaultTargetPlatform == TargetPlatform.windows) {
// Once in a blue moon on Windows we get "explorer.exe" as the active
// window, even when no file explorer windows are open / the desktop
// is not the active element, etc. So we filter it just in case.
if (window.process.executable == 'explorer.exe') {
log.e('Only got explorer as active window!');
return false;
}
}
}

await _minimize(window.id);
await _minimize(window.id);

// Small delay on Windows to ensure the window actually minimizes.
// Doesn't seem to be necessary on Linux.
if (defaultTargetPlatform == TargetPlatform.windows) {
await Future.delayed(const Duration(milliseconds: 500));
}
// Small delay on Windows to ensure the window actually minimizes.
// Doesn't seem to be necessary on Linux.
if (defaultTargetPlatform == TargetPlatform.windows) {
await Future.delayed(const Duration(milliseconds: 500));
}

final suspended = await _processRepository.suspend(window.process.pid);
if (!suspended) {
log.e('Failed to suspend active window.');
return false;
}
final suspended = await _processRepository.suspend(window.process.pid);
if (!suspended) {
log.e('Failed to suspend active window.');
return false;
}

await _storageRepository.saveValue(
key: 'pid',
value: window.process.pid,
storageArea: 'activeWindow',
);
await _storageRepository.saveValue(
key: 'windowId',
value: window.id,
storageArea: 'activeWindow',
);
log.i('Suspended ${window.process.pid} successfully');
await _storageRepository.saveValue(
key: 'pid',
value: window.process.pid,
storageArea: 'activeWindow',
);
await _storageRepository.saveValue(
key: 'windowId',
value: window.id,
storageArea: 'activeWindow',
);
log.i('Suspended ${window.process.pid} successfully');

return true;
}

return true;
log.e('Failed to suspend after $_maxRetries attempts.');
return false;
}

Future<void> _minimize(int windowId) async {
Expand Down
9 changes: 7 additions & 2 deletions lib/app/cubit/app_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ If you need Nyrna to work with a specific app, you can try running it with XWayl
env XDG_SESSION_TYPE=x11 <app>
```

or

```
env QT_QPA_PLATFORM=xcb <app>
```

Otherwise, [consider signing in using X11 instead](https://docs.fedoraproject.org/en-US/quick-docs/configuring-xorg-as-default-gnome-session/).''';

switch (sessionType) {
Expand All @@ -120,8 +126,7 @@ Otherwise, [consider signing in using X11 instead](https://docs.fedoraproject.or
runningVersion: versionInfo.currentVersion,
updateVersion: versionInfo.latestVersion,
updateAvailable: versionInfo.updateAvailable,
showUpdateButton:
(defaultTargetPlatform.isDesktop && versionInfo.updateAvailable),
showUpdateButton: (defaultTargetPlatform.isDesktop && versionInfo.updateAvailable),
));
}

Expand Down
Loading
Loading