From 0d2a2d2b20e128b6de3ca65b7140a26badeb23ba Mon Sep 17 00:00:00 2001 From: David Kocik Date: Mon, 9 Dec 2019 15:33:10 +0100 Subject: [PATCH] osx device unmount callback - not sure if will build --- src/slic3r/CMakeLists.txt | 1 + src/slic3r/GUI/RemovableDriveManager.cpp | 11 ++--- src/slic3r/GUI/RemovableDriveManager.hpp | 4 +- src/slic3r/GUI/RemovableDriveManager.mm | 51 ++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 src/slic3r/GUI/RemovableDriveManager.mm diff --git a/src/slic3r/CMakeLists.txt b/src/slic3r/CMakeLists.txt index 03413f9337..6a14a1b3f3 100644 --- a/src/slic3r/CMakeLists.txt +++ b/src/slic3r/CMakeLists.txt @@ -169,6 +169,7 @@ if (APPLE) list(APPEND SLIC3R_GUI_SOURCES Utils/RetinaHelperImpl.mm Utils/MacDarkMode.mm + GUI/RemovableDriveManager.mm ) endif () diff --git a/src/slic3r/GUI/RemovableDriveManager.cpp b/src/slic3r/GUI/RemovableDriveManager.cpp index 5daa9eb261..166728e68b 100644 --- a/src/slic3r/GUI/RemovableDriveManager.cpp +++ b/src/slic3r/GUI/RemovableDriveManager.cpp @@ -203,7 +203,7 @@ INT_PTR WINAPI WinProcCallback(HWND hWnd, UINT message, WPARAM wParam, LPARAM lP if(wParam == DBT_DEVICEREMOVECOMPLETE) { std::cout << "WM_DEVICECHANGE\n"; - RemovableDriveManager::get_instance().on_drive_removed_callback(); + RemovableDriveManager::get_instance().update(); } } break; @@ -219,6 +219,10 @@ INT_PTR WINAPI WinProcCallback(HWND hWnd, UINT message, WPARAM wParam, LPARAM lP void RemovableDriveManager::search_for_drives() { +#if __APPLE__ + list_devices(); +#endif + m_current_drives.clear(); m_current_drives.reserve(26); @@ -483,10 +487,7 @@ void RemovableDriveManager::reset_last_save_path() { m_last_save_path = ""; } -void RemovableDriveManager::on_drive_removed_callback() -{ - update(); -} + void RemovableDriveManager::print() { //std::cout << "Removed Device: "<<(int)is_last_drive_removed()<<"\n"; diff --git a/src/slic3r/GUI/RemovableDriveManager.hpp b/src/slic3r/GUI/RemovableDriveManager.hpp index 210d89477b..501c16b71a 100644 --- a/src/slic3r/GUI/RemovableDriveManager.hpp +++ b/src/slic3r/GUI/RemovableDriveManager.hpp @@ -37,7 +37,6 @@ public: bool is_last_drive_removed(); //if we dont need info about this drive, call reset_last_save_path(); bool is_last_drive_removed_with_update(const long time = 0); // param as update() void reset_last_save_path(); - void on_drive_removed_callback(); void print(); private: RemovableDriveManager():m_drives_count(0),m_last_update(0),m_last_save_path(""){} @@ -52,6 +51,9 @@ private: #if _WIN32 void register_window(); //INT_PTR WINAPI WinProcCallback(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); +#elif __APPLE__ + void register_window(); + void list_devices(); #else void search_path(const std::string &path, const std::string &parent_path); bool compare_filesystem_id(const std::string &path_a, const std::string &path_b); diff --git a/src/slic3r/GUI/RemovableDriveManager.mm b/src/slic3r/GUI/RemovableDriveManager.mm new file mode 100644 index 0000000000..a1358625fc --- /dev/null +++ b/src/slic3r/GUI/RemovableDriveManager.mm @@ -0,0 +1,51 @@ +#import "RemovableDriveManager.hpp" + +@implementation RemovableDriveManager + +namespace Slic3r { +namespace GUI { + +void RemovableDriveManager::register_window() +{ + //[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector: @selector(volumesChanged:) name:NSWorkspaceDidMountNotification object: nil]; + [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector: @selector(on_device_unmount:) name:NSWorkspaceDidUnmountNotification object:nil]; +} + +-(void) on_device_unmount: (NSNotification*) notification +{ + NSLog(@"on device change"); + RemovableDriveManager::get_instance().update(); +} + +-(void) RemovableDriveManager::list_devices() +{ + NSLog(@"---"); + NSArray* devices = [[NSWorkspace sharedWorkspace] mountedRemovableMedia]; + for (NSString* volumePath in listOfMedia) + { + NSLog(@"@", volumePath); + } + NSLog(@"--"); + //removable here means CD not USB :/ + NSArray* listOfMedia = [[NSWorkspace sharedWorkspace] mountedLocalVolumePaths]; + NSLog(@"%@", listOfMedia); + + for (NSString* volumePath in listOfMedia) + { + BOOL isRemovable = NO; + BOOL isWritable = NO; + BOOL isUnmountable = NO; + NSString* description = [NSString string]; + NSString* type = [NSString string]; + + BOOL result = [[NSWorkspace sharedWorkspace] getFileSystemInfoForPath:volumePath + isRemovable:&isRemovable + isWritable:&isWritable + isUnmountable:&isUnmountable + description:&description + type:&type]; + NSLog(@"Result:%i Volume: %@, Removable:%i, W:%i, Unmountable:%i, Desc:%@, type:%@", result, volumePath, isRemovable, isWritable, isUnmountable, description, type); + } +} + +}}//namespace Slicer::GUI \ No newline at end of file