Skip to content

Commit

Permalink
fixes #349
Browse files Browse the repository at this point in the history
  • Loading branch information
icidasset committed Feb 11, 2024
1 parent bc12d52 commit 2a509e1
Show file tree
Hide file tree
Showing 15 changed files with 89 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,4 @@ js-prod:


@watch-system:
watchexec -p --ignore *.elm --ignore *.js --ignore *.ts --ignore *.css -- just system js
watchexec -p --ignore *.elm --ignore *.js --ignore *.ts --ignore *.css --ignore src-tauri/** -- just system js
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ This project can be built with [Node.js](https://nodejs.org/).
# 1. Install dependencies
npm install

# 2. Build, start server & watch for changes
# 2. Build
npx just build

# 3. Start static-file server
npx just server

# 4. Watch for changes (requires [watchexec](https://github.com/watchexec/watchexec/) to be installed)
npx just watch

# Alternatively, to build, serve & watch:
npx just
```
38 changes: 38 additions & 0 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
"devDependencies": {
"@tauri-apps/api": "^2.0.0-beta.0",
"@tauri-apps/cli": "^2.0.0-beta.0",
"@tauri-apps/plugin-dialog": "^2.0.0-beta.0",
"@tauri-apps/plugin-fs": "^2.0.0-beta.0",
"@tauri-apps/plugin-shell": "^2.0.0-beta.0",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
Expand Down
1 change: 1 addition & 0 deletions src-tauri/Cargo.lock

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

1 change: 1 addition & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ tauri-build = { version = "2.0.0-beta", features = [] }
[dependencies]
tauri = { version = "2.0.0-beta", features = ["unstable"] }
tauri-plugin-dialog = "2.0.0-beta"
tauri-plugin-fs = "2.0.0-beta"
tauri-plugin-localhost = "2.0.0-beta"
tauri-plugin-positioner = "2.0.0-beta"
tauri-plugin-shell = "2.0.0-beta"
Expand Down
10 changes: 7 additions & 3 deletions src-tauri/capabilities/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
"$schema": "./schemas/desktop-schema.json",
"identifier": "main-capability",
"description": "Capability for the main window",
"windows": [
"main"
],
"windows": ["main"],
"permissions": [
"path:default",
"event:default",
"window:default",
"app:default",
"dialog:allow-ask",
"dialog:allow-confirm",
"dialog:allow-message",
"dialog:allow-open",
"dialog:allow-save",
"fs:allow-download-write",
"resources:default",
"menu:default",
"tray:default",
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/gen/schemas/capabilities.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"main-capability":{"identifier":"main-capability","description":"Capability for the main window","context":"local","windows":["main"],"permissions":["path:default","event:default","window:default","app:default","resources:default","menu:default","tray:default","shell:allow-open"],"platforms":["linux","macOS","windows","android","iOS"]}}
{"main-capability":{"identifier":"main-capability","description":"Capability for the main window","context":"local","windows":["main"],"permissions":["path:default","event:default","window:default","app:default","dialog:allow-ask","dialog:allow-confirm","dialog:allow-message","dialog:allow-open","dialog:allow-save","fs:allow-download-write","resources:default","menu:default","tray:default","shell:allow-open"],"platforms":["linux","macOS","windows","android","iOS"]}}
2 changes: 1 addition & 1 deletion src-tauri/gen/schemas/plugin-manifests.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ fn main() {

fn default_builder() -> tauri::Builder<tauri::Wry> {
tauri::Builder::default()
.plugin(tauri_plugin_fs::init())
.plugin(tauri_plugin_shell::init())
.plugin(tauri_plugin_dialog::init())
.plugin(tauri_plugin_window_state::Builder::default().build())
Expand Down
1 change: 1 addition & 0 deletions src/Applications/UI.elm
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ init flags url key =
, isDragging = False
, isLoading = True
, isOnline = flags.isOnline
, isTauri = flags.isTauri
, isTouchDevice = False
, isUpgrading = flags.upgrade
, lastFm = LastFm.initialModel
Expand Down
3 changes: 3 additions & 0 deletions src/Applications/UI/Ports.elm
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ port collectFissionCapabilities : () -> Cmd msg
port copyToClipboard : String -> Cmd msg


port downloadJsonUsingTauri : { filename : String, json : String } -> Cmd msg


port loadAlbumCovers : { list : Bool, coverView : Bool } -> Cmd msg


Expand Down
2 changes: 2 additions & 0 deletions src/Applications/UI/Types.elm
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type alias Flags =
, initialTime : Int
, isInstallingServiceWorker : Bool -- ie. Installing SW for the first time
, isOnline : Bool
, isTauri : Bool
, upgrade : Bool
, version : String
, viewport : Viewport
Expand All @@ -67,6 +68,7 @@ type alias Model =
, isDragging : Bool
, isLoading : Bool
, isOnline : Bool
, isTauri : Bool
, isTouchDevice : Bool
, isUpgrading : Bool
, lastFm : LastFm.Model
Expand Down
7 changes: 6 additions & 1 deletion src/Applications/UI/User/State/Export.elm
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ export model =
}
|> encodeHypaethralData
|> Json.Encode.encode 2
|> File.Download.string "diffuse.json" "application/json"
|> (if model.isTauri then
\json -> Ports.downloadJsonUsingTauri { filename = "diffuse.json", json = json }

else
File.Download.string "diffuse.json" "application/json"
)
|> return model


Expand Down
16 changes: 14 additions & 2 deletions src/Javascript/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { version } from "../../package.json"
// 🌸


const isNativeWrapper = location.host === "localhost:44999" || location.host === "127.0.0.1:44999"
const isNativeWrapper = !!globalThis.__TAURI__



Expand Down Expand Up @@ -121,6 +121,7 @@ async function initialise(reg) {
initialTime: Date.now(),
isInstallingServiceWorker: !!reg.installing,
isOnline: navigator.onLine,
isTauri: isNativeWrapper,
upgrade: viableForUpgrade(),
version,
viewport: {
Expand All @@ -141,7 +142,18 @@ async function initialise(reg) {
wire.odd()

// Other ports
app.ports.openUrlOnNewPage.subscribe(url => {
app.ports.downloadJsonUsingTauri.subscribe(async (
{ filename, json }: { filename: string, json: string }
) => {
const { save } = await import("@tauri-apps/plugin-dialog")
const { writeTextFile } = await import("@tauri-apps/plugin-fs")
const { BaseDirectory } = await import("@tauri-apps/api/path")

const filePath = await save({ defaultPath: filename })
await writeTextFile(filePath || filename, json, { baseDir: BaseDirectory.Download })
})

app.ports.openUrlOnNewPage.subscribe((url: string) => {
if (globalThis.__TAURI__) {
globalThis.__TAURI__.shell.open(
url.includes("://") ? url : `${location.origin}/${url.replace(/^\.\//, "")}`
Expand Down

0 comments on commit 2a509e1

Please sign in to comment.