Skip to content

Commit

Permalink
use icon name for tray
Browse files Browse the repository at this point in the history
  • Loading branch information
Merrit committed Mar 23, 2024
1 parent 2a35930 commit e6deebc
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 8 deletions.
50 changes: 47 additions & 3 deletions lib/src/system_tray/system_tray.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:helpers/helpers.dart';
import 'package:tray_manager/tray_manager.dart';
Expand Down Expand Up @@ -33,10 +35,52 @@ class SystemTray {

/// Shows the system tray icon.
Future<void> show() async {
final String iconPath = (defaultTargetPlatform.isWindows) //
? AppIcons.windows
: AppIcons.linux;
// final String iconPath = (defaultTargetPlatform.isWindows) //
// ? AppIcons.windows
// : AppIcons.linux;

// final String iconRelativePath = (defaultTargetPlatform.isWindows) //
// ? AppIcons.windows
// : AppIcons.linux;

// const String iconRelativePath = 'icons/codes.merritt.FeelingFinder.png';

// final String iconAbsolutePath = getAssetAbsolutePath(iconRelativePath);

// await trayManager.setIcon(iconAbsolutePath);

// await trayManager.setIcon('codes.merritt.FeelingFinder');

final flatpakId = Platform.environment['FLATPAK_ID'];

final String iconPath;
if (flatpakId != null) {
iconPath = 'codes.merritt.FeelingFinder';
} else {
iconPath = (defaultTargetPlatform.isWindows) //
? AppIcons.windows
: AppIcons.linux;
}

await trayManager.setIcon(iconPath);
}
}

/// Returns the absolute path to an asset.
///
/// The [relativePath] argument must be a relative path to the asset.
///
/// Example:
///
/// ```dart
/// final String iconPath = getAssetAbsolutePath('icons/linux.png');
/// ```
String getAssetAbsolutePath(String relativePath) {
final currentDirectory = Directory.current.absolute.path;

// If in release mode the path will look like: data\flutter_assets\assets\
// Otherwise it looks like: assets\
const String assetsPath = kReleaseMode ? 'data/flutter_assets/assets' : 'assets';

return '$currentDirectory/$assetsPath/$relativePath';
}
9 changes: 5 additions & 4 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1063,10 +1063,11 @@ packages:
tray_manager:
dependency: "direct main"
description:
name: tray_manager
sha256: "4ab709d70a4374af172f8c39e018db33a4271265549c6fc9d269a65e5f4b0225"
url: "https://pub.dev"
source: hosted
path: "."
ref: "1c16c734e271c07cbb17776e62537d0e5ff5b826"
resolved-ref: "1c16c734e271c07cbb17776e62537d0e5ff5b826"
url: "https://github.com/Merrit/tray_manager.git"
source: git
version: "0.2.1"
tutorial_coach_mark:
dependency: "direct main"
Expand Down
6 changes: 5 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ dependencies:
pub_semver: ^2.1.4
slang: ^3.22.0
slang_flutter: ^3.22.0
tray_manager: ^0.2.0
# tray_manager: ^0.2.0
tray_manager:
git:
url: https://github.com/Merrit/tray_manager.git
ref: 1c16c734e271c07cbb17776e62537d0e5ff5b826
tutorial_coach_mark: ^1.2.8
unicode_emojis: ^0.4.0
url_launcher: ^6.1.11
Expand Down

0 comments on commit e6deebc

Please sign in to comment.