|
| 1 | +// |
| 2 | +// Aster Communications Inc. |
| 3 | +// |
| 4 | +// Copyright (c) 2026 Aster Communications Inc. |
| 5 | +// |
| 6 | +// This file is part of this project. |
| 7 | +// |
| 8 | +// This program is free software: you can redistribute it and/or modify |
| 9 | +// it under the terms of the GNU Affero General Public License as published by |
| 10 | +// the Free Software Foundation, either version 3 of the License, or |
| 11 | +// (at your option) any later version. |
| 12 | +// |
| 13 | +// This program is distributed in the hope that it will be useful, |
| 14 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | +// GNU Affero General Public License for more details. |
| 17 | +// |
| 18 | +// You should have received a copy of the GNU Affero General Public License |
| 19 | +// along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 20 | +// |
| 21 | +use objc2::{AnyThread, MainThreadMarker}; |
| 22 | +use objc2_app_kit::{NSApplication, NSImage}; |
| 23 | +use objc2_foundation::NSData; |
| 24 | +use tauri::Theme; |
| 25 | + |
| 26 | +const LIGHT_ICON: &[u8] = include_bytes!("../icons/icon_macos.png"); |
| 27 | +const DARK_ICON: &[u8] = include_bytes!("../icons/icon_macos_dark.png"); |
| 28 | + |
| 29 | +pub fn apply(theme: Theme) { |
| 30 | + let Some(main_thread) = MainThreadMarker::new() else { |
| 31 | + return; |
| 32 | + }; |
| 33 | + let bytes = match theme { |
| 34 | + Theme::Dark => DARK_ICON, |
| 35 | + _ => LIGHT_ICON, |
| 36 | + }; |
| 37 | + let data = NSData::with_bytes(bytes); |
| 38 | + let Some(image) = NSImage::initWithData(NSImage::alloc(), &data) else { |
| 39 | + return; |
| 40 | + }; |
| 41 | + unsafe { |
| 42 | + NSApplication::sharedApplication(main_thread).setApplicationIconImage(Some(&image)); |
| 43 | + } |
| 44 | +} |
0 commit comments