mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-01-10 17:08:29 +08:00
desktop: Add "Open .livebookdesktop.sh|bat" menu item (#2225)
This commit is contained in:
parent
d0b6af357b
commit
a82345d22e
4 changed files with 69 additions and 5 deletions
|
@ -17,9 +17,11 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||
private var launchedByOpenURL = false
|
||||
private var initialURLs: [URL] = []
|
||||
private var url: String?
|
||||
private var bootScriptURL: URL!
|
||||
|
||||
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
||||
logPath = "\(NSHomeDirectory())/Library/Logs/Livebook.log"
|
||||
bootScriptURL = NSURL.fileURL(withPath: "\(NSHomeDirectory())/.livebookdesktop.sh")
|
||||
|
||||
ElixirKit.API.start(
|
||||
name: "app",
|
||||
|
@ -72,6 +74,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||
NSMenuItem(title: "Open", action: #selector(open), keyEquivalent: "o"),
|
||||
copyURLItem,
|
||||
NSMenuItem(title: "View Logs", action: #selector(viewLogs), keyEquivalent: "l"),
|
||||
NSMenuItem(title: "Open .livebookdesktop.sh", action: #selector(openBootScript), keyEquivalent: ""),
|
||||
NSMenuItem(title: "Settings", action: #selector(openSettings), keyEquivalent: ","),
|
||||
NSMenuItem(title: "Quit", action: #selector(NSApplication.terminate(_:)), keyEquivalent: "q")
|
||||
]
|
||||
|
@ -129,4 +132,28 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||
func openSettings() {
|
||||
ElixirKit.API.publish("open", "/settings")
|
||||
}
|
||||
|
||||
@objc
|
||||
func openBootScript() {
|
||||
let fm = FileManager.default
|
||||
|
||||
if !fm.fileExists(atPath: bootScriptURL.path) {
|
||||
let data = """
|
||||
# This file is used to configure Livebook before booting.
|
||||
# If you change this file, you must restart Livebook for your changes to take place.
|
||||
# See https://hexdocs.pm/livebook/readme.html#environment-variables for all available environment variables.
|
||||
|
||||
# # Allow Livebook to connect to remote machines over IPv6
|
||||
# export LIVEBOOK_DISTRIBUTION=name
|
||||
# export ERL_AFLAGS="-proto_dist inet6_tcp"
|
||||
|
||||
# # Add Homebrew to PATH
|
||||
# export PATH=/opt/homebrew/bin:$PATH
|
||||
""".data(using: .utf8)
|
||||
|
||||
fm.createFile(atPath: bootScriptURL.path, contents: data)
|
||||
}
|
||||
|
||||
NSWorkspace.shared.open(bootScriptURL)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
|
@ -72,6 +73,7 @@ class LivebookApp : ApplicationContext
|
|||
copyURLButton.Enabled = false;
|
||||
|
||||
menu.Items.Add("View Logs", null, viewLogsClicked);
|
||||
menu.Items.Add("Open .livebookdesktop.bat", null, openBootScriptClicked);
|
||||
menu.Items.Add("Settings", null, openSettingsClicked);
|
||||
menu.Items.Add("Quit", null, quitClicked);
|
||||
notifyIcon = new NotifyIcon()
|
||||
|
@ -139,7 +141,34 @@ class LivebookApp : ApplicationContext
|
|||
|
||||
private void viewLogsClicked(object? sender, EventArgs e)
|
||||
{
|
||||
System.Diagnostics.Process.Start(logPath);
|
||||
Process.Start(logPath);
|
||||
}
|
||||
|
||||
private void openBootScriptClicked(object? sender, EventArgs e)
|
||||
{
|
||||
var path =
|
||||
Path.Combine(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
|
||||
".livebookdesktop.bat"
|
||||
);
|
||||
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
File.WriteAllText(path, @"@echo off
|
||||
rem This file is used to configure Livebook before booting.
|
||||
rem If you change this file, you must restart Livebook for your changes to take place.
|
||||
rem See https://hexdocs.pm/livebook/readme.html#environment-variables for all available enviornment variables.
|
||||
|
||||
rem Allow Livebook to connect to remote machines over IPv6
|
||||
rem set LIVEBOOK_DISTRIBUTION=name
|
||||
rem set ERL_AFLAGS="-proto_dist inet6_tcp"
|
||||
|
||||
rem Add directory to PATH
|
||||
rem set PATH=C:\bin;%PATH%
|
||||
");
|
||||
}
|
||||
|
||||
Process.Start("notepad.exe", path);
|
||||
}
|
||||
|
||||
private void openSettingsClicked(object? sender, EventArgs e)
|
||||
|
|
|
@ -4,5 +4,9 @@ set -euo pipefail
|
|||
. `dirname $0`/env.sh
|
||||
|
||||
rm -rf $target_dir
|
||||
dotnet build $build_args
|
||||
(cd ../../.. && mix release app --overwrite --path=${target_dir}/rel)
|
||||
dotnet build Livebook.csproj $build_args
|
||||
|
||||
(
|
||||
cd ../../..
|
||||
mix release app --overwrite --path=${target_dir}/rel
|
||||
)
|
||||
|
|
|
@ -4,8 +4,12 @@ set -euo pipefail
|
|||
. `dirname $0`/env.sh
|
||||
|
||||
rm -rf $target_dir
|
||||
dotnet publish $build_args
|
||||
(cd ../../.. && mix release app --overwrite --path=${target_dir}/rel)
|
||||
dotnet publish Livebook.csproj $build_args
|
||||
|
||||
(
|
||||
cd ../../..
|
||||
mix release app --overwrite --path=${target_dir}/rel
|
||||
)
|
||||
|
||||
vc_redist_path="bin/vc_redist.x64.exe"
|
||||
if [ ! -f $vc_redist_path ]; then
|
||||
|
|
Loading…
Reference in a new issue