desktop: platform socket fix, file extension association for windows
This commit is contained in:
parent
fb7312cb80
commit
dd45f7ce38
3 changed files with 77 additions and 69 deletions
|
@ -114,13 +114,15 @@ impl<Platform: PlatformCallbacks> App<Platform> {
|
||||||
|
|
||||||
// Provide incoming data to wallets.
|
// Provide incoming data to wallets.
|
||||||
if let Some(data) = self.platform.consume_data() {
|
if let Some(data) = self.platform.consume_data() {
|
||||||
|
if !data.is_empty() {
|
||||||
self.content.wallets.on_data(ui, Some(data), &self.platform);
|
self.content.wallets.on_data(ui, Some(data), &self.platform);
|
||||||
|
}
|
||||||
self.attention_required = true;
|
self.attention_required = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Check if desktop window was focused after requested attention.
|
// Check if desktop window was focused after requested attention.
|
||||||
if View::is_desktop() && self.attention_required
|
if self.attention_required && View::is_desktop()
|
||||||
&& ctx.input(|i| i.viewport().focused.unwrap_or(true)) {
|
&& ctx.input(|i| i.viewport().focused.unwrap_or(true)) {
|
||||||
self.attention_required = false;
|
self.attention_required = false;
|
||||||
ctx.send_viewport_cmd(
|
ctx.send_viewport_cmd(
|
||||||
|
|
124
src/main.rs
124
src/main.rs
|
@ -42,7 +42,7 @@ fn real_main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if another app instance already running.
|
// Check if another app instance already running.
|
||||||
if is_app_running(data.clone()) {
|
if is_app_running(&data) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ fn real_main() {
|
||||||
// Save backtrace to file.
|
// Save backtrace to file.
|
||||||
let log = grim::Settings::crash_report_path();
|
let log = grim::Settings::crash_report_path();
|
||||||
if log.exists() {
|
if log.exists() {
|
||||||
std::fs::remove_file(log.clone()).unwrap();
|
let _ = std::fs::remove_file(log.clone());
|
||||||
}
|
}
|
||||||
std::fs::write(log, err.as_bytes()).unwrap();
|
std::fs::write(log, err.as_bytes()).unwrap();
|
||||||
// Setup flag to show crash after app restart.
|
// Setup flag to show crash after app restart.
|
||||||
|
@ -74,48 +74,7 @@ fn real_main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if application is already running to pass extra data.
|
/// Start GUI with Desktop related setup passing data from opening.
|
||||||
#[allow(dead_code)]
|
|
||||||
#[cfg(not(target_os = "android"))]
|
|
||||||
fn is_app_running(data: Option<String>) -> bool {
|
|
||||||
use tor_rtcompat::BlockOn;
|
|
||||||
let runtime = tor_rtcompat::tokio::TokioNativeTlsRuntime::create().unwrap();
|
|
||||||
let res: Result<(), Box<dyn std::error::Error>> = runtime
|
|
||||||
.block_on(async {
|
|
||||||
use interprocess::local_socket::{
|
|
||||||
tokio::{prelude::*, Stream},
|
|
||||||
GenericFilePath
|
|
||||||
};
|
|
||||||
use tokio::{
|
|
||||||
io::{AsyncBufReadExt, AsyncWriteExt, BufReader},
|
|
||||||
try_join,
|
|
||||||
};
|
|
||||||
|
|
||||||
let socket_path = grim::Settings::socket_path();
|
|
||||||
let name = socket_path.to_fs_name::<GenericFilePath>()?;
|
|
||||||
// Connect to running application socket.
|
|
||||||
let conn = Stream::connect(name).await?;
|
|
||||||
|
|
||||||
let (rec, mut sen) = conn.split();
|
|
||||||
let mut rec = BufReader::new(rec);
|
|
||||||
let data = data.unwrap_or("".to_string());
|
|
||||||
let mut buffer = String::with_capacity(data.len());
|
|
||||||
|
|
||||||
// Send extra data to socket.
|
|
||||||
let send = sen.write_all(data.as_bytes());
|
|
||||||
let recv = rec.read_line(&mut buffer);
|
|
||||||
try_join!(send, recv)?;
|
|
||||||
|
|
||||||
drop((rec, sen));
|
|
||||||
Ok(())
|
|
||||||
});
|
|
||||||
return match res {
|
|
||||||
Ok(_) => true,
|
|
||||||
Err(_) => false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Start GUI with Desktop related setup passing extra data from opening.
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[cfg(not(target_os = "android"))]
|
#[cfg(not(target_os = "android"))]
|
||||||
fn start_desktop_gui(data: Option<String>) {
|
fn start_desktop_gui(data: Option<String>) {
|
||||||
|
@ -199,7 +158,46 @@ fn start_desktop_gui(data: Option<String>) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Start socket that handles data for single application instance.
|
/// Check if application is already running to pass data.
|
||||||
|
#[allow(dead_code)]
|
||||||
|
#[cfg(not(target_os = "android"))]
|
||||||
|
fn is_app_running(data: &Option<String>) -> bool {
|
||||||
|
use tor_rtcompat::BlockOn;
|
||||||
|
let runtime = tor_rtcompat::tokio::TokioNativeTlsRuntime::create().unwrap();
|
||||||
|
let res: Result<(), Box<dyn std::error::Error>> = runtime
|
||||||
|
.block_on(async {
|
||||||
|
use interprocess::local_socket::{
|
||||||
|
tokio::{prelude::*, Stream},
|
||||||
|
GenericFilePath, GenericNamespaced
|
||||||
|
};
|
||||||
|
use tokio::{
|
||||||
|
io::AsyncWriteExt,
|
||||||
|
};
|
||||||
|
|
||||||
|
let socket_path = grim::Settings::socket_path();
|
||||||
|
let name = if GenericNamespaced::is_supported() {
|
||||||
|
"grim.sock".to_ns_name::<GenericNamespaced>()?
|
||||||
|
} else {
|
||||||
|
socket_path.clone().to_fs_name::<GenericFilePath>()?
|
||||||
|
};
|
||||||
|
// Connect to running application socket.
|
||||||
|
let conn = Stream::connect(name).await?;
|
||||||
|
let (rec, mut sen) = conn.split();
|
||||||
|
|
||||||
|
// Send data to socket.
|
||||||
|
let data = data.clone().unwrap_or("".to_string());
|
||||||
|
let _ = sen.write_all(data.as_bytes()).await;
|
||||||
|
|
||||||
|
drop((rec, sen));
|
||||||
|
Ok(())
|
||||||
|
});
|
||||||
|
return match res {
|
||||||
|
Ok(_) => true,
|
||||||
|
Err(_) => false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Start desktop socket that handles data for single application instance.
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[cfg(not(target_os = "android"))]
|
#[cfg(not(target_os = "android"))]
|
||||||
fn start_app_socket(platform: grim::gui::platform::Desktop) {
|
fn start_app_socket(platform: grim::gui::platform::Desktop) {
|
||||||
|
@ -209,36 +207,35 @@ fn start_app_socket(platform: grim::gui::platform::Desktop) {
|
||||||
.block_on(async {
|
.block_on(async {
|
||||||
use interprocess::local_socket::{
|
use interprocess::local_socket::{
|
||||||
tokio::{prelude::*, Stream},
|
tokio::{prelude::*, Stream},
|
||||||
GenericFilePath, Listener, ListenerOptions,
|
GenericFilePath, GenericNamespaced, Listener, ListenerOptions,
|
||||||
};
|
};
|
||||||
use std::io;
|
use std::io;
|
||||||
use tokio::{
|
use tokio::{
|
||||||
io::{AsyncBufReadExt, AsyncWriteExt, BufReader},
|
io::{AsyncBufReadExt, BufReader},
|
||||||
try_join,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle incoming connection.
|
// Handle incoming connection.
|
||||||
async fn handle_conn(conn: Stream)
|
async fn handle_conn(conn: Stream)
|
||||||
-> io::Result<String> {
|
-> io::Result<String> {
|
||||||
let mut rec = BufReader::new(&conn);
|
let mut read = BufReader::new(&conn);
|
||||||
let mut sen = &conn;
|
|
||||||
|
|
||||||
let mut buffer = String::new();
|
let mut buffer = String::new();
|
||||||
let send = sen.write_all(b"");
|
// Read data.
|
||||||
let recv = rec.read_line(&mut buffer);
|
let _ = read.read_line(&mut buffer).await;
|
||||||
|
|
||||||
// Read data and send answer.
|
|
||||||
try_join!(recv, send)?;
|
|
||||||
|
|
||||||
Ok(buffer)
|
Ok(buffer)
|
||||||
}
|
}
|
||||||
|
|
||||||
let socket_path = grim::Settings::socket_path();
|
let socket_path = grim::Settings::socket_path();
|
||||||
std::fs::remove_file(socket_path.clone()).unwrap();
|
let name = if GenericNamespaced::is_supported() {
|
||||||
let name = socket_path.to_fs_name::<GenericFilePath>()?;
|
"grim.sock".to_ns_name::<GenericNamespaced>()?
|
||||||
let opts = ListenerOptions::new().name(name);
|
} else {
|
||||||
|
socket_path.clone().to_fs_name::<GenericFilePath>()?
|
||||||
|
};
|
||||||
|
if socket_path.exists() {
|
||||||
|
let _ = std::fs::remove_file(socket_path);
|
||||||
|
}
|
||||||
|
|
||||||
// Create socket listener.
|
// Create listener.
|
||||||
|
let opts = ListenerOptions::new().name(name);
|
||||||
let listener = match opts.create_tokio() {
|
let listener = match opts.create_tokio() {
|
||||||
Err(e) if e.kind() == io::ErrorKind::AddrInUse => {
|
Err(e) if e.kind() == io::ErrorKind::AddrInUse => {
|
||||||
eprintln!("Socket file is occupied.");
|
eprintln!("Socket file is occupied.");
|
||||||
|
@ -251,7 +248,10 @@ fn start_app_socket(platform: grim::gui::platform::Desktop) {
|
||||||
loop {
|
loop {
|
||||||
let conn = match listener.accept().await {
|
let conn = match listener.accept().await {
|
||||||
Ok(c) => c,
|
Ok(c) => c,
|
||||||
Err(_) => continue
|
Err(e) => {
|
||||||
|
println!("{:?}", e);
|
||||||
|
continue
|
||||||
|
}
|
||||||
};
|
};
|
||||||
let res = handle_conn(conn).await;
|
let res = handle_conn(conn).await;
|
||||||
match res {
|
match res {
|
||||||
|
|
14
wix/main.wxs
14
wix/main.wxs
|
@ -16,8 +16,8 @@
|
||||||
AllowSameVersionUpgrades = "yes"
|
AllowSameVersionUpgrades = "yes"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Icon Id='ProductICO' SourceFile='wix\Product.ico'/>
|
<Icon Id='Product.ico' SourceFile='wix\Product.ico'/>
|
||||||
<Property Id='ARPPRODUCTICON' Value='ProductICO' />
|
<Property Id='ARPPRODUCTICON' Value='Product.ico' />
|
||||||
|
|
||||||
<Directory Id="TARGETDIR" Name="SourceDir">
|
<Directory Id="TARGETDIR" Name="SourceDir">
|
||||||
<Directory Id='$(var.PlatformProgramFilesFolder)'>
|
<Directory Id='$(var.PlatformProgramFilesFolder)'>
|
||||||
|
@ -28,7 +28,7 @@
|
||||||
<Component Id="ApplicationShortcutDesktop" Guid="14efa019-7ed7-4765-8263-fa5460f92495">
|
<Component Id="ApplicationShortcutDesktop" Guid="14efa019-7ed7-4765-8263-fa5460f92495">
|
||||||
<Shortcut Id="ApplicationDesktopShortcut"
|
<Shortcut Id="ApplicationDesktopShortcut"
|
||||||
Name="Grim"
|
Name="Grim"
|
||||||
Icon="ProductICO"
|
Icon="Product.ico"
|
||||||
Description="GUI for Grin"
|
Description="GUI for Grin"
|
||||||
Target="[APPLICATIONROOTDIRECTORY]grim.exe"
|
Target="[APPLICATIONROOTDIRECTORY]grim.exe"
|
||||||
WorkingDirectory="APPLICATIONROOTDIRECTORY"/>
|
WorkingDirectory="APPLICATIONROOTDIRECTORY"/>
|
||||||
|
@ -55,6 +55,12 @@
|
||||||
</Component>
|
</Component>
|
||||||
<Component Id="grim.exe" Guid="95444223-45BF-427A-85CA-61B035044305">
|
<Component Id="grim.exe" Guid="95444223-45BF-427A-85CA-61B035044305">
|
||||||
<File Id="grim.exe" Source="$(var.CargoTargetBinDir)\grim.exe" KeyPath="yes" Checksum="yes"/>
|
<File Id="grim.exe" Source="$(var.CargoTargetBinDir)\grim.exe" KeyPath="yes" Checksum="yes"/>
|
||||||
|
<File Id="slatepack.ico" Source="wix\Product.ico" />
|
||||||
|
<ProgId Id='grim.slatepack' Description='Grin Slatepack message' Icon='slatepack.ico'>
|
||||||
|
<Extension Id='slatepack' ContentType='text/plain'>
|
||||||
|
<Verb Id='open' Command='Open' Target='[APPLICATIONROOTDIRECTORY]grim.exe' Argument='%1' />
|
||||||
|
</Extension>
|
||||||
|
</ProgId>
|
||||||
</Component>
|
</Component>
|
||||||
</DirectoryRef>
|
</DirectoryRef>
|
||||||
|
|
||||||
|
@ -64,7 +70,7 @@
|
||||||
<Shortcut Id="ApplicationStartMenuShortcut"
|
<Shortcut Id="ApplicationStartMenuShortcut"
|
||||||
Name="Grim"
|
Name="Grim"
|
||||||
Description="Cross-platform GUI for Grin with focus on usability and availability to be used by anyone, anywhere."
|
Description="Cross-platform GUI for Grin with focus on usability and availability to be used by anyone, anywhere."
|
||||||
Icon="ProductICO"
|
Icon="Product.ico"
|
||||||
Target="[#grim.exe]"
|
Target="[#grim.exe]"
|
||||||
WorkingDirectory="APPLICATIONROOTDIRECTORY"/>
|
WorkingDirectory="APPLICATIONROOTDIRECTORY"/>
|
||||||
<RemoveFolder Id="ApplicationProgramsFolder" On="uninstall"/>
|
<RemoveFolder Id="ApplicationProgramsFolder" On="uninstall"/>
|
||||||
|
|
Loading…
Reference in a new issue