Skip to content

Commit

Permalink
Windows support (#666)
Browse files Browse the repository at this point in the history
* use the flutter.ps1 windows script

* several windows fixes

* create a common constant
  • Loading branch information
devoncarew authored Jan 27, 2017
1 parent 1e89559 commit ef489a3
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 24 deletions.
7 changes: 7 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Line endings: enforce LF in GitHub, convert to native on checkout.
* text=auto
*.dart text
*.java text
*.md text
*.sh text
*.yaml text
2 changes: 2 additions & 0 deletions src/io/flutter/FlutterConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class FlutterConstants {

public static final String FLUTTER_SETTINGS_PAGE_ID = "flutter.settings";

public static final String INDEPENDENT_PATH_SEPARATOR = "/";

private FlutterConstants() {

}
Expand Down
33 changes: 17 additions & 16 deletions src/io/flutter/actions/DeviceSelectorAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ private void updateActions(Presentation presentation, @NotNull Project project)
actions.add(new NoDevicesAction());
}

// Show the 'Open iOS Simulator' action.
if (SystemInfo.isMac) {
boolean simulatorOpen = false;
for (AnAction action : actions) {
Expand All @@ -140,26 +141,26 @@ private void updateActions(Presentation presentation, @NotNull Project project)

actions.add(new Separator());
actions.add(new OpenSimulatorAction(!simulatorOpen));
}

FlutterUtils.invokeAndWait(() -> {
final FlutterDevice selectedDevice = service.getSelectedDevice();
for (AnAction action : actions) {
if (action instanceof SelectDeviceAction) {
final SelectDeviceAction deviceAction = (SelectDeviceAction)action;

FlutterUtils.invokeAndWait(() -> {
final FlutterDevice selectedDevice = service.getSelectedDevice();
for (AnAction action : actions) {
if (action instanceof SelectDeviceAction) {
final SelectDeviceAction deviceAction = (SelectDeviceAction)action;

if (Objects.equals(deviceAction.device, selectedDevice)) {
final Presentation template = action.getTemplatePresentation();
presentation.setIcon(template.getIcon());
presentation.setText(template.getText());
presentation.setEnabled(true);
return;
}
if (Objects.equals(deviceAction.device, selectedDevice)) {
final Presentation template = action.getTemplatePresentation();
presentation.setIcon(template.getIcon());
presentation.setText(template.getText());
presentation.setEnabled(true);
return;
}
}
}

presentation.setText(null);
});
}
presentation.setText(null);
});
}

private static class NoDevicesAction extends AnAction implements TransparentUpdate {
Expand Down
12 changes: 7 additions & 5 deletions src/io/flutter/console/FlutterConsoleFolding.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@

import com.intellij.execution.ConsoleFolding;
import com.intellij.openapi.util.text.StringUtil;
import io.flutter.FlutterConstants;
import io.flutter.sdk.FlutterSdkUtil;
import org.jetbrains.annotations.Nullable;

import java.io.File;
import java.util.List;
import java.util.regex.Pattern;

Expand All @@ -18,7 +19,8 @@
* '/Users/.../projects/flutter/flutter/bin/flutter --no-color packages get'.
*/
public class FlutterConsoleFolding extends ConsoleFolding {
private static final String marker = File.separator + "flutter --no-color ";
private static final String flutterMarker =
FlutterConstants.INDEPENDENT_PATH_SEPARATOR + FlutterSdkUtil.flutterScriptName() + " --no-color ";

private boolean isFolding = false;

Expand All @@ -39,7 +41,7 @@ public class FlutterConsoleFolding extends ConsoleFolding {

@Override
public boolean shouldFoldLine(String line) {
if (line.contains(marker)) {
if (line.contains(flutterMarker)) {
isFolding = false;
return true;
}
Expand Down Expand Up @@ -67,7 +69,7 @@ public boolean shouldFoldLine(String line) {
@Override
public String getPlaceholderText(List<String> lines) {
final String fullText = StringUtil.join(lines, "\n");
final int index = fullText.indexOf(marker);
final int index = fullText.indexOf(flutterMarker);
if (index == -1) {
final String trimmed = fullText.trim();

Expand All @@ -82,7 +84,7 @@ else if (lines.stream().anyMatch((s) -> s.endsWith("}"))) {
}
}
else {
return "flutter " + fullText.substring(index + marker.length());
return "flutter " + fullText.substring(index + flutterMarker.length());
}
}
}
8 changes: 7 additions & 1 deletion src/io/flutter/run/FlutterAppState.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleUtil;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import io.flutter.FlutterConstants;
import io.flutter.actions.OpenObservatoryAction;
import io.flutter.actions.OpenSimulatorAction;
import io.flutter.console.FlutterConsoleFilter;
Expand Down Expand Up @@ -100,11 +102,15 @@ protected ProcessHandler startProcess() throws ExecutionException {
String relativePath = parameters.getFilePath();
if (relativePath != null && relativePath.startsWith(cwd)) {
relativePath = relativePath.substring(cwd.length());
if (relativePath.startsWith(File.separator)) {
if (relativePath.startsWith(FlutterConstants.INDEPENDENT_PATH_SEPARATOR)) {
relativePath = relativePath.substring(1);
}
}

if (relativePath != null) {
relativePath = FileUtil.toSystemDependentName(relativePath);
}

if (device != null) {
// Bring simulator to front.
if (device.emulator() && Objects.equals(device.platform(), "ios")) {
Expand Down
4 changes: 4 additions & 0 deletions src/io/flutter/sdk/FlutterSdk.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.CharsetToolkit;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.ui.content.MessageView;
Expand All @@ -39,6 +40,7 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -123,6 +125,7 @@ public void run(@NotNull Command cmd,
final String flutterPath = FlutterSdkUtil.pathToFlutterTool(getHomePath());
final String dirPath = workingDir == null ? null : workingDir.getPath();
final GeneralCommandLine command = new GeneralCommandLine().withWorkDirectory(dirPath);
command.setCharset(CharsetToolkit.UTF8_CHARSET);
command.setExePath(flutterPath);
// Example: [create, foo_bar]
String[] toolArgs = ArrayUtil.mergeArrays(cmd.command, args);
Expand Down Expand Up @@ -170,6 +173,7 @@ public void runProject(@NotNull Project project,
throws ExecutionException {
final String flutterPath = FlutterSdkUtil.pathToFlutterTool(getHomePath());
final GeneralCommandLine command = new GeneralCommandLine();
command.setCharset(CharsetToolkit.UTF8_CHARSET);
command.setExePath(flutterPath);
// Example: [create, foo_bar]
final String[] toolArgs = ArrayUtil.prepend("--no-color", args);
Expand Down
9 changes: 7 additions & 2 deletions src/io/flutter/sdk/FlutterSdkUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
Expand Down Expand Up @@ -84,8 +85,12 @@ public static void addKnownSDKPathsToCombo(@NotNull JComboBox combo) {

@NotNull
public static String pathToFlutterTool(@NotNull String sdkPath) throws ExecutionException {
// TODO: Use flutter.bat on Windows.
return sdkRelativePathTo(sdkPath, "bin", "flutter");
return sdkRelativePathTo(sdkPath, "bin", flutterScriptName());
}

@NotNull
public static String flutterScriptName() {
return SystemInfo.isWindows ? "flutter.bat" : "flutter";
}

@NotNull
Expand Down

0 comments on commit ef489a3

Please sign in to comment.