osx device unmount callback - not sure if will build

This commit is contained in:
David Kocik 2019-12-09 15:33:10 +01:00
parent 87fff4626e
commit 0d2a2d2b20
4 changed files with 61 additions and 6 deletions

View file

@ -169,6 +169,7 @@ if (APPLE)
list(APPEND SLIC3R_GUI_SOURCES
Utils/RetinaHelperImpl.mm
Utils/MacDarkMode.mm
GUI/RemovableDriveManager.mm
)
endif ()

View file

@ -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";

View file

@ -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);

View file

@ -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