Migrate to Tauri V2
This commit is contained in:
11
package.json
11
package.json
@@ -27,7 +27,14 @@
|
||||
"@risuai/ccardlib": "^0.4.1",
|
||||
"@smithy/protocol-http": "^3.0.12",
|
||||
"@smithy/signature-v4": "^2.0.19",
|
||||
"@tauri-apps/api": "1.5.3",
|
||||
"@tauri-apps/api": "2.0.0",
|
||||
"@tauri-apps/plugin-dialog": "~2",
|
||||
"@tauri-apps/plugin-fs": "~2",
|
||||
"@tauri-apps/plugin-http": "~2",
|
||||
"@tauri-apps/plugin-os": "~2",
|
||||
"@tauri-apps/plugin-process": "~2",
|
||||
"@tauri-apps/plugin-shell": "~2",
|
||||
"@tauri-apps/plugin-updater": "~2",
|
||||
"@types/markdown-it": "^14.1.1",
|
||||
"@xenova/transformers": "^2.17.1",
|
||||
"blueimp-md5": "^2.19.0",
|
||||
@@ -81,7 +88,7 @@
|
||||
"@sveltejs/vite-plugin-svelte": "3.0.1",
|
||||
"@swc/core": "1.5.7",
|
||||
"@tailwindcss/typography": "^0.5.10",
|
||||
"@tauri-apps/cli": "1.5.11",
|
||||
"@tauri-apps/cli": "2.0.2",
|
||||
"@tsconfig/svelte": "^3.0.0",
|
||||
"@types/blueimp-md5": "^2.18.2",
|
||||
"@types/codemirror": "^5.60.15",
|
||||
|
||||
171
pnpm-lock.yaml
generated
171
pnpm-lock.yaml
generated
@@ -42,8 +42,29 @@ importers:
|
||||
specifier: ^2.0.19
|
||||
version: 2.0.19
|
||||
'@tauri-apps/api':
|
||||
specifier: 1.5.3
|
||||
version: 1.5.3
|
||||
specifier: 2.0.0
|
||||
version: 2.0.0
|
||||
'@tauri-apps/plugin-dialog':
|
||||
specifier: ~2
|
||||
version: 2.0.0
|
||||
'@tauri-apps/plugin-fs':
|
||||
specifier: ~2
|
||||
version: 2.0.0
|
||||
'@tauri-apps/plugin-http':
|
||||
specifier: ~2
|
||||
version: 2.0.0
|
||||
'@tauri-apps/plugin-os':
|
||||
specifier: ~2
|
||||
version: 2.0.0
|
||||
'@tauri-apps/plugin-process':
|
||||
specifier: ~2
|
||||
version: 2.0.0
|
||||
'@tauri-apps/plugin-shell':
|
||||
specifier: ~2
|
||||
version: 2.0.0
|
||||
'@tauri-apps/plugin-updater':
|
||||
specifier: ~2
|
||||
version: 2.0.0
|
||||
'@types/markdown-it':
|
||||
specifier: ^14.1.1
|
||||
version: 14.1.1
|
||||
@@ -199,8 +220,8 @@ importers:
|
||||
specifier: ^0.5.10
|
||||
version: 0.5.10(tailwindcss@3.4.1(ts-node@10.9.2(@swc/core@1.5.7)(@types/node@18.19.7)(typescript@5.3.3)))
|
||||
'@tauri-apps/cli':
|
||||
specifier: 1.5.11
|
||||
version: 1.5.11
|
||||
specifier: 2.0.2
|
||||
version: 2.0.2
|
||||
'@tsconfig/svelte':
|
||||
specifier: ^3.0.0
|
||||
version: 3.0.0
|
||||
@@ -914,75 +935,95 @@ packages:
|
||||
peerDependencies:
|
||||
tailwindcss: '>=3.0.0 || insiders'
|
||||
|
||||
'@tauri-apps/api@1.5.3':
|
||||
resolution: {integrity: sha512-zxnDjHHKjOsrIzZm6nO5Xapb/BxqUq1tc7cGkFXsFkGTsSWgCPH1D8mm0XS9weJY2OaR73I3k3S+b7eSzJDfqA==}
|
||||
engines: {node: '>= 14.6.0', npm: '>= 6.6.0', yarn: '>= 1.19.1'}
|
||||
'@tauri-apps/api@2.0.0':
|
||||
resolution: {integrity: sha512-moKgCp2EX7X5GiOx/G/bmoEpkFQVVmyS98UaJU4xUVzan+E1BdwlAKcbip+cGldshYOqL4JSwAEN1OkRXeug0Q==}
|
||||
|
||||
'@tauri-apps/cli-darwin-arm64@1.5.11':
|
||||
resolution: {integrity: sha512-2NLSglDb5VfvTbMtmOKWyD+oaL/e8Z/ZZGovHtUFyUSFRabdXc6cZOlcD1BhFvYkHqm+TqGaz5qtPR5UbqDs8A==}
|
||||
'@tauri-apps/cli-darwin-arm64@2.0.2':
|
||||
resolution: {integrity: sha512-B+/a8Q6wAqmB4A4HVeK0oQP5TdQGKW60ZLOI9O2ktH2HPr9ETr3XkwXPuJ2uAOuGEgtRZHBgFOIgG000vMnKlg==}
|
||||
engines: {node: '>= 10'}
|
||||
cpu: [arm64]
|
||||
os: [darwin]
|
||||
|
||||
'@tauri-apps/cli-darwin-x64@1.5.11':
|
||||
resolution: {integrity: sha512-/RQllHiJRH2fJOCudtZlaUIjofkHzP3zZgxi71ZUm7Fy80smU5TDfwpwOvB0wSVh0g/ciDjMArCSTo0MRvL+ag==}
|
||||
'@tauri-apps/cli-darwin-x64@2.0.2':
|
||||
resolution: {integrity: sha512-kaurhn6XT4gAVCPAQSSHl/CHFxTS0ljc47N7iGTSlYJ03sCWPRZeNuVa/bn6rolz9MA2JfnRnFqB1pUL6jzp9Q==}
|
||||
engines: {node: '>= 10'}
|
||||
cpu: [x64]
|
||||
os: [darwin]
|
||||
|
||||
'@tauri-apps/cli-linux-arm-gnueabihf@1.5.11':
|
||||
resolution: {integrity: sha512-IlBuBPKmMm+a5LLUEK6a21UGr9ZYd6zKuKLq6IGM4tVweQa8Sf2kP2Nqs74dMGIUrLmMs0vuqdURpykQg+z4NQ==}
|
||||
'@tauri-apps/cli-linux-arm-gnueabihf@2.0.2':
|
||||
resolution: {integrity: sha512-bVrofjlacMxmGMcqK18iBW05tsZXOd19/MnqruFFcHSVjvkGGIXHMtUbMXnZNXBPkHDsnfytNtkY9SZGfCFaBA==}
|
||||
engines: {node: '>= 10'}
|
||||
cpu: [arm]
|
||||
os: [linux]
|
||||
|
||||
'@tauri-apps/cli-linux-arm64-gnu@1.5.11':
|
||||
resolution: {integrity: sha512-w+k1bNHCU/GbmXshtAhyTwqosThUDmCEFLU4Zkin1vl2fuAtQry2RN7thfcJFepblUGL/J7yh3Q/0+BCjtspKQ==}
|
||||
'@tauri-apps/cli-linux-arm64-gnu@2.0.2':
|
||||
resolution: {integrity: sha512-7XCBn0TTBVQGnV42dXcbHPLg/9W8kJoVzuliIozvNGyRWxfXqDbQYzpI48HUQG3LgHMabcw8+pVZAfGhevLrCA==}
|
||||
engines: {node: '>= 10'}
|
||||
cpu: [arm64]
|
||||
os: [linux]
|
||||
|
||||
'@tauri-apps/cli-linux-arm64-musl@1.5.11':
|
||||
resolution: {integrity: sha512-PN6/dl+OfYQ/qrAy4HRAfksJ2AyWQYn2IA/2Wwpaa7SDRz2+hzwTQkvajuvy0sQ5L2WCG7ymFYRYMbpC6Hk9Pg==}
|
||||
'@tauri-apps/cli-linux-arm64-musl@2.0.2':
|
||||
resolution: {integrity: sha512-1xi2SreGVlpAL68MCsDUY63rdItUdPZreXIAcOVqvUehcJRYOa1XGSBhrV0YXRgZeh0AtKC19z6PRzcv4rosZA==}
|
||||
engines: {node: '>= 10'}
|
||||
cpu: [arm64]
|
||||
os: [linux]
|
||||
|
||||
'@tauri-apps/cli-linux-x64-gnu@1.5.11':
|
||||
resolution: {integrity: sha512-MTVXLi89Nj7Apcvjezw92m7ZqIDKT5SFKZtVPCg6RoLUBTzko/BQoXYIRWmdoz2pgkHDUHgO2OMJ8oKzzddXbw==}
|
||||
'@tauri-apps/cli-linux-x64-gnu@2.0.2':
|
||||
resolution: {integrity: sha512-WVjwYzPWFqZVg1fx6KSU5w47Q0VbMyaCp34qs5EcS8EIU0/RnofdzqUoOYqvgGVgNgoz7Pj5dXK2SkS8BHXMmA==}
|
||||
engines: {node: '>= 10'}
|
||||
cpu: [x64]
|
||||
os: [linux]
|
||||
|
||||
'@tauri-apps/cli-linux-x64-musl@1.5.11':
|
||||
resolution: {integrity: sha512-kwzAjqFpz7rvTs7WGZLy/a5nS5t15QKr3E9FG95MNF0exTl3d29YoAUAe1Mn0mOSrTJ9Z+vYYAcI/QdcsGBP+w==}
|
||||
'@tauri-apps/cli-linux-x64-musl@2.0.2':
|
||||
resolution: {integrity: sha512-h5miE2mctgaQNn/BbG9o1pnJcrx+VGBi2A6JFqGu934lFgSV5+s28M8Gc8AF2JgFH4hQV4IuMkeSw8Chu5Dodg==}
|
||||
engines: {node: '>= 10'}
|
||||
cpu: [x64]
|
||||
os: [linux]
|
||||
|
||||
'@tauri-apps/cli-win32-arm64-msvc@1.5.11':
|
||||
resolution: {integrity: sha512-L+5NZ/rHrSUrMxjj6YpFYCXp6wHnq8c8SfDTBOX8dO8x+5283/vftb4vvuGIsLS4UwUFXFnLt3XQr44n84E67Q==}
|
||||
'@tauri-apps/cli-win32-arm64-msvc@2.0.2':
|
||||
resolution: {integrity: sha512-2b8oO0+dYonahG5PfA/zoq0zlafLclfmXgqoWDZ++UiPtQHJNpNeEQ8GWbSFKGHQ494Jo6jHvazOojGRE1kqAg==}
|
||||
engines: {node: '>= 10'}
|
||||
cpu: [arm64]
|
||||
os: [win32]
|
||||
|
||||
'@tauri-apps/cli-win32-ia32-msvc@1.5.11':
|
||||
resolution: {integrity: sha512-oVlD9IVewrY0lZzTdb71kNXkjdgMqFq+ohb67YsJb4Rf7o8A9DTlFds1XLCe3joqLMm4M+gvBKD7YnGIdxQ9vA==}
|
||||
'@tauri-apps/cli-win32-ia32-msvc@2.0.2':
|
||||
resolution: {integrity: sha512-axgICLunFi0To3EibdCBgbST5RocsSmtM4c04+CbcX8WQQosJ9ziWlCSrrOTRr+gJERAMSvEyVUS98f6bWMw9A==}
|
||||
engines: {node: '>= 10'}
|
||||
cpu: [ia32]
|
||||
os: [win32]
|
||||
|
||||
'@tauri-apps/cli-win32-x64-msvc@1.5.11':
|
||||
resolution: {integrity: sha512-1CexcqUFCis5ypUIMOKllxUBrna09McbftWENgvVXMfA+SP+yPDPAVb8fIvUcdTIwR/yHJwcIucmTB4anww4vg==}
|
||||
'@tauri-apps/cli-win32-x64-msvc@2.0.2':
|
||||
resolution: {integrity: sha512-JR17cM6+DyExZRgpXr2/DdqvcFYi/EKvQt8dI5R1/uQoesWd8jeNnrU7c1FG1Zmw9+pTzDztsNqEKsrNq2sNIg==}
|
||||
engines: {node: '>= 10'}
|
||||
cpu: [x64]
|
||||
os: [win32]
|
||||
|
||||
'@tauri-apps/cli@1.5.11':
|
||||
resolution: {integrity: sha512-B475D7phZrq5sZ3kDABH4g2mEoUIHtnIO+r4ZGAAfsjMbZCwXxR/jlMGTEL+VO3YzjpF7gQe38IzB4vLBbVppw==}
|
||||
'@tauri-apps/cli@2.0.2':
|
||||
resolution: {integrity: sha512-R4ontHZvXORArERAHIidp5zRfZEshZczTiK+poslBv7AGKpQZoMw+E49zns7mOmP64i2Cq9Ci0pJvi4Rm8Okzw==}
|
||||
engines: {node: '>= 10'}
|
||||
hasBin: true
|
||||
|
||||
'@tauri-apps/plugin-dialog@2.0.0':
|
||||
resolution: {integrity: sha512-ApNkejXP2jpPBSifznPPcHTXxu9/YaRW+eJ+8+nYwqp0lLUtebFHG4QhxitM43wwReHE81WAV1DQ/b+2VBftOA==}
|
||||
|
||||
'@tauri-apps/plugin-fs@2.0.0':
|
||||
resolution: {integrity: sha512-BNEeQQ5aH8J5SwYuWgRszVyItsmquRuzK2QRkVj8Z0sCsLnSvJFYI3JHRzzr3ltZGq1nMPtblrlZzuKqVzRawA==}
|
||||
|
||||
'@tauri-apps/plugin-http@2.0.0':
|
||||
resolution: {integrity: sha512-UfKAICL25ayluV/SjiEQujz8q/2uyAzp3u9uaHFkaIyKS5usBL8DoqSwi4eKz2mEjkbxTwldhDEXG4CEfTE0JQ==}
|
||||
|
||||
'@tauri-apps/plugin-os@2.0.0':
|
||||
resolution: {integrity: sha512-M7hG/nNyQYTJxVG/UhTKhp9mpXriwWzrs9mqDreB8mIgqA3ek5nHLdwRZJWhkKjZrnDT4v9CpA9BhYeplTlAiA==}
|
||||
|
||||
'@tauri-apps/plugin-process@2.0.0':
|
||||
resolution: {integrity: sha512-OYzi0GnkrF4NAnsHZU7U3tjSoP0PbeAlO7T1Z+vJoBUH9sFQ1NSLqWYWQyf8hcb3gVWe7P1JggjiskO+LST1ug==}
|
||||
|
||||
'@tauri-apps/plugin-shell@2.0.0':
|
||||
resolution: {integrity: sha512-OpW2+ycgJLrEoZityWeWYk+6ZWP9VyiAfbO+N/O8VfLkqyOym8kXh7odKDfINx9RAotkSGBtQM4abyKfJDkcUg==}
|
||||
|
||||
'@tauri-apps/plugin-updater@2.0.0':
|
||||
resolution: {integrity: sha512-N0cl71g7RPr7zK2Fe5aoIwzw14NcdLcz7XMGFWZVjprsqgDRWoxbnUkknyCQMZthjhGkppCd/wN2MIsUz+eAhQ==}
|
||||
|
||||
'@trapezedev/gradle-parse@7.0.10':
|
||||
resolution: {integrity: sha512-k822Is3jGroqOTKF0gAFm80LmhFJWBAyZvNtyuXq6uQUzDDe2fj/gHwixP6VFzlpaWKLP7IuR609Xv8gwJCXyg==}
|
||||
|
||||
@@ -4383,50 +4424,78 @@ snapshots:
|
||||
postcss-selector-parser: 6.0.10
|
||||
tailwindcss: 3.4.1(ts-node@10.9.2(@swc/core@1.5.7)(@types/node@18.19.7)(typescript@5.3.3))
|
||||
|
||||
'@tauri-apps/api@1.5.3': {}
|
||||
'@tauri-apps/api@2.0.0': {}
|
||||
|
||||
'@tauri-apps/cli-darwin-arm64@1.5.11':
|
||||
'@tauri-apps/cli-darwin-arm64@2.0.2':
|
||||
optional: true
|
||||
|
||||
'@tauri-apps/cli-darwin-x64@1.5.11':
|
||||
'@tauri-apps/cli-darwin-x64@2.0.2':
|
||||
optional: true
|
||||
|
||||
'@tauri-apps/cli-linux-arm-gnueabihf@1.5.11':
|
||||
'@tauri-apps/cli-linux-arm-gnueabihf@2.0.2':
|
||||
optional: true
|
||||
|
||||
'@tauri-apps/cli-linux-arm64-gnu@1.5.11':
|
||||
'@tauri-apps/cli-linux-arm64-gnu@2.0.2':
|
||||
optional: true
|
||||
|
||||
'@tauri-apps/cli-linux-arm64-musl@1.5.11':
|
||||
'@tauri-apps/cli-linux-arm64-musl@2.0.2':
|
||||
optional: true
|
||||
|
||||
'@tauri-apps/cli-linux-x64-gnu@1.5.11':
|
||||
'@tauri-apps/cli-linux-x64-gnu@2.0.2':
|
||||
optional: true
|
||||
|
||||
'@tauri-apps/cli-linux-x64-musl@1.5.11':
|
||||
'@tauri-apps/cli-linux-x64-musl@2.0.2':
|
||||
optional: true
|
||||
|
||||
'@tauri-apps/cli-win32-arm64-msvc@1.5.11':
|
||||
'@tauri-apps/cli-win32-arm64-msvc@2.0.2':
|
||||
optional: true
|
||||
|
||||
'@tauri-apps/cli-win32-ia32-msvc@1.5.11':
|
||||
'@tauri-apps/cli-win32-ia32-msvc@2.0.2':
|
||||
optional: true
|
||||
|
||||
'@tauri-apps/cli-win32-x64-msvc@1.5.11':
|
||||
'@tauri-apps/cli-win32-x64-msvc@2.0.2':
|
||||
optional: true
|
||||
|
||||
'@tauri-apps/cli@1.5.11':
|
||||
'@tauri-apps/cli@2.0.2':
|
||||
optionalDependencies:
|
||||
'@tauri-apps/cli-darwin-arm64': 1.5.11
|
||||
'@tauri-apps/cli-darwin-x64': 1.5.11
|
||||
'@tauri-apps/cli-linux-arm-gnueabihf': 1.5.11
|
||||
'@tauri-apps/cli-linux-arm64-gnu': 1.5.11
|
||||
'@tauri-apps/cli-linux-arm64-musl': 1.5.11
|
||||
'@tauri-apps/cli-linux-x64-gnu': 1.5.11
|
||||
'@tauri-apps/cli-linux-x64-musl': 1.5.11
|
||||
'@tauri-apps/cli-win32-arm64-msvc': 1.5.11
|
||||
'@tauri-apps/cli-win32-ia32-msvc': 1.5.11
|
||||
'@tauri-apps/cli-win32-x64-msvc': 1.5.11
|
||||
'@tauri-apps/cli-darwin-arm64': 2.0.2
|
||||
'@tauri-apps/cli-darwin-x64': 2.0.2
|
||||
'@tauri-apps/cli-linux-arm-gnueabihf': 2.0.2
|
||||
'@tauri-apps/cli-linux-arm64-gnu': 2.0.2
|
||||
'@tauri-apps/cli-linux-arm64-musl': 2.0.2
|
||||
'@tauri-apps/cli-linux-x64-gnu': 2.0.2
|
||||
'@tauri-apps/cli-linux-x64-musl': 2.0.2
|
||||
'@tauri-apps/cli-win32-arm64-msvc': 2.0.2
|
||||
'@tauri-apps/cli-win32-ia32-msvc': 2.0.2
|
||||
'@tauri-apps/cli-win32-x64-msvc': 2.0.2
|
||||
|
||||
'@tauri-apps/plugin-dialog@2.0.0':
|
||||
dependencies:
|
||||
'@tauri-apps/api': 2.0.0
|
||||
|
||||
'@tauri-apps/plugin-fs@2.0.0':
|
||||
dependencies:
|
||||
'@tauri-apps/api': 2.0.0
|
||||
|
||||
'@tauri-apps/plugin-http@2.0.0':
|
||||
dependencies:
|
||||
'@tauri-apps/api': 2.0.0
|
||||
|
||||
'@tauri-apps/plugin-os@2.0.0':
|
||||
dependencies:
|
||||
'@tauri-apps/api': 2.0.0
|
||||
|
||||
'@tauri-apps/plugin-process@2.0.0':
|
||||
dependencies:
|
||||
'@tauri-apps/api': 2.0.0
|
||||
|
||||
'@tauri-apps/plugin-shell@2.0.0':
|
||||
dependencies:
|
||||
'@tauri-apps/api': 2.0.0
|
||||
|
||||
'@tauri-apps/plugin-updater@2.0.0':
|
||||
dependencies:
|
||||
'@tauri-apps/api': 2.0.0
|
||||
|
||||
'@trapezedev/gradle-parse@7.0.10': {}
|
||||
|
||||
|
||||
3001
src-tauri/Cargo.lock
generated
3001
src-tauri/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -10,10 +10,10 @@ edition = "2021"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[build-dependencies]
|
||||
tauri-build = { version = "1.4.0", features = [] }
|
||||
tauri-build = { version = "2", features = [] }
|
||||
|
||||
[dependencies]
|
||||
tauri = { version = "1.6.0", features = [ "updater", "app-all", "dialog-all", "fs-all", "http-all", "os-all", "path-all", "process-relaunch", "protocol-all", "reqwest-client", "shell-open", "window-maximize", "window-set-fullscreen"] }
|
||||
tauri = { version = "2", features = ["protocol-asset"] }
|
||||
serde_json = "1.0"
|
||||
tiktoken-rs = "0.4.0"
|
||||
base64 = "0.21.0"
|
||||
@@ -23,13 +23,23 @@ zip = "0.6.6"
|
||||
tar = "0.4.40"
|
||||
eventsource-client = "0.12.2"
|
||||
futures = "0.3.30"
|
||||
actix-web = "4.0"
|
||||
actix-cors = "0.6"
|
||||
actix-rt = "2.5"
|
||||
url = "2.2"
|
||||
uuid = { version = "1.9.1", features = [ "v4" ] }
|
||||
tauri-plugin-fs = "2"
|
||||
tauri-plugin-os = "2"
|
||||
tauri-plugin-dialog = "2"
|
||||
tauri-plugin-process = "2"
|
||||
tauri-plugin-shell = "2"
|
||||
tauri-plugin-http = "2"
|
||||
|
||||
[features]
|
||||
# this feature is used for production builds or when `devPath` points to the filesystem
|
||||
# DO NOT REMOVE!!
|
||||
custom-protocol = ["tauri/custom-protocol"]
|
||||
|
||||
# [lib]
|
||||
# name = "alib"
|
||||
# crate-type = ["staticlib", "cdylib", "rlib", "lib"]
|
||||
|
||||
[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies]
|
||||
tauri-plugin-updater = "2"
|
||||
|
||||
14
src-tauri/capabilities/desktop.json
Normal file
14
src-tauri/capabilities/desktop.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"identifier": "desktop-capability",
|
||||
"platforms": [
|
||||
"macOS",
|
||||
"windows",
|
||||
"linux"
|
||||
],
|
||||
"permissions": [
|
||||
"updater:default",
|
||||
"process:default",
|
||||
"shell:default",
|
||||
"http:default"
|
||||
]
|
||||
}
|
||||
73
src-tauri/capabilities/migrated.json
Normal file
73
src-tauri/capabilities/migrated.json
Normal file
@@ -0,0 +1,73 @@
|
||||
{
|
||||
"identifier": "migrated",
|
||||
"description": "permissions that were migrated from v1",
|
||||
"local": true,
|
||||
"windows": [
|
||||
"main"
|
||||
],
|
||||
"permissions": [
|
||||
"core:default",
|
||||
"fs:allow-read-file",
|
||||
"fs:allow-write-file",
|
||||
"fs:allow-read-dir",
|
||||
"fs:allow-copy-file",
|
||||
"fs:allow-mkdir",
|
||||
"fs:allow-remove",
|
||||
"fs:allow-remove",
|
||||
"fs:allow-rename",
|
||||
"fs:allow-exists",
|
||||
{
|
||||
"identifier": "fs:scope",
|
||||
"allow": [
|
||||
"$APPDATA",
|
||||
"$APPDATA/*",
|
||||
"$APPDATA/**/*",
|
||||
"$DOWNLOAD/*",
|
||||
"/data/**/*",
|
||||
"$RESOURCE/*"
|
||||
]
|
||||
},
|
||||
"core:window:allow-maximize",
|
||||
"core:window:allow-set-fullscreen",
|
||||
"shell:allow-open",
|
||||
"dialog:allow-open",
|
||||
"dialog:allow-save",
|
||||
"dialog:allow-message",
|
||||
"dialog:allow-ask",
|
||||
"dialog:allow-confirm",
|
||||
{
|
||||
"identifier": "http:default",
|
||||
"allow": [
|
||||
{
|
||||
"url": "https://*/*"
|
||||
},
|
||||
{
|
||||
"url": "https://*/**/*"
|
||||
},
|
||||
{
|
||||
"url": "http://*/*"
|
||||
},
|
||||
{
|
||||
"url": "http://*/**/*"
|
||||
}
|
||||
]
|
||||
},
|
||||
"os:allow-platform",
|
||||
"os:allow-version",
|
||||
"os:allow-os-type",
|
||||
"os:allow-family",
|
||||
"os:allow-arch",
|
||||
"os:allow-exe-extension",
|
||||
"os:allow-locale",
|
||||
"os:allow-hostname",
|
||||
"process:allow-restart",
|
||||
"core:app:allow-app-show",
|
||||
"core:app:allow-app-hide",
|
||||
"fs:default",
|
||||
"os:default",
|
||||
"dialog:default",
|
||||
"process:default",
|
||||
"shell:default",
|
||||
"http:default"
|
||||
]
|
||||
}
|
||||
1
src-tauri/gen/schemas/acl-manifests.json
Normal file
1
src-tauri/gen/schemas/acl-manifests.json
Normal file
File diff suppressed because one or more lines are too long
1
src-tauri/gen/schemas/capabilities.json
Normal file
1
src-tauri/gen/schemas/capabilities.json
Normal file
@@ -0,0 +1 @@
|
||||
{"desktop-capability":{"identifier":"desktop-capability","description":"","local":true,"permissions":["updater:default","process:default","shell:default","http:default"],"platforms":["macOS","windows","linux"]},"migrated":{"identifier":"migrated","description":"permissions that were migrated from v1","local":true,"windows":["main"],"permissions":["core:default","fs:allow-read-file","fs:allow-write-file","fs:allow-read-dir","fs:allow-copy-file","fs:allow-mkdir","fs:allow-remove","fs:allow-remove","fs:allow-rename","fs:allow-exists",{"identifier":"fs:scope","allow":["$APPDATA","$APPDATA/*","$APPDATA/**/*","$DOWNLOAD/*","/data/**/*","$RESOURCE/*"]},"core:window:allow-maximize","core:window:allow-set-fullscreen","shell:allow-open","dialog:allow-open","dialog:allow-save","dialog:allow-message","dialog:allow-ask","dialog:allow-confirm",{"identifier":"http:default","allow":[{"url":"https://*/*"},{"url":"https://*/**/*"},{"url":"http://*/*"},{"url":"http://*/**/*"}]},"os:allow-platform","os:allow-version","os:allow-os-type","os:allow-family","os:allow-arch","os:allow-exe-extension","os:allow-locale","os:allow-hostname","process:allow-restart","core:app:allow-app-show","core:app:allow-app-hide","fs:default","os:default","dialog:default","process:default","shell:default","http:default"]}}
|
||||
5358
src-tauri/gen/schemas/desktop-schema.json
Normal file
5358
src-tauri/gen/schemas/desktop-schema.json
Normal file
File diff suppressed because it is too large
Load Diff
5358
src-tauri/gen/schemas/windows-schema.json
Normal file
5358
src-tauri/gen/schemas/windows-schema.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,31 +1,24 @@
|
||||
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
|
||||
#[tauri::command]
|
||||
fn greet(name: &str) -> String {
|
||||
format!("Hello, {}! You've been greeted from Rust!", name)
|
||||
}
|
||||
|
||||
use serde_json::Value;
|
||||
use reqwest::header::{HeaderMap, HeaderName, HeaderValue};
|
||||
use base64::{engine::general_purpose, Engine as _};
|
||||
use tauri::Manager;
|
||||
use tauri::State;
|
||||
use std::io::Write;
|
||||
use std::sync::Mutex;
|
||||
use std::{time::Duration, path::Path};
|
||||
use reqwest::header::{HeaderMap, HeaderName, HeaderValue};
|
||||
use serde_json::json;
|
||||
use serde_json::Value;
|
||||
use tauri::path::BaseDirectory;
|
||||
use std::collections::HashMap;
|
||||
use actix_cors::Cors;
|
||||
use tauri::api::path::app_data_dir;
|
||||
use actix_web::{web, HttpRequest, HttpResponse, HttpServer, Responder, App, post};
|
||||
use std::fs::File;
|
||||
struct HttpSecret(Mutex<String>);
|
||||
struct HttpPort(Mutex<u16>);
|
||||
use std::io::Write;
|
||||
use std::{path::Path, time::Duration};
|
||||
use tauri::Manager;
|
||||
use tauri::{AppHandle, Emitter};
|
||||
|
||||
#[tauri::command]
|
||||
async fn native_request(url: String, body: String, header: String, method:String) -> String {
|
||||
async fn native_request(url: String, body: String, header: String, method: String) -> String {
|
||||
let headers_json: Value = match serde_json::from_str(&header) {
|
||||
Ok(h) => h,
|
||||
Err(e) => return format!(r#"{{"success":false,"body":"{}"}}"#, e.to_string()),
|
||||
@@ -50,7 +43,7 @@ async fn native_request(url: String, body: String, header: String, method:String
|
||||
}
|
||||
|
||||
let client = reqwest::Client::new();
|
||||
let response:Result<reqwest::Response, reqwest::Error>;
|
||||
let response: Result<reqwest::Response, reqwest::Error>;
|
||||
|
||||
if method == "POST" {
|
||||
response = client
|
||||
@@ -60,8 +53,7 @@ async fn native_request(url: String, body: String, header: String, method:String
|
||||
.body(body)
|
||||
.send()
|
||||
.await;
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
response = client
|
||||
.get(&url)
|
||||
.headers(headers)
|
||||
@@ -80,14 +72,17 @@ async fn native_request(url: String, body: String, header: String, method:String
|
||||
};
|
||||
let encoded = general_purpose::STANDARD.encode(&bytes);
|
||||
|
||||
format!(r#"{{"success":true,"body":"{}","headers":{}}}"#, encoded, header_json)
|
||||
format!(
|
||||
r#"{{"success":true,"body":"{}","headers":{}}}"#,
|
||||
encoded, header_json
|
||||
)
|
||||
}
|
||||
Err(e) => format!(r#"{{"success":false,"body":"{}"}}"#, e.to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn check_auth(fpath: String, auth: String) -> bool{
|
||||
fn check_auth(fpath: String, auth: String) -> bool {
|
||||
//check file exists
|
||||
let path = Path::new(&fpath);
|
||||
if !path.exists() {
|
||||
@@ -110,8 +105,6 @@ fn check_auth(fpath: String, auth: String) -> bool{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// read file, return false when error
|
||||
let got_auth = std::fs::read_to_string(&path);
|
||||
|
||||
@@ -119,8 +112,7 @@ fn check_auth(fpath: String, auth: String) -> bool{
|
||||
if got_auth.is_err() {
|
||||
println!("Error reading file {}", path.display());
|
||||
return false;
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
// check auth
|
||||
if got_auth.unwrap() != auth {
|
||||
println!("Auth does not match");
|
||||
@@ -129,11 +121,10 @@ fn check_auth(fpath: String, auth: String) -> bool{
|
||||
println!("Auth matches");
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn install_python(path:String) -> bool{
|
||||
async fn install_python(path: String) -> bool {
|
||||
//get python embeddable depending on os
|
||||
let os = std::env::consts::OS;
|
||||
let url;
|
||||
@@ -146,8 +137,7 @@ async fn install_python(path:String) -> bool{
|
||||
println!("Path: {}", path);
|
||||
if os == "windows" {
|
||||
url = "https://www.python.org/ftp/python/3.11.7/python-3.11.7-embed-amd64.zip".to_string()
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
println!("OS not supported");
|
||||
return false;
|
||||
}
|
||||
@@ -168,16 +158,13 @@ async fn install_python(path:String) -> bool{
|
||||
if os == "windows" {
|
||||
let mut zipf = ZipArchive::new(std::fs::File::open(&zip_path).unwrap()).unwrap();
|
||||
zipf.extract(&py_path).unwrap();
|
||||
}
|
||||
else if os == "linux" {
|
||||
} else if os == "linux" {
|
||||
let mut tarf = tar::Archive::new(std::fs::File::open(&zip_path).unwrap());
|
||||
tarf.unpack(&py_path).unwrap();
|
||||
}
|
||||
else if os == "macos" {
|
||||
} else if os == "macos" {
|
||||
let mut zipf = zip::ZipArchive::new(std::fs::File::open(&zip_path).unwrap()).unwrap();
|
||||
zipf.extract(&py_path).unwrap();
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
println!("OS not supported");
|
||||
return false;
|
||||
}
|
||||
@@ -191,20 +178,20 @@ async fn install_python(path:String) -> bool{
|
||||
Ok(o) => {
|
||||
let res = String::from_utf8(o.stdout).unwrap();
|
||||
if !res.starts_with("Python ") {
|
||||
return false
|
||||
return false;
|
||||
}
|
||||
println!("{}", res);
|
||||
return true
|
||||
},
|
||||
return true;
|
||||
}
|
||||
Err(e) => {
|
||||
println!("{}", e);
|
||||
return false
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn install_pip(path:String) -> bool{
|
||||
async fn install_pip(path: String) -> bool {
|
||||
let py_path = Path::new(&path).join("python");
|
||||
let py_exec_path = py_path.join("python.exe");
|
||||
let get_pip_url = "https://bootstrap.pypa.io/get-pip.py";
|
||||
@@ -224,13 +211,13 @@ async fn install_pip(path:String) -> bool{
|
||||
let res = String::from_utf8(o.stdout).unwrap();
|
||||
println!("{}", res);
|
||||
if !res.starts_with("Python ") {
|
||||
return false
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true
|
||||
},
|
||||
Err(e) => {
|
||||
println!("{}", e);
|
||||
return false
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -238,20 +225,20 @@ async fn install_pip(path:String) -> bool{
|
||||
use std::process::Command;
|
||||
|
||||
#[tauri::command]
|
||||
fn check_requirements_local() -> String{
|
||||
fn check_requirements_local() -> String {
|
||||
let mut py = Command::new("python");
|
||||
let output = py.arg("--version").output();
|
||||
match output {
|
||||
Ok(o) => {
|
||||
let res = String::from_utf8(o.stdout).unwrap();
|
||||
if !res.starts_with("Python ") {
|
||||
return "Python is not installed".to_string()
|
||||
return "Python is not installed".to_string();
|
||||
}
|
||||
println!("{}", res);
|
||||
},
|
||||
}
|
||||
Err(e) => {
|
||||
println!("{}", e);
|
||||
return "Python is not installed, or not loadable".to_string()
|
||||
return "Python is not installed, or not loadable".to_string();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -261,21 +248,21 @@ fn check_requirements_local() -> String{
|
||||
Ok(o) => {
|
||||
let res = String::from_utf8(o.stdout).unwrap();
|
||||
if !res.starts_with("git version ") {
|
||||
return "Git is not installed".to_string()
|
||||
return "Git is not installed".to_string();
|
||||
}
|
||||
println!("{}", res);
|
||||
},
|
||||
}
|
||||
Err(e) => {
|
||||
println!("{}", e);
|
||||
return "Git is not installed, or not loadable".to_string()
|
||||
return "Git is not installed, or not loadable".to_string();
|
||||
}
|
||||
}
|
||||
|
||||
return "success".to_string()
|
||||
return "success".to_string();
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn post_py_install(path:String){
|
||||
fn post_py_install(path: String) {
|
||||
let py_path = Path::new(&path).join("python");
|
||||
let py_pth_path = py_path.join("python311._pth");
|
||||
//uncomment python libs
|
||||
@@ -288,31 +275,38 @@ fn post_py_install(path:String){
|
||||
std::fs::write(&completed_path, "python311").unwrap();
|
||||
}
|
||||
|
||||
|
||||
#[tauri::command]
|
||||
fn install_py_dependencies(path:String, dependency:String) -> Result<(), String>{
|
||||
fn install_py_dependencies(path: String, dependency: String) -> Result<(), String> {
|
||||
println!("installing {}", dependency);
|
||||
let py_path = Path::new(&path).join("python");
|
||||
let py_exec_path = py_path.join("python.exe");
|
||||
let mut py = Command::new(py_exec_path);
|
||||
let output = py.arg("-m").arg("pip").arg("install").arg(dependency).output();
|
||||
let output = py
|
||||
.arg("-m")
|
||||
.arg("pip")
|
||||
.arg("install")
|
||||
.arg(dependency)
|
||||
.output();
|
||||
match output {
|
||||
Ok(o) => {
|
||||
let res = String::from_utf8(o.stdout).unwrap();
|
||||
println!("{}", res);
|
||||
return Ok(())
|
||||
},
|
||||
return Ok(());
|
||||
}
|
||||
Err(e) => {
|
||||
println!("{}", e);
|
||||
return Err(e.to_string())
|
||||
return Err(e.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn run_py_server(handle: tauri::AppHandle, py_path:String){
|
||||
fn run_py_server(handle: tauri::AppHandle, py_path: String) {
|
||||
let py_exec_path = Path::new(&py_path).join("python").join("python.exe");
|
||||
let server_path = handle.path_resolver().resolve_resource("src-python/run.py").expect("failed to resolve resource");
|
||||
let server_path = handle
|
||||
.path()
|
||||
.resolve("src-python/run.py", BaseDirectory::Resource)
|
||||
.expect("failed to resolve resource");
|
||||
|
||||
let mut py_server = Command::new(&py_exec_path);
|
||||
//set working directory to server path
|
||||
@@ -320,77 +314,32 @@ fn run_py_server(handle: tauri::AppHandle, py_path:String){
|
||||
|
||||
println!("server_path: {}", server_path.display());
|
||||
println!("py_exec_path: {}", py_exec_path.display());
|
||||
let mut _child = py_server.arg("-m").arg("uvicorn").arg("--port").arg("10026").arg("main:app").spawn().expect("failed to execute process");
|
||||
let mut _child = py_server
|
||||
.arg("-m")
|
||||
.arg("uvicorn")
|
||||
.arg("--port")
|
||||
.arg("10026")
|
||||
.arg("main:app")
|
||||
.spawn()
|
||||
.expect("failed to execute process");
|
||||
println!("server started");
|
||||
return
|
||||
return;
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn run_server_local(){
|
||||
let app_base_path = tauri::api::path::data_dir().unwrap().join("co.aiclient.risu");
|
||||
|
||||
//check app base path exists
|
||||
if !app_base_path.exists() {
|
||||
std::fs::create_dir_all(&app_base_path).unwrap();
|
||||
}
|
||||
|
||||
let server_path = app_base_path.clone().join("local_server");
|
||||
|
||||
//check server path exists
|
||||
if !&server_path.exists() {
|
||||
//git clone server
|
||||
let mut git = Command::new("git");
|
||||
let output = git
|
||||
.current_dir(&app_base_path.clone())
|
||||
.arg("clone")
|
||||
.arg("https://github.com/kwaroran/risu-exllama-connector.git")
|
||||
.output();
|
||||
match output {
|
||||
Ok(o) => {
|
||||
let res = String::from_utf8(o.stdout).unwrap();
|
||||
println!("output: {}", res);
|
||||
},
|
||||
Err(e) => {
|
||||
println!("{}", e);
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
println!("cloned");
|
||||
|
||||
let git_cloned_path = app_base_path.clone().join("risu-exllama-connector");
|
||||
|
||||
println!("git_cloned_path: {}", git_cloned_path.display());
|
||||
//rename folder to local_server
|
||||
std::fs::rename(git_cloned_path, server_path.clone()).unwrap();
|
||||
}
|
||||
|
||||
|
||||
//check os is windows
|
||||
if cfg!(target_os = "windows") {
|
||||
println!("windows runner");
|
||||
let command_location = &server_path.clone().join("run.cmd");
|
||||
let mut server = Command::new(command_location);
|
||||
let mut _child = server.current_dir(server_path).spawn().expect("failed to execute process");
|
||||
}
|
||||
else{
|
||||
println!("linux/mac runner");
|
||||
let command_location = &server_path.clone().join("run.sh");
|
||||
let mut server = Command::new(command_location);
|
||||
let mut _child = server.current_dir(server_path).spawn().expect("failed to execute process");
|
||||
}
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn streamed_fetch(id:String, url:String, headers: String, body: String, handle: tauri::AppHandle) -> String {
|
||||
async fn streamed_fetch(
|
||||
id: String,
|
||||
url: String,
|
||||
headers: String,
|
||||
body: String,
|
||||
app: AppHandle
|
||||
) -> String {
|
||||
//parse headers
|
||||
let headers_json: Value = match serde_json::from_str(&headers) {
|
||||
Ok(h) => h,
|
||||
Err(e) => return format!(r#"{{"success":false, body:{}}}"#, e.to_string()),
|
||||
};
|
||||
let app = handle.app_handle();
|
||||
|
||||
let mut headers = HeaderMap::new();
|
||||
if let Some(obj) = headers_json.as_object() {
|
||||
@@ -415,13 +364,23 @@ async fn streamed_fetch(id:String, url:String, headers: String, body: String, ha
|
||||
.headers(headers)
|
||||
.timeout(Duration::from_secs(240))
|
||||
.body(body)
|
||||
.send().await;
|
||||
.send()
|
||||
.await;
|
||||
|
||||
match response {
|
||||
Ok(mut resp) => {
|
||||
let headers = resp.headers();
|
||||
let header_json = header_map_to_json(headers);
|
||||
app.emit_all("streamed_fetch", &format!(r#"{{"type": "headers", "body": {}, "id": "{}", "status": {}}}"#, header_json, id, resp.status().as_u16())).unwrap();
|
||||
app.emit(
|
||||
"streamed_fetch",
|
||||
&format!(
|
||||
r#"{{"type": "headers", "body": {}, "id": "{}", "status": {}}}"#,
|
||||
header_json,
|
||||
id,
|
||||
resp.status().as_u16()
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
loop {
|
||||
let byt = resp.chunk().await;
|
||||
match byt {
|
||||
@@ -431,140 +390,68 @@ async fn streamed_fetch(id:String, url:String, headers: String, body: String, ha
|
||||
}
|
||||
let chunk = chunk.unwrap();
|
||||
let encoded = general_purpose::STANDARD.encode(chunk);
|
||||
let emited = app.emit_all("streamed_fetch", &format!(r#"{{"type": "chunk", "body": "{}", "id": "{}"}}"#, encoded, id));
|
||||
let emited = app.emit(
|
||||
"streamed_fetch",
|
||||
&format!(
|
||||
r#"{{"type": "chunk", "body": "{}", "id": "{}"}}"#,
|
||||
encoded, id
|
||||
),
|
||||
);
|
||||
|
||||
match emited {
|
||||
Ok(_) => {},
|
||||
Ok(_) => {}
|
||||
Err(e) => {
|
||||
return format!(r#"{{"success":false, body:{}}}"#, e.to_string())
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
return format!(r#"{{"success":false, body:{}}}"#, e.to_string())
|
||||
Err(e) => return format!(r#"{{"success":false, body:{}}}"#, e.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
app.emit_all("streamed_fetch", &format!(r#"{{"type": "end", "id": "{}"}}"#, id)).unwrap();
|
||||
app.emit(
|
||||
"streamed_fetch",
|
||||
&format!(r#"{{"type": "end", "id": "{}"}}"#, id),
|
||||
)
|
||||
.unwrap();
|
||||
return "{\"success\":true}".to_string();
|
||||
}
|
||||
Err(e) => {
|
||||
return format!(r#"{{"success":false, body:{}}}"#, e.to_string())
|
||||
}
|
||||
Err(e) => return format!(r#"{{"success":false, body:{}}}"#, e.to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn get_http_secret(secret_state: State<HttpSecret>) -> String {
|
||||
secret_state.0.lock().unwrap().clone()
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn get_http_port(port_state: State<HttpPort>) -> u16 {
|
||||
port_state.0.lock().unwrap().clone()
|
||||
}
|
||||
|
||||
#[post("/")]
|
||||
async fn write_binary_file_to_appdata(req: HttpRequest, body: web::Bytes, app_handle: web::Data<tauri::AppHandle>, secret: web::Data<String>) -> impl Responder {
|
||||
let query = req.query_string();
|
||||
let headers = req.headers();
|
||||
let req_secret = headers.get("x-tauri-secret").unwrap().to_str().unwrap();
|
||||
if req_secret != *secret.as_ref() {
|
||||
return HttpResponse::Unauthorized().body("Unauthorized");
|
||||
}
|
||||
let params: std::collections::HashMap<_, _> = url::form_urlencoded::parse(query.as_bytes()).into_owned().collect();
|
||||
let app_data_dir = app_data_dir(&app_handle.config()).expect("App dir must be returned by tauri");
|
||||
if let Some(file_path) = params.get("path") {
|
||||
let full_path = app_data_dir.join(file_path);
|
||||
if let Some(parent) = Path::new(&full_path).parent() {
|
||||
if let Err(e) = std::fs::create_dir_all(parent) {
|
||||
return HttpResponse::InternalServerError().body(format!("Failed to create directories: {}", e));
|
||||
}
|
||||
}
|
||||
|
||||
match File::create(&full_path) {
|
||||
Ok(mut file) => {
|
||||
if let Err(e) = file.write_all(&body) {
|
||||
return HttpResponse::InternalServerError().body(format!("Failed to write to file: {}", e));
|
||||
}
|
||||
HttpResponse::Ok().body("File written successfully")
|
||||
}
|
||||
Err(e) => HttpResponse::InternalServerError().body(format!("Failed to create file: {}", e)),
|
||||
}
|
||||
} else {
|
||||
HttpResponse::BadRequest().body("Missing file path in query string")
|
||||
}
|
||||
}
|
||||
|
||||
async fn run_http_server(handle: tauri::AppHandle, secret: String) {
|
||||
for port in 5354..65535 {
|
||||
let handle_copy = handle.clone();
|
||||
let secret_copy = secret.clone();
|
||||
let res = HttpServer::new(move || {
|
||||
App::new()
|
||||
.wrap(
|
||||
Cors::default()
|
||||
.allow_any_origin()
|
||||
.allow_any_method()
|
||||
.allow_any_header()
|
||||
.max_age(3600)
|
||||
)
|
||||
.app_data(web::PayloadConfig::new(1024 * 1024 * 1024)) // 1 GB
|
||||
.app_data(web::Data::new(handle_copy.clone()))
|
||||
.app_data(web::Data::new(secret_copy.clone()))
|
||||
.service(write_binary_file_to_appdata)
|
||||
})
|
||||
.bind(("127.0.0.1", port));
|
||||
match res {
|
||||
Ok(server) => {
|
||||
handle.manage(HttpPort(Mutex::new(port)));
|
||||
let _ = server.run().await;
|
||||
break;
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Failed to bind to port {}: {}", port, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
tauri::Builder::default()
|
||||
.manage(HttpSecret(uuid::Uuid::new_v4().to_string().into()))
|
||||
.plugin(tauri_plugin_http::init())
|
||||
.plugin(tauri_plugin_shell::init())
|
||||
.plugin(tauri_plugin_process::init())
|
||||
.plugin(tauri_plugin_updater::Builder::new().build())
|
||||
.plugin(tauri_plugin_dialog::init())
|
||||
.plugin(tauri_plugin_os::init())
|
||||
.plugin(tauri_plugin_fs::init())
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
greet,
|
||||
native_request,
|
||||
check_auth,
|
||||
check_requirements_local,
|
||||
run_server_local,
|
||||
install_python,
|
||||
install_pip,
|
||||
post_py_install,
|
||||
run_py_server,
|
||||
install_py_dependencies,
|
||||
streamed_fetch,
|
||||
get_http_secret,
|
||||
get_http_port
|
||||
])
|
||||
.setup(|app| {
|
||||
let handle = app.handle().clone();
|
||||
let secret_state: State<HttpSecret> = app.state();
|
||||
let secret = secret_state.0.lock().unwrap().clone();
|
||||
std::thread::spawn(move || {
|
||||
let rt = actix_rt::Runtime::new().unwrap();
|
||||
rt.block_on(run_http_server(handle.clone(), secret.clone()));
|
||||
});
|
||||
Ok(())
|
||||
})
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
|
||||
|
||||
fn header_map_to_json(header_map: &HeaderMap) -> serde_json::Value {
|
||||
let mut map = HashMap::new();
|
||||
for (key, value) in header_map {
|
||||
map.insert(key.as_str().to_string(), value.to_str().unwrap().to_string());
|
||||
map.insert(
|
||||
key.as_str().to_string(),
|
||||
value.to_str().unwrap().to_string(),
|
||||
);
|
||||
}
|
||||
json!(map)
|
||||
}
|
||||
|
||||
5
src-tauri/src/mainx.txt
Normal file
5
src-tauri/src/mainx.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
fn main() {
|
||||
alib::run();
|
||||
}
|
||||
@@ -2,80 +2,8 @@
|
||||
"build": {
|
||||
"beforeDevCommand": "pnpm dev",
|
||||
"beforeBuildCommand": "pnpm build",
|
||||
"devPath": "http://localhost:5174",
|
||||
"distDir": "../dist",
|
||||
"withGlobalTauri": false
|
||||
},
|
||||
"package": {
|
||||
"productName": "RisuAI",
|
||||
"version": "135.0.0"
|
||||
},
|
||||
"tauri": {
|
||||
"allowlist": {
|
||||
"app": {
|
||||
"all": true
|
||||
},
|
||||
"process": {
|
||||
"relaunch": true
|
||||
},
|
||||
"protocol": {
|
||||
"all": true,
|
||||
"assetScope": ["asset","$APPDATA","$APPDATA/*","$APPDATA/**/*", "/data/**/*"]
|
||||
},
|
||||
"all": false,
|
||||
"shell": {
|
||||
"all": false,
|
||||
"open": true
|
||||
},
|
||||
"fs":{
|
||||
"all": true,
|
||||
"scope": ["$APPDATA","$APPDATA/*","$APPDATA/**/*", "$DOWNLOAD/*", "/data/**/*", "$RESOURCE/*"]
|
||||
},
|
||||
"path":{
|
||||
"all": true
|
||||
},
|
||||
"http": {
|
||||
"all": true,
|
||||
"request": true,
|
||||
"scope": ["https://*/*", "https://*/**/*","http://*/*", "http://*/**/*"]
|
||||
},
|
||||
"window": {
|
||||
"center": false,
|
||||
"close": false,
|
||||
"create": false,
|
||||
"hide": false,
|
||||
"maximize": true,
|
||||
"minimize": false,
|
||||
"print": false,
|
||||
"requestUserAttention": false,
|
||||
"setAlwaysOnTop": false,
|
||||
"setCursorGrab": false,
|
||||
"setCursorIcon": false,
|
||||
"setCursorPosition": false,
|
||||
"setCursorVisible": false,
|
||||
"setDecorations": false,
|
||||
"setFocus": false,
|
||||
"setFullscreen": true,
|
||||
"setIcon": false,
|
||||
"setIgnoreCursorEvents": false,
|
||||
"setMaxSize": false,
|
||||
"setMinSize": false,
|
||||
"setPosition": false,
|
||||
"setResizable": false,
|
||||
"setSize": false,
|
||||
"setSkipTaskbar": false,
|
||||
"setTitle": false,
|
||||
"show": false,
|
||||
"startDragging": false,
|
||||
"unmaximize": false,
|
||||
"unminimize": false
|
||||
},
|
||||
"dialog": {
|
||||
"all": true
|
||||
},
|
||||
"os": {
|
||||
"all": true
|
||||
}
|
||||
"frontendDist": "../dist",
|
||||
"devUrl": "http://localhost:5174"
|
||||
},
|
||||
"bundle": {
|
||||
"active": true,
|
||||
@@ -86,24 +14,29 @@
|
||||
"icons/icon.icns",
|
||||
"icons/icon.ico"
|
||||
],
|
||||
"identifier": "co.aiclient.risu",
|
||||
"targets": "all",
|
||||
"resources": [
|
||||
"src-python/*"
|
||||
]
|
||||
},
|
||||
"security": {
|
||||
"csp": null
|
||||
],
|
||||
"targets": "all",
|
||||
"createUpdaterArtifacts": "v1Compatible"
|
||||
},
|
||||
"productName": "RisuAI",
|
||||
"mainBinaryName": "RisuAI",
|
||||
"version": "135.0.0",
|
||||
"identifier": "co.aiclient.risu",
|
||||
"plugins": {
|
||||
"updater": {
|
||||
"active": true,
|
||||
"endpoints": ["https://github.com/kwaroran/RisuAI/releases/latest/download/latest.json"],
|
||||
"dialog": false,
|
||||
"pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IDU2ODMzOTIxMDMxOTY1MUYKUldRZlpSa0RJVG1EVmx5Vm1WYlhFM29HMEJrUTRrYmg5dDQ0RFpvdUphNDdxQmVlWXJHVmV5TEYK",
|
||||
"endpoints": [
|
||||
"https://github.com/kwaroran/RisuAI/releases/latest/download/latest.json"
|
||||
],
|
||||
"windows": {
|
||||
"installMode": "passive"
|
||||
}
|
||||
}
|
||||
},
|
||||
"app": {
|
||||
"withGlobalTauri": false,
|
||||
"windows": [
|
||||
{
|
||||
"fullscreen": false,
|
||||
@@ -113,8 +46,21 @@
|
||||
"height": 768,
|
||||
"minWidth": 300,
|
||||
"minHeight": 500,
|
||||
"fileDropEnabled": false
|
||||
"dragDropEnabled": false
|
||||
}
|
||||
],
|
||||
"security": {
|
||||
"assetProtocol": {
|
||||
"scope": [
|
||||
"asset",
|
||||
"$APPDATA",
|
||||
"$APPDATA/*",
|
||||
"$APPDATA/**/*",
|
||||
"/data/**/*"
|
||||
],
|
||||
"enable": true
|
||||
},
|
||||
"csp": null
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
import Help from "../Others/Help.svelte";
|
||||
import CheckInput from "./GUI/CheckInput.svelte";
|
||||
import { isTauri } from "src/ts/storage/globalApi";
|
||||
import {open} from '@tauri-apps/api/dialog'
|
||||
import {open} from '@tauri-apps/plugin-dialog'
|
||||
import { getModelName } from "src/ts/model/names";
|
||||
|
||||
export let value = ""
|
||||
|
||||
@@ -4,7 +4,7 @@ export function preLoadCheck(){
|
||||
const searchParams = new URLSearchParams(location.search);
|
||||
|
||||
//@ts-ignore
|
||||
const isTauri = !!window.__TAURI__
|
||||
const isTauri = !!window.__TAURI_INTERNALS__
|
||||
//@ts-ignore
|
||||
const isNodeServer = !!globalThis.__NODE__
|
||||
const isCapacitor = Capacitor.isNativePlatform();
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { BaseDirectory, readBinaryFile, readDir, writeBinaryFile } from "@tauri-apps/api/fs";
|
||||
import { BaseDirectory, readFile, readDir, writeFile } from "@tauri-apps/plugin-fs";
|
||||
import { alertError, alertNormal, alertStore, alertWait } from "../alert";
|
||||
import { LocalWriter, forageStorage, isTauri } from "../storage/globalApi";
|
||||
import { decodeRisuSave, encodeRisuSave } from "../storage/risuSave";
|
||||
import { get } from "svelte/store";
|
||||
import { DataBase } from "../storage/database";
|
||||
import { save } from "@tauri-apps/api/dialog";
|
||||
import { relaunch } from "@tauri-apps/api/process";
|
||||
import { save } from "@tauri-apps/plugin-dialog";
|
||||
import { relaunch } from "@tauri-apps/plugin-process";
|
||||
import { sleep } from "../util";
|
||||
import { hubURL } from "../characterCards";
|
||||
|
||||
@@ -41,7 +41,7 @@ export async function SaveLocalBackup(){
|
||||
|
||||
|
||||
if(isTauri){
|
||||
const assets = await readDir('assets', {dir: BaseDirectory.AppData})
|
||||
const assets = await readDir('assets', {baseDir: BaseDirectory.AppData})
|
||||
let i = 0;
|
||||
for(let asset of assets){
|
||||
i += 1;
|
||||
@@ -50,7 +50,7 @@ export async function SaveLocalBackup(){
|
||||
if(!key || !key.endsWith('.png')){
|
||||
continue
|
||||
}
|
||||
await writer.writeBackup(key, await readBinaryFile(asset.path))
|
||||
await writer.writeBackup(key, await readFile(asset.name, {baseDir: BaseDirectory.AppData}))
|
||||
}
|
||||
}
|
||||
else{
|
||||
@@ -63,7 +63,7 @@ export async function SaveLocalBackup(){
|
||||
if(!key || !key.endsWith('.png')){
|
||||
continue
|
||||
}
|
||||
await writer.writeBackup(key, await forageStorage.getItem(key))
|
||||
await writer.writeBackup(key, await forageStorage.getItem(key) as unknown as Uint8Array)
|
||||
if(forageStorage.isAccount){
|
||||
await sleep(1000)
|
||||
}
|
||||
@@ -115,7 +115,7 @@ export async function LoadLocalBackup(){
|
||||
const dbData = await decodeRisuSave(db)
|
||||
DataBase.set(dbData)
|
||||
if(isTauri){
|
||||
await writeBinaryFile('database/database.bin', db, {dir: BaseDirectory.AppData})
|
||||
await writeFile('database/database.bin', db, {baseDir: BaseDirectory.AppData})
|
||||
relaunch()
|
||||
alertStore.set({
|
||||
type: "wait",
|
||||
@@ -133,7 +133,7 @@ export async function LoadLocalBackup(){
|
||||
continue
|
||||
}
|
||||
if(isTauri){
|
||||
await writeBinaryFile(`assets/` + name, data ,{dir: BaseDirectory.AppData})
|
||||
await writeFile(`assets/` + name, data ,{baseDir: BaseDirectory.AppData})
|
||||
}
|
||||
else{
|
||||
await forageStorage.setItem('assets/' + name, data)
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { get } from "svelte/store";
|
||||
import { alertError, alertErrorWait, alertInput, alertNormal, alertSelect, alertStore } from "../alert";
|
||||
import { DataBase, setDatabase, type Database } from "../storage/database";
|
||||
import { forageStorage, getUnpargeables, isNodeServer, isTauri, openURL } from "../storage/globalApi";
|
||||
import { BaseDirectory, exists, readBinaryFile, readDir, writeBinaryFile } from "@tauri-apps/api/fs";
|
||||
import { alertError, alertInput, alertNormal, alertSelect, alertStore } from "../alert";
|
||||
import { DataBase, type Database } from "../storage/database";
|
||||
import { forageStorage, getUnpargeables, isTauri, openURL } from "../storage/globalApi";
|
||||
import { BaseDirectory, exists, readFile, readDir, writeFile } from "@tauri-apps/plugin-fs";
|
||||
import { language } from "../../lang";
|
||||
import { relaunch } from '@tauri-apps/api/process';
|
||||
import { relaunch } from '@tauri-apps/plugin-process';
|
||||
import { isEqual } from "lodash";
|
||||
import { sleep } from "../util";
|
||||
import { hubURL } from "../characterCards";
|
||||
@@ -112,89 +112,6 @@ let BackupDb:Database = null
|
||||
export async function syncDrive() {
|
||||
BackupDb = structuredClone(get(DataBase))
|
||||
return
|
||||
while(true){
|
||||
const maindb = get(DataBase)
|
||||
if(maindb?.account?.data?.access_token && maindb?.account?.data?.refresh_token && maindb?.account?.data?.expires_in){
|
||||
if(maindb.account.data.expires_in < Date.now()){
|
||||
if(!maindb.account){
|
||||
alertError("Not logged in error")
|
||||
return
|
||||
}
|
||||
const s = await fetch(hubURL + '/drive/refresh', {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
token: maindb.account.token
|
||||
})
|
||||
})
|
||||
if(s.status !== 200){
|
||||
alertError(await s.text())
|
||||
return
|
||||
}
|
||||
maindb.account.data = await s.json()
|
||||
}
|
||||
const ACCESS_TOKEN = maindb.account.data.access_token
|
||||
const d = await loadDrive(ACCESS_TOKEN, 'sync')
|
||||
lastSaved = Math.floor(Date.now() / 1000)
|
||||
localStorage.setItem('risu_lastsaved', `${lastSaved}`)
|
||||
const hadNoSync = d === 'noSync'
|
||||
if((!isEqual(maindb, BackupDb)) || hadNoSync){
|
||||
BackupDb = structuredClone(maindb)
|
||||
const files:DriveFile[] = await getFilesInFolder(ACCESS_TOKEN)
|
||||
const fileNames = files.map((d) => {
|
||||
return d.name
|
||||
})
|
||||
if(isTauri){
|
||||
const assets = await readDir('assets', {dir: BaseDirectory.AppData})
|
||||
let i = 0;
|
||||
for(let asset of assets){
|
||||
i += 1;
|
||||
if(hadNoSync){
|
||||
alertStore.set({
|
||||
type: "wait",
|
||||
msg: `Uploading Sync Files... (${i} / ${assets.length})`
|
||||
})
|
||||
}
|
||||
const key = asset.name
|
||||
if(!key || !key.endsWith('.png')){
|
||||
continue
|
||||
}
|
||||
const formatedKey = formatKeys(key)
|
||||
if(!fileNames.includes(formatedKey)){
|
||||
await createFileInFolder(ACCESS_TOKEN, formatedKey, await readBinaryFile(asset.path))
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
const keys = await forageStorage.keys()
|
||||
|
||||
for(let i=0;i<keys.length;i++){
|
||||
if(hadNoSync){
|
||||
alertStore.set({
|
||||
type: "wait",
|
||||
msg: `Uploading Sync Files... (${i} / ${keys.length})`
|
||||
})
|
||||
}
|
||||
const key = keys[i]
|
||||
if(!key.endsWith('.png')){
|
||||
continue
|
||||
}
|
||||
const formatedKey = formatKeys(key)
|
||||
if(!fileNames.includes(formatedKey)){
|
||||
await createFileInFolder(ACCESS_TOKEN, formatedKey, await forageStorage.getItem(key))
|
||||
}
|
||||
}
|
||||
}
|
||||
const dbjson = JSON.stringify(get(DataBase))
|
||||
lastSaved = Math.floor(Date.now() / 1000)
|
||||
localStorage.setItem('risu_lastsaved', `${lastSaved}`)
|
||||
await createFileInFolder(ACCESS_TOKEN, `${lastSaved}-database.risudat2`, Buffer.from(dbjson, 'utf-8'))
|
||||
if(hadNoSync){
|
||||
alertNormal("First Setup Success")
|
||||
}
|
||||
}
|
||||
}
|
||||
await sleep(3000)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -224,7 +141,7 @@ async function backupDrive(ACCESS_TOKEN:string) {
|
||||
})
|
||||
|
||||
if(isTauri){
|
||||
const assets = await readDir('assets', {dir: BaseDirectory.AppData})
|
||||
const assets = await readDir('assets', {baseDir: BaseDirectory.AppData})
|
||||
let i = 0;
|
||||
for(let asset of assets){
|
||||
i += 1;
|
||||
@@ -238,7 +155,7 @@ async function backupDrive(ACCESS_TOKEN:string) {
|
||||
}
|
||||
const formatedKey = newFormatKeys(key)
|
||||
if(!fileNames.includes(formatedKey)){
|
||||
await createFileInFolder(ACCESS_TOKEN, formatedKey, await readBinaryFile(asset.path))
|
||||
await createFileInFolder(ACCESS_TOKEN, formatedKey, await readFile(asset.name, {baseDir: BaseDirectory.AppData}))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -256,7 +173,7 @@ async function backupDrive(ACCESS_TOKEN:string) {
|
||||
}
|
||||
const formatedKey = newFormatKeys(key)
|
||||
if(!fileNames.includes(formatedKey)){
|
||||
await createFileInFolder(ACCESS_TOKEN, formatedKey, await forageStorage.getItem(key))
|
||||
await createFileInFolder(ACCESS_TOKEN, formatedKey, await forageStorage.getItem(key) as unknown as Uint8Array)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -297,7 +214,7 @@ async function loadDrive(ACCESS_TOKEN:string, mode: 'backup'|'sync'):Promise<voi
|
||||
return false
|
||||
}
|
||||
if(isTauri){
|
||||
return await exists(`assets/` + images, {dir: BaseDirectory.AppData})
|
||||
return await exists(`assets/` + images, {baseDir: BaseDirectory.AppData})
|
||||
}
|
||||
else{
|
||||
if(!loadedForageKeys){
|
||||
@@ -408,7 +325,7 @@ async function loadDrive(ACCESS_TOKEN:string, mode: 'backup'|'sync'):Promise<voi
|
||||
if(file.name === formatedImage){
|
||||
const fData = await getFileData(ACCESS_TOKEN, file.id)
|
||||
if(isTauri){
|
||||
await writeBinaryFile(`assets/` + images, fData ,{dir: BaseDirectory.AppData})
|
||||
await writeFile(`assets/` + images, fData ,{baseDir: BaseDirectory.AppData})
|
||||
|
||||
}
|
||||
else{
|
||||
@@ -433,7 +350,7 @@ async function loadDrive(ACCESS_TOKEN:string, mode: 'backup'|'sync'):Promise<voi
|
||||
const dbData = encodeRisuSave(db, 'compression')
|
||||
|
||||
if(isTauri){
|
||||
await writeBinaryFile('database/database.bin', dbData, {dir: BaseDirectory.AppData})
|
||||
await writeFile('database/database.bin', dbData, {baseDir: BaseDirectory.AppData})
|
||||
relaunch()
|
||||
alertStore.set({
|
||||
type: "wait",
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import { invoke } from "@tauri-apps/api/tauri";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { globalFetch } from "src/ts/storage/globalApi";
|
||||
import { sleep } from "src/ts/util";
|
||||
import * as path from "@tauri-apps/api/path";
|
||||
import { exists, readTextFile } from "@tauri-apps/api/fs";
|
||||
import { exists, readTextFile } from "@tauri-apps/plugin-fs";
|
||||
import { alertClear, alertError, alertMd, alertWait } from "src/ts/alert";
|
||||
import { get } from "svelte/store";
|
||||
import { DataBase } from "src/ts/storage/database";
|
||||
import { resolveResource } from '@tauri-apps/api/path'
|
||||
let serverRunning = false;
|
||||
|
||||
export function checkLocalModel():Promise<string>{
|
||||
|
||||
@@ -664,7 +664,7 @@ export async function requestChatDataMain(arg:requestDataArgument, model:'model'
|
||||
url: replacerURL,
|
||||
})
|
||||
|
||||
let dataUint = new Uint8Array([])
|
||||
let dataUint:Uint8Array|Buffer = new Uint8Array([])
|
||||
|
||||
const transtream = new TransformStream<Uint8Array, StreamResponseChunk>( {
|
||||
async transform(chunk, control) {
|
||||
@@ -1240,7 +1240,7 @@ export async function requestChatDataMain(arg:requestDataArgument, model:'model'
|
||||
const API_ENDPOINT="us-central1-aiplatform.googleapis.com"
|
||||
const PROJECT_ID=db.google.projectId
|
||||
const MODEL_ID= aiModel === 'palm2' ? 'text-bison' :
|
||||
'palm2_unicorn' ? 'text-unicorn' :
|
||||
aiModel ==='palm2_unicorn' ? 'text-unicorn' :
|
||||
''
|
||||
const LOCATION_ID="us-central1"
|
||||
|
||||
|
||||
@@ -1,16 +1,22 @@
|
||||
import { writeBinaryFile,BaseDirectory, readBinaryFile, exists, createDir, readDir, removeFile } from "@tauri-apps/api/fs"
|
||||
|
||||
import {
|
||||
writeFile,
|
||||
BaseDirectory,
|
||||
readFile,
|
||||
exists,
|
||||
mkdir,
|
||||
readDir,
|
||||
remove
|
||||
} from "@tauri-apps/plugin-fs"
|
||||
import { changeFullscreen, checkNullish, findCharacterbyId, sleep } from "../util"
|
||||
import { convertFileSrc, invoke } from "@tauri-apps/api/tauri"
|
||||
import { convertFileSrc, invoke } from "@tauri-apps/api/core"
|
||||
import { v4 as uuidv4, v4 } from 'uuid';
|
||||
import { appDataDir, join } from "@tauri-apps/api/path";
|
||||
import { get } from "svelte/store";
|
||||
import {open} from '@tauri-apps/api/shell'
|
||||
import {open} from '@tauri-apps/plugin-shell'
|
||||
import { DataBase, loadedStore, setDatabase, type Database, defaultSdDataFunc } from "./database";
|
||||
import { appWindow } from "@tauri-apps/api/window";
|
||||
import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow";
|
||||
import { checkRisuUpdate } from "../update";
|
||||
import { MobileGUI, botMakerMode, selectedCharID } from "../stores";
|
||||
import { Body, ResponseType, fetch as TauriFetch } from "@tauri-apps/api/http";
|
||||
import { loadPlugins } from "../plugins/plugins";
|
||||
import { alertConfirm, alertError, alertNormal, alertNormalWait, alertSelect, alertTOS, alertWait } from "../alert";
|
||||
import { checkDriverInit, syncDrive } from "../drive/drive";
|
||||
@@ -25,7 +31,7 @@ import { updateColorScheme, updateTextThemeAndCSS } from "../gui/colorscheme";
|
||||
import { saveDbKei } from "../kei/backup";
|
||||
import { Capacitor, CapacitorHttp } from '@capacitor/core';
|
||||
import * as CapFS from '@capacitor/filesystem'
|
||||
import { save } from "@tauri-apps/api/dialog";
|
||||
import { save } from "@tauri-apps/plugin-dialog";
|
||||
import type { RisuModule } from "../process/modules";
|
||||
import { listen } from '@tauri-apps/api/event'
|
||||
import { registerPlugin } from '@capacitor/core';
|
||||
@@ -36,9 +42,11 @@ import { updateGuisize } from "../gui/guisize";
|
||||
import { encodeCapKeySafe } from "./mobileStorage";
|
||||
import { updateLorebooks } from "../characters";
|
||||
import { initMobileGesture } from "../hotkey";
|
||||
import { fetch as TauriHTTPFetch } from '@tauri-apps/plugin-http';
|
||||
const appWindow = getCurrentWebviewWindow()
|
||||
|
||||
//@ts-ignore
|
||||
export const isTauri = !!window.__TAURI__
|
||||
export const isTauri = !!window.__TAURI_INTERNALS__
|
||||
//@ts-ignore
|
||||
export const isNodeServer = !!globalThis.__NODE__
|
||||
export const forageStorage = new AutoStorage()
|
||||
@@ -58,26 +66,6 @@ interface fetchLog{
|
||||
|
||||
let fetchLog:fetchLog[] = []
|
||||
|
||||
async function writeBinaryFileFast(appPath: string, data: Uint8Array) {
|
||||
const secret = await invoke('get_http_secret') as string;
|
||||
const port = await invoke('get_http_port') as number;
|
||||
|
||||
const apiUrl = `http://127.0.0.1:${port}/?path=${encodeURIComponent(appPath)}`;
|
||||
|
||||
const response = await fetch(apiUrl, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/octet-stream',
|
||||
'x-tauri-secret': secret
|
||||
},
|
||||
body: new Blob([data])
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
}
|
||||
|
||||
export async function downloadFile(name:string, dat:Uint8Array|ArrayBuffer|string) {
|
||||
if(typeof(dat) === 'string'){
|
||||
dat = Buffer.from(dat, 'utf-8')
|
||||
@@ -94,7 +82,7 @@ export async function downloadFile(name:string, dat:Uint8Array|ArrayBuffer|strin
|
||||
}
|
||||
|
||||
if(isTauri){
|
||||
await writeBinaryFile(name, data, {dir: BaseDirectory.Download})
|
||||
await writeFile(name, data, {baseDir: BaseDirectory.Download})
|
||||
}
|
||||
else{
|
||||
downloadURL(`data:png/image;base64,${Buffer.from(data).toString('base64')}`, name)
|
||||
@@ -172,7 +160,7 @@ export async function getFileSrc(loc:string) {
|
||||
return "/sw/img/" + encoded
|
||||
}
|
||||
else{
|
||||
const f:Uint8Array = await forageStorage.getItem(loc)
|
||||
const f:Uint8Array = await forageStorage.getItem(loc) as unknown as Uint8Array
|
||||
await fetch("/sw/register/" + encoded, {
|
||||
method: "POST",
|
||||
body: f
|
||||
@@ -201,7 +189,7 @@ export async function getFileSrc(loc:string) {
|
||||
ind = fileCache.origin.length
|
||||
fileCache.origin.push(loc)
|
||||
fileCache.res.push('loading')
|
||||
const f:Uint8Array = await forageStorage.getItem(loc)
|
||||
const f:Uint8Array = await forageStorage.getItem(loc) as unknown as Uint8Array
|
||||
fileCache.res[ind] = f
|
||||
return `data:image/png;base64,${Buffer.from(f).toString('base64')}`
|
||||
}
|
||||
@@ -230,12 +218,12 @@ export async function readImage(data:string) {
|
||||
if(appDataDirPath === ''){
|
||||
appDataDirPath = await appDataDir();
|
||||
}
|
||||
return await readBinaryFile(await join(appDataDirPath,data))
|
||||
return await readFile(await join(appDataDirPath,data))
|
||||
}
|
||||
return await readBinaryFile(data)
|
||||
return await readFile(data)
|
||||
}
|
||||
else{
|
||||
return (await forageStorage.getItem(data) as Uint8Array)
|
||||
return (await forageStorage.getItem(data) as unknown as Uint8Array)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,7 +244,9 @@ export async function saveAsset(data:Uint8Array, customId:string = '', fileName:
|
||||
fileExtension = fileName.split('.').pop()
|
||||
}
|
||||
if(isTauri){
|
||||
await writeBinaryFileFast(`assets/${id}.${fileExtension}`, data);
|
||||
await writeFile(`assets/${id}.${fileExtension}`, data, {
|
||||
baseDir: BaseDirectory.AppData
|
||||
});
|
||||
return `assets/${id}.${fileExtension}`
|
||||
}
|
||||
else{
|
||||
@@ -271,10 +261,10 @@ export async function saveAsset(data:Uint8Array, customId:string = '', fileName:
|
||||
|
||||
export async function loadAsset(id:string){
|
||||
if(isTauri){
|
||||
return await readBinaryFile(id,{dir: BaseDirectory.AppData})
|
||||
return await readFile(id,{baseDir: BaseDirectory.AppData})
|
||||
}
|
||||
else{
|
||||
return await forageStorage.getItem(id) as Uint8Array
|
||||
return await forageStorage.getItem(id) as unknown as Uint8Array
|
||||
}
|
||||
}
|
||||
|
||||
@@ -322,8 +312,8 @@ export async function saveDb(){
|
||||
db.saveTime = Math.floor(Date.now() / 1000)
|
||||
if(isTauri){
|
||||
const dbData = encodeRisuSave(db)
|
||||
await writeBinaryFileFast('database/database.bin', dbData);
|
||||
await writeBinaryFileFast(`database/dbbackup-${(Date.now()/100).toFixed()}.bin`, dbData);
|
||||
await writeFile('database/database.bin', dbData, {baseDir: BaseDirectory.AppData});
|
||||
await writeFile(`database/dbbackup-${(Date.now()/100).toFixed()}.bin`, dbData, {baseDir: BaseDirectory.AppData});
|
||||
}
|
||||
else{
|
||||
if(!forageStorage.isAccount){
|
||||
@@ -365,7 +355,7 @@ async function getDbBackups() {
|
||||
return []
|
||||
}
|
||||
if(isTauri){
|
||||
const keys = await readDir('database', {dir: BaseDirectory.AppData})
|
||||
const keys = await readDir('database', {baseDir: BaseDirectory.AppData})
|
||||
let backups:number[] = []
|
||||
for(const key of keys){
|
||||
if(key.name.startsWith("dbbackup-")){
|
||||
@@ -377,7 +367,7 @@ async function getDbBackups() {
|
||||
backups.sort((a, b) => b - a)
|
||||
while(backups.length > 20){
|
||||
const last = backups.pop()
|
||||
await removeFile(`database/dbbackup-${last}.bin`,{dir: BaseDirectory.AppData})
|
||||
await remove(`database/dbbackup-${last}.bin`,{baseDir: BaseDirectory.AppData})
|
||||
}
|
||||
return backups
|
||||
}
|
||||
@@ -407,27 +397,27 @@ export async function loadData() {
|
||||
try {
|
||||
if(isTauri){
|
||||
appWindow.maximize()
|
||||
if(!await exists('', {dir: BaseDirectory.AppData})){
|
||||
await createDir('', {dir: BaseDirectory.AppData})
|
||||
if(!await exists('', {baseDir: BaseDirectory.AppData})){
|
||||
await mkdir('', {baseDir: BaseDirectory.AppData})
|
||||
}
|
||||
if(!await exists('database', {dir: BaseDirectory.AppData})){
|
||||
await createDir('database', {dir: BaseDirectory.AppData})
|
||||
if(!await exists('database', {baseDir: BaseDirectory.AppData})){
|
||||
await mkdir('database', {baseDir: BaseDirectory.AppData})
|
||||
}
|
||||
if(!await exists('assets', {dir: BaseDirectory.AppData})){
|
||||
await createDir('assets', {dir: BaseDirectory.AppData})
|
||||
if(!await exists('assets', {baseDir: BaseDirectory.AppData})){
|
||||
await mkdir('assets', {baseDir: BaseDirectory.AppData})
|
||||
}
|
||||
if(!await exists('database/database.bin', {dir: BaseDirectory.AppData})){
|
||||
await writeBinaryFileFast('database/database.bin', encodeRisuSave({}));
|
||||
if(!await exists('database/database.bin', {baseDir: BaseDirectory.AppData})){
|
||||
await writeFile('database/database.bin', encodeRisuSave({}), {baseDir: BaseDirectory.AppData});
|
||||
}
|
||||
try {
|
||||
const decoded = decodeRisuSave(await readBinaryFile('database/database.bin',{dir: BaseDirectory.AppData}))
|
||||
const decoded = decodeRisuSave(await readFile('database/database.bin',{baseDir: BaseDirectory.AppData}))
|
||||
setDatabase(decoded)
|
||||
} catch (error) {
|
||||
const backups = await getDbBackups()
|
||||
let backupLoaded = false
|
||||
for(const backup of backups){
|
||||
try {
|
||||
const backupData = await readBinaryFile(`database/dbbackup-${backup}.bin`,{dir: BaseDirectory.AppData})
|
||||
const backupData = await readFile(`database/dbbackup-${backup}.bin`,{baseDir: BaseDirectory.AppData})
|
||||
setDatabase(
|
||||
decodeRisuSave(backupData)
|
||||
)
|
||||
@@ -445,7 +435,7 @@ export async function loadData() {
|
||||
|
||||
}
|
||||
else{
|
||||
let gotStorage:Uint8Array = await forageStorage.getItem('database/database.bin')
|
||||
let gotStorage:Uint8Array = await forageStorage.getItem('database/database.bin') as unknown as Uint8Array
|
||||
if(checkNullish(gotStorage)){
|
||||
gotStorage = encodeRisuSave({})
|
||||
await forageStorage.setItem('database/database.bin', gotStorage)
|
||||
@@ -460,7 +450,7 @@ export async function loadData() {
|
||||
let backupLoaded = false
|
||||
for(const backup of backups){
|
||||
try {
|
||||
const backupData:Uint8Array = await forageStorage.getItem(`database/dbbackup-${backup}.bin`)
|
||||
const backupData:Uint8Array = await forageStorage.getItem(`database/dbbackup-${backup}.bin`) as unknown as Uint8Array
|
||||
setDatabase(
|
||||
decodeRisuSave(backupData)
|
||||
)
|
||||
@@ -472,7 +462,7 @@ export async function loadData() {
|
||||
}
|
||||
}
|
||||
if(await forageStorage.checkAccountSync()){
|
||||
let gotStorage:Uint8Array = await forageStorage.getItem('database/database.bin')
|
||||
let gotStorage:Uint8Array = await forageStorage.getItem('database/database.bin') as unknown as Uint8Array
|
||||
if(checkNullish(gotStorage)){
|
||||
gotStorage = encodeRisuSave({})
|
||||
await forageStorage.setItem('database/database.bin', gotStorage)
|
||||
@@ -486,7 +476,7 @@ export async function loadData() {
|
||||
let backupLoaded = false
|
||||
for(const backup of backups){
|
||||
try {
|
||||
const backupData:Uint8Array = await forageStorage.getItem(`database/dbbackup-${backup}.bin`)
|
||||
const backupData:Uint8Array = await forageStorage.getItem(`database/dbbackup-${backup}.bin`) as unknown as Uint8Array
|
||||
setDatabase(
|
||||
decodeRisuSave(backupData)
|
||||
)
|
||||
@@ -711,32 +701,16 @@ async function fetchWithPlainFetch(url: string, arg: GlobalFetchArgs): Promise<G
|
||||
|
||||
// Decoupled globalFetch built-in function
|
||||
async function fetchWithTauri(url: string, arg: GlobalFetchArgs): Promise<GlobalFetchResult> {
|
||||
const body = !arg.body ? null : arg.body instanceof URLSearchParams ? Body.text(arg.body.toString()) : Body.json(arg.body);
|
||||
const headers = arg.headers ?? {};
|
||||
const fetchPromise = TauriFetch(url, {
|
||||
body,
|
||||
method: arg.method ?? 'POST',
|
||||
headers,
|
||||
timeout: { secs: get(DataBase).timeOut, nanos: 0 },
|
||||
responseType: arg.rawResponse ? ResponseType.Binary : ResponseType.JSON,
|
||||
});
|
||||
try {
|
||||
const headers = { 'Content-Type': 'application/json', ...arg.headers };
|
||||
const response = await TauriHTTPFetch(new URL(url), { body: JSON.stringify(arg.body), headers, method: arg.method ?? "POST", signal: arg.abortSignal });
|
||||
const data = arg.rawResponse ? new Uint8Array(await response.arrayBuffer()) : await response.json();
|
||||
const ok = response.status >= 200 && response.status < 300;
|
||||
addFetchLogInGlobalFetch(data, ok, url, arg);
|
||||
return { ok, data, headers: Object.fromEntries(response.headers) };
|
||||
} catch (error) {
|
||||
|
||||
let abortFn = () => {};
|
||||
const abortPromise = new Promise<"aborted">((res, rej) => {
|
||||
abortFn = () => res("aborted");
|
||||
arg.abortSignal?.addEventListener('abort', abortFn);
|
||||
});
|
||||
|
||||
const result = await Promise.any([fetchPromise, abortPromise]);
|
||||
arg.abortSignal?.removeEventListener('abort', abortFn);
|
||||
|
||||
if (result === 'aborted') {
|
||||
return { ok: false, data: 'aborted', headers: {} };
|
||||
}
|
||||
|
||||
const data = arg.rawResponse ? new Uint8Array(result.data as number[]) : result.data;
|
||||
addFetchLogInGlobalFetch(data, result.ok, url, arg);
|
||||
return { ok: result.ok, data, headers: result.headers };
|
||||
}
|
||||
|
||||
// Decoupled globalFetch built-in function
|
||||
@@ -1137,13 +1111,13 @@ async function pargeChunks(){
|
||||
|
||||
const unpargeable = getUnpargeables(db)
|
||||
if(isTauri){
|
||||
const assets = await readDir('assets', {dir: BaseDirectory.AppData})
|
||||
const assets = await readDir('assets', {baseDir: BaseDirectory.AppData})
|
||||
for(const asset of assets){
|
||||
const n = getBasename(asset.name)
|
||||
if(unpargeable.includes(n)){
|
||||
}
|
||||
else{
|
||||
await removeFile(asset.path)
|
||||
await remove(asset.name, {baseDir: BaseDirectory.AppData})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1222,7 +1196,7 @@ export class TauriWriter{
|
||||
}
|
||||
|
||||
async write(data:Uint8Array) {
|
||||
await writeBinaryFile(this.path, data, {
|
||||
await writeFile(this.path, data, {
|
||||
append: !this.firstWrite
|
||||
})
|
||||
this.firstWrite = false
|
||||
@@ -1520,7 +1494,7 @@ export async function fetchNative(url:string, arg:{
|
||||
const data = nativeFetchData[fetchId].shift()
|
||||
if(data.type === 'chunk'){
|
||||
const chunk = Buffer.from(data.body, 'base64')
|
||||
controller.enqueue(chunk)
|
||||
controller.enqueue(chunk as unknown as Uint8Array)
|
||||
}
|
||||
if(data.type === 'headers'){
|
||||
resHeaders = data.body
|
||||
@@ -1649,7 +1623,7 @@ export class BlankWriter{
|
||||
|
||||
export async function loadInternalBackup(){
|
||||
|
||||
const keys = isTauri ? (await readDir('database', {dir: BaseDirectory.AppData})).map((v) => {
|
||||
const keys = isTauri ? (await readDir('database', {baseDir: BaseDirectory.AppData})).map((v) => {
|
||||
return v.name
|
||||
}) : (await forageStorage.keys())
|
||||
let internalBackups:string[] = []
|
||||
@@ -1677,11 +1651,11 @@ export async function loadInternalBackup(){
|
||||
const selectedBackup = internalBackups[alertResult]
|
||||
|
||||
const data = isTauri ? (
|
||||
await readBinaryFile('database/' + selectedBackup, {dir: BaseDirectory.AppData})
|
||||
await readFile('database/' + selectedBackup, {baseDir: BaseDirectory.AppData})
|
||||
) : (await forageStorage.getItem(selectedBackup))
|
||||
|
||||
setDatabase(
|
||||
decodeRisuSave(data)
|
||||
decodeRisuSave(Buffer.from(data) as unknown as Uint8Array)
|
||||
)
|
||||
|
||||
await alertNormal('Loaded backup')
|
||||
|
||||
@@ -2,10 +2,9 @@ import { alertConfirm, alertWait } from "./alert";
|
||||
import { language } from "../lang";
|
||||
import { Capacitor } from "@capacitor/core";
|
||||
import {
|
||||
checkUpdate,
|
||||
installUpdate,
|
||||
} from '@tauri-apps/api/updater'
|
||||
import { relaunch } from '@tauri-apps/api/process'
|
||||
check,
|
||||
} from '@tauri-apps/plugin-updater'
|
||||
import { relaunch } from '@tauri-apps/plugin-process'
|
||||
|
||||
export async function checkRisuUpdate(){
|
||||
|
||||
@@ -14,12 +13,12 @@ export async function checkRisuUpdate(){
|
||||
}
|
||||
|
||||
try {
|
||||
const checked = await checkUpdate()
|
||||
if(checked.shouldUpdate){
|
||||
const checked = await check()
|
||||
if(checked){
|
||||
const conf = await alertConfirm(language.newVersion)
|
||||
if(conf){
|
||||
alertWait(`Updating to ${checked.manifest.version}...`)
|
||||
await installUpdate()
|
||||
alertWait(`Updating to ${checked.version}...`)
|
||||
await checked.downloadAndInstall()
|
||||
await relaunch()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,13 @@ import { get, writable, type Writable } from "svelte/store"
|
||||
import type { Database, Message } from "./storage/database"
|
||||
import { DataBase } from "./storage/database"
|
||||
import { selectedCharID } from "./stores"
|
||||
import {open} from '@tauri-apps/api/dialog'
|
||||
import { readBinaryFile } from "@tauri-apps/api/fs"
|
||||
import {open} from '@tauri-apps/plugin-dialog'
|
||||
import { readFile } from "@tauri-apps/plugin-fs"
|
||||
import { basename } from "@tauri-apps/api/path"
|
||||
import { createBlankChar, getCharImage } from "./characters"
|
||||
import { appWindow } from '@tauri-apps/api/window';
|
||||
import { getCurrentWebviewWindow } from '@tauri-apps/api/webviewWindow';
|
||||
import { isTauri } from "./storage/globalApi"
|
||||
const appWindow = getCurrentWebviewWindow()
|
||||
|
||||
export const isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1
|
||||
|
||||
@@ -64,7 +65,7 @@ export async function selectSingleFile(ext:string[]){
|
||||
} else if (selected === null) {
|
||||
return null
|
||||
} else {
|
||||
return {name: await basename(selected),data:await readBinaryFile(selected)}
|
||||
return {name: await basename(selected),data:await readFile(selected)}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,13 +89,13 @@ export async function selectMultipleFile(ext:string[]){
|
||||
if (Array.isArray(selected)) {
|
||||
let arr:{name:string, data:Uint8Array}[] = []
|
||||
for(const file of selected){
|
||||
arr.push({name: await basename(file),data:await readBinaryFile(file)})
|
||||
arr.push({name: await basename(file),data:await readFile(file)})
|
||||
}
|
||||
return arr
|
||||
} else if (selected === null) {
|
||||
return null
|
||||
} else {
|
||||
return [{name: await basename(selected),data:await readBinaryFile(selected)}]
|
||||
return [{name: await basename(selected),data:await readFile(selected)}]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user