Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(portable): do not use system notification api while app is portable #334

Merged
merged 4 commits into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,4 @@ jobs:
run: pnpm updater
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
RELEASE_BODY: ${{ github.event.release.body }}
12 changes: 12 additions & 0 deletions backend/tauri/src/cmds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ pub fn get_profiles() -> CmdResult<IProfiles> {
Ok(Config::profiles().data().clone())
}

#[cfg(target_os = "windows")]
#[tauri::command]
pub fn is_portable() -> CmdResult<bool> {
Ok(crate::utils::dirs::get_portable_flag())
}

#[cfg(not(target_os = "windows"))]
#[tauri::command]
pub fn is_portable() -> CmdResult<bool> {
Ok(false)
}

#[tauri::command]
pub async fn enhance_profiles() -> CmdResult {
wrap_err!(CoreManager::global().update_config().await)?;
Expand Down
1 change: 1 addition & 0 deletions backend/tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ fn main() -> std::io::Result<()> {
cmds::service::check_service,
cmds::service::install_service,
cmds::service::uninstall_service,
cmds::is_portable,
]);

#[cfg(target_os = "macos")]
Expand Down
3 changes: 2 additions & 1 deletion scripts/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { colorize, consola } from "./utils/logger";
const UPDATE_TAG_NAME = "updater";
const UPDATE_JSON_FILE = "update.json";
const UPDATE_JSON_PROXY = "update-proxy.json";
const UPDATE_RELEASE_BODY = process.env.RELEASE_BODY || "";

/// generate update.json
/// upload to update tag's release asset
Expand Down Expand Up @@ -36,7 +37,7 @@ async function resolveUpdater() {

const updateData = {
name: tag.name,
notes: await resolveUpdateLog(tag.name), // use updatelog.md
notes: (await resolveUpdateLog(tag.name)) || UPDATE_RELEASE_BODY || "", // use updatelog.md
pub_date: new Date().toISOString(),
platforms: {
win64: { signature: "", url: "" }, // compatible with older formats
Expand Down
9 changes: 7 additions & 2 deletions src/hooks/use-notification.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { Notice } from "@/components/base";
import { isPortable } from "@/services/cmds";
import {
Options,
isPermissionGranted,
requestPermission,
sendNotification,
} from "@tauri-apps/api/notification";
let permissionGranted: boolean | null = null;
let portable: boolean | null = null;

const checkPermission = async () => {
if (permissionGranted == null) {
Expand Down Expand Up @@ -39,8 +41,11 @@ export const useNotification = async ({
if (!title) {
throw new Error("missing message argument!");
}
const permissionGranted = await checkPermission();
if (!permissionGranted) {
if (portable === null) {
portable = await isPortable();
}
const permissionGranted = portable || (await checkPermission());
if (portable || !permissionGranted) {
// fallback to mui notification
Notice[type](`${title} ${body ? `: ${body}` : ""}}`);
// throw new Error("notification permission not granted!");
Expand Down
5 changes: 5 additions & 0 deletions src/services/cmds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,8 @@ export async function cmdGetProxyDelay(name: string, url?: string) {
name = encodeURIComponent(name);
return invoke<{ delay: number }>("clash_api_get_proxy_delay", { name, url });
}

export async function isPortable() {
if (OS_PLATFORM !== "win32") return false;
return invoke<boolean>("is_portable");
}
Loading