dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.31k stars 1.59k forks source link

.dart files are treated as disk images (security sensitive) on Macs #28205

Open eseidelGoogle opened 7 years ago

eseidelGoogle commented 7 years ago

This is not Dart's "fault" per say, but it isn't going to help us reach less-terminal-friendly Mac developers and may be something we need to call out in our getting started docs, or work around in some way?

Dart files show up like this in the finder:

screen shot 2016-12-27 at 12 11 40 pm

If you try and double click ones you've downloaded, you will get this:

screen shot 2016-12-27 at 12 14 39 pm

Even if you use "Open With...":

screen shot 2016-12-27 at 12 13 19 pm

And configure the default handler:

screen shot 2016-12-27 at 12 13 44 pm

You will still get that security dialog for downloaded .dart files. I don't currently know of a workaround.

matanlurey commented 7 years ago

/sub

sethladd commented 7 years ago

What should happen when I double click the file?

eseidelGoogle commented 7 years ago

Ideally we would instruct users how to bind .dart files how to open in their favorite editor (without warnings). Try downloading a .txt file from the internet and double clicking it, e.g.: option-click on "Raw" (to download) in https://github.com/flutter/flutter/blob/master/README.md and then double click it (it will open in XCode by default w/o any security warnings). Now try a .dart file to see the above. :)

Well, it's possible to bind certain extensions to certain apps on Mac: https://developer.apple.com/library/content/documentation/Carbon/Conceptual/LaunchServicesConcepts/LSCConcepts/LSCConcepts.html#//apple_ref/doc/uid/TP30000999-CH202-BABEJFCD

Apps can sign up to support certain types with their Info.plist files: https://developer.apple.com/library/content/documentation/FileManagement/Conceptual/DocumentInteraction_TopicsForIOS/Articles/RegisteringtheFileTypesYourAppSupports.html

I guess none of the apps on my system are signed up for .dart (but I expect that to be common). .dart also seems to have some special security treatment (at least by default? not sure if that's changeable), given that it can be a disk image and thus contain executable code.

mit-mit commented 7 years ago

I think the issue here is that .dart / com.apple.disk-image-dart is a registered MacOS file format: https://support.apple.com/kb/TA29157?locale=en_US&viewlocale=en_US

anders-sandholm commented 7 years ago

Added documentation label for now. We should at least talk about this - even if there is no work-around given the overlap with MacOS' DART (Disk Archive/Retrieval Tool).

kwalrath commented 7 years ago

I guess I could talk about this in the Mac installation page, which is the only Mac-specific page I can think of. But a real fix or good workaround would be better, of course.

gspencergoog commented 7 years ago

Maybe we can write a small app that registers for the .dart extension and simply visually enumerates the text editor and "Other..." apps on the system to ask which executable .dart should be associated with, and then registers that app to handle it going forward. Then we can just suggest that people install it to solve this problem (and we can install it with the Dart SDK on OSX).

[IANAAD (I Am Not An Apple Developer), so it's possible there are security blockades to that approach too, of course.]

cseder commented 6 years ago

Would be nice to find a simple solution to this.

What I did to work around this was first choosing to open all .dart files with Sublime Text, by cmd + i on a .dart file and choose Open With... Select Sublime Text and click "Change all".

I then created a DART.icns file to use for .dart files in Finder and added it into the Sublime Text app bundle Resources folder (/Applications/Sublime Text.app/Contents/Resources).

resources.png

and edited the /Applications/Sublime Text.app/Contents/Info.plist to contain an entry for Dart files:

info-plist.png

The applications listed in the Launch Services database on MacOS uses the info from the Info.plist for each application in /Applications, so after choosing Sublime Text as the default application for all .dart files and adding the .icns file and the appropriate entry in Info.plist and rebuilding the Launch Services database, Finder handles the files the way I want, showing the icon I added to the Sublime resources and promptly opens the file in Sublime Text upon double-clicking it.

Rebuilding the LaunchService database can be done by running a command in a Terminal:

/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -r -domain local -domain system -domain user

After a reboot, it looks all good:

finder.png

Opening in Sublime Text shows the icon from resources in the application bar as well! :)

sublime.png

This is definitely a cumbersome workaround, but it can probably be customized for any code editor using the same steps...

osaxma commented 5 years ago

Another way to fix it (without dart icon):

To enable the QuickLook, I installed a QuickLook Plugin called qlstephen: brew cask install qlstephen then restart QuickLook qlmanage -r

eseidelGoogle commented 5 years ago

It seems silly that we still have this bug in 2019.

Is it possible to at least add .dart as a known type to VSCode or IntelliJ (via the Flutter or Dart plugins) so these show up correctly when a user has those installed? @DanTup @devoncarew @mit-mit @csells

DanTup commented 5 years ago

@eseidelGoogle I'm not sure, I've opened https://github.com/Microsoft/vscode/issues/69551 asking. VS Code supports associating itself with files during install, and also can give them icons. It's not clear if it's reserved for things shipped with out-of-the-box support though.

leapit commented 5 years ago

trouble with this too

DanTup commented 5 years ago

VS Code doesn't want to do this at install time because Dart isn't a built-in language, so if we wanted to do something, it'd have to be done ourselves. I'm not sure how complicated that'd be (we'd need to do it for each OS).

eseidelGoogle commented 5 years ago

I linked to some docs back in https://github.com/dart-lang/sdk/issues/28205#issuecomment-269379526. Last I was aware, file extensions couldn't be added separately from app install, but maybe that's changed?

DanTup commented 5 years ago

Last I was aware, file extensions couldn't be added separately from app install, but maybe that's changed?

I ran this:

defaults write com.apple.LaunchServices LSHandlers -array-add \
"<dict><key>LSHandlerContentTag</key>
<string>dart</string><key>LSHandlerContentTagClass</key>
<string>public.filename-extension</string><key>LSHandlerRoleAll</key>
<string>com.microsoft.vscode</string></dict>"

And rebooted, and now my .dart files open with VS Code. However, they still have the original icon. I'm not sure how to fix that.. I did some searching, but the internet suggests that this may have to be done in the app (the app that will be opened supplies the icon?) in which case, we may be stuck.

Panway commented 4 years ago

I found a solution that can preview dart files on MacOS: https://medium.com/@claudmarotta/how-to-preview-dart-files-with-macos-quick-look-54779340811f