Skip to content

Commit f86ea77

Browse files
authored
Fixed macOS Remote File Protocol (#310)
1 parent 4c14892 commit f86ea77

File tree

8 files changed

+85
-7
lines changed

8 files changed

+85
-7
lines changed

Cargo.lock

Lines changed: 49 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"@tauri-apps/plugin-dialog": "2.2.0",
4242
"@tauri-apps/plugin-fs": "2.2.0",
4343
"@tauri-apps/plugin-log": "2.2.1",
44+
"@tauri-apps/plugin-os": "2.2.0",
4445
"@tauri-apps/plugin-shell": "2.2.0",
4546
"@tauri-apps/plugin-upload": "2.2.1",
4647
"@xterm/addon-fit": "0.10.0",

src-tauri/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ tauri-plugin-shell = "2.2.0"
3939
tauri-plugin-dialog = "2.2.0"
4040
tauri-plugin-fs = "2.2.0"
4141
regex = "1.11.1"
42-
tauri-plugin-log = "2"
42+
tauri-plugin-log = "2.2.1"
43+
tauri-plugin-os = "2.2.0"
4344

4445
[dependencies.tauri]
4546
version = "2.2.5"

src-tauri/capabilities/app.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"remote-file:default",
2121
"dev-mode:default",
2222
"local-file:default",
23-
"log:default"
23+
"log:default",
24+
"os:default"
2425
]
2526
}

src-tauri/src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ mod spawn_manager;
2929

3030
#[cfg_attr(mobile, tauri::mobile_entry_point)]
3131
pub fn run() {
32-
let mut builder = tauri::Builder::default();
32+
let mut builder = tauri::Builder::default().plugin(tauri_plugin_os::init());
3333
#[cfg(feature = "tauri-plugin-single-instance")]
3434
{
3535
builder = builder.plugin(tauri_plugin_single_instance::init(|app, _argv, _cwd| {
@@ -55,7 +55,10 @@ pub fn run() {
5555
.manage(SessionManager::default())
5656
.manage(SpawnManager::default())
5757
.manage(ShellManager::default())
58-
.register_asynchronous_uri_scheme_protocol("remote-file", plugins::file::protocol)
58+
.register_asynchronous_uri_scheme_protocol(
59+
plugins::file::URI_SCHEME,
60+
plugins::file::protocol,
61+
)
5962
.on_page_load(|wnd, payload| {
6063
if payload.event() == PageLoadEvent::Started {
6164
let spawns = wnd.state::<SpawnManager>();

src-tauri/src/plugins/file.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,18 +248,25 @@ pub fn plugin<R: Runtime>(name: &'static str) -> TauriPlugin<R> {
248248
.build()
249249
}
250250

251+
pub const URI_SCHEME: &str = "remote-file";
252+
251253
pub fn protocol<R: Runtime>(
252254
ctx: UriSchemeContext<'_, R>,
253255
req: http::Request<Vec<u8>>,
254256
resp: UriSchemeResponder,
255257
) {
256258
let app = ctx.app_handle().clone();
257-
let Some((device_name, path)) = req.uri().path()[1..].split_once('/') else {
259+
let uri = req.uri();
260+
let Some((device_name, path)) = (match cfg!(target_os = "windows") {
261+
true => uri.path()[1..]
262+
.split_once('/')
263+
.map(|(device, path)| (device, format!("/{path}"))),
264+
_ => uri.host().map(|host| (host, uri.path().to_string())),
265+
}) else {
258266
resp.respond(http::Response::builder().status(404).body(vec![]).unwrap());
259267
return;
260268
};
261269
let device_name = device_name.to_string();
262-
let path = format!("/{path}");
263270
tauri::async_runtime::spawn(async move {
264271
let devices = app.state::<DeviceManager>();
265272
let Some(device) = devices.find(&device_name).await.ok().flatten() else {

src/app/core/services/app-manager.service.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {APP_ID_HBCHANNEL} from "../../shared/constants";
2020
import {DeviceManagerService} from "./device-manager.service";
2121
import {HomebrewChannelConfiguration} from "../../types/luna-apis";
2222
import {download} from "@tauri-apps/plugin-upload";
23+
import {platform} from "@tauri-apps/plugin-os";
2324

2425
@Injectable({
2526
providedIn: 'root'
@@ -52,6 +53,7 @@ export class AppManagerService {
5253
}
5354

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

6668
private completeIcon(device: Device, info: RawPackageInfo): PackageInfo {
69+
const iconPath = path.join(info.folderPath, info.icon);
70+
return {iconUri: `remote-file://${device.name}${iconPath}`, ...info};
71+
}
72+
73+
private completeIconWin(device: Device, info: RawPackageInfo): PackageInfo {
6774
const iconPath = path.join(info.folderPath, info.icon);
6875
return {iconUri: `http://remote-file.localhost/${device.name}${iconPath}`, ...info};
6976
}

0 commit comments

Comments
 (0)