Skip to content

Commit

Permalink
Fixed macOS Remote File Protocol (#310)
Browse files Browse the repository at this point in the history
  • Loading branch information
mariotaku authored Feb 13, 2025
1 parent 4c14892 commit f86ea77
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 7 deletions.
49 changes: 49 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"@tauri-apps/plugin-dialog": "2.2.0",
"@tauri-apps/plugin-fs": "2.2.0",
"@tauri-apps/plugin-log": "2.2.1",
"@tauri-apps/plugin-os": "2.2.0",
"@tauri-apps/plugin-shell": "2.2.0",
"@tauri-apps/plugin-upload": "2.2.1",
"@xterm/addon-fit": "0.10.0",
Expand Down
3 changes: 2 additions & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ tauri-plugin-shell = "2.2.0"
tauri-plugin-dialog = "2.2.0"
tauri-plugin-fs = "2.2.0"
regex = "1.11.1"
tauri-plugin-log = "2"
tauri-plugin-log = "2.2.1"
tauri-plugin-os = "2.2.0"

[dependencies.tauri]
version = "2.2.5"
Expand Down
3 changes: 2 additions & 1 deletion src-tauri/capabilities/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"remote-file:default",
"dev-mode:default",
"local-file:default",
"log:default"
"log:default",
"os:default"
]
}
7 changes: 5 additions & 2 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ mod spawn_manager;

#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
let mut builder = tauri::Builder::default();
let mut builder = tauri::Builder::default().plugin(tauri_plugin_os::init());
#[cfg(feature = "tauri-plugin-single-instance")]
{
builder = builder.plugin(tauri_plugin_single_instance::init(|app, _argv, _cwd| {
Expand All @@ -55,7 +55,10 @@ pub fn run() {
.manage(SessionManager::default())
.manage(SpawnManager::default())
.manage(ShellManager::default())
.register_asynchronous_uri_scheme_protocol("remote-file", plugins::file::protocol)
.register_asynchronous_uri_scheme_protocol(
plugins::file::URI_SCHEME,
plugins::file::protocol,
)
.on_page_load(|wnd, payload| {
if payload.event() == PageLoadEvent::Started {
let spawns = wnd.state::<SpawnManager>();
Expand Down
11 changes: 9 additions & 2 deletions src-tauri/src/plugins/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,18 +248,25 @@ pub fn plugin<R: Runtime>(name: &'static str) -> TauriPlugin<R> {
.build()
}

pub const URI_SCHEME: &str = "remote-file";

pub fn protocol<R: Runtime>(
ctx: UriSchemeContext<'_, R>,
req: http::Request<Vec<u8>>,
resp: UriSchemeResponder,
) {
let app = ctx.app_handle().clone();
let Some((device_name, path)) = req.uri().path()[1..].split_once('/') else {
let uri = req.uri();
let Some((device_name, path)) = (match cfg!(target_os = "windows") {
true => uri.path()[1..]
.split_once('/')
.map(|(device, path)| (device, format!("/{path}"))),
_ => uri.host().map(|host| (host, uri.path().to_string())),
}) else {
resp.respond(http::Response::builder().status(404).body(vec![]).unwrap());
return;
};
let device_name = device_name.to_string();
let path = format!("/{path}");
tauri::async_runtime::spawn(async move {
let devices = app.state::<DeviceManager>();
let Some(device) = devices.find(&device_name).await.ok().flatten() else {
Expand Down
9 changes: 8 additions & 1 deletion src/app/core/services/app-manager.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {APP_ID_HBCHANNEL} from "../../shared/constants";
import {DeviceManagerService} from "./device-manager.service";
import {HomebrewChannelConfiguration} from "../../types/luna-apis";
import {download} from "@tauri-apps/plugin-upload";
import {platform} from "@tauri-apps/plugin-os";

@Injectable({
providedIn: 'root'
Expand Down Expand Up @@ -52,6 +53,7 @@ export class AppManagerService {
}

async list(device: Device): Promise<PackageInfo[]> {
const completeIcon = platform() === 'windows' ? this.completeIconWin : this.completeIcon;
return this.luna.call(device, 'luna://com.webos.applicationManager/dev/listApps')
.catch((e) => {
if (e instanceof LunaUnknownMethodError) {
Expand All @@ -60,10 +62,15 @@ export class AppManagerService {
throw e;
})
.then(resp => resp['apps'] as RawPackageInfo[])
.then((result) => result.map(item => this.completeIcon(device, item)));
.then((result) => result.map(item => completeIcon(device, item)));
}

private completeIcon(device: Device, info: RawPackageInfo): PackageInfo {
const iconPath = path.join(info.folderPath, info.icon);
return {iconUri: `remote-file://${device.name}${iconPath}`, ...info};
}

private completeIconWin(device: Device, info: RawPackageInfo): PackageInfo {
const iconPath = path.join(info.folderPath, info.icon);
return {iconUri: `http://remote-file.localhost/${device.name}${iconPath}`, ...info};
}
Expand Down

0 comments on commit f86ea77

Please sign in to comment.