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 clipboard issue when coping debug info #1675

Merged
merged 4 commits into from
Sep 3, 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
147 changes: 67 additions & 80 deletions desktop/angular/package-lock.json

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

14 changes: 7 additions & 7 deletions desktop/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@
"@fortawesome/free-brands-svg-icons": "^6.4.0",
"@fortawesome/free-regular-svg-icons": "^6.4.0",
"@fortawesome/free-solid-svg-icons": "^6.4.0",
"@tauri-apps/api": ">=2.0.0-beta.0",
"@tauri-apps/plugin-cli": ">=2.0.0-beta.0",
"@tauri-apps/plugin-clipboard-manager": ">=2.0.0-beta.0",
"@tauri-apps/plugin-dialog": ">=2.0.0-beta.0",
"@tauri-apps/plugin-notification": ">=2.0.0-beta.0",
"@tauri-apps/plugin-os": ">=2.0.0-beta.0",
"@tauri-apps/plugin-shell": "^2.0.0-beta",
"@tauri-apps/api": ">=2.0.0-rc.1",
"@tauri-apps/plugin-cli": ">=2.0.0-rc.1",
"@tauri-apps/plugin-clipboard-manager": ">=2.0.0-rc.1",
"@tauri-apps/plugin-dialog": ">=2.0.0-rc.1",
"@tauri-apps/plugin-notification": ">=2.0.0-rc.1",
"@tauri-apps/plugin-os": ">=2.0.0-rc.1",
"@tauri-apps/plugin-shell": "^2.0.0-rc",
"autoprefixer": "^10.4.14",
"d3": "^7.8.4",
"data-urls": "^5.0.0",
Expand Down
60 changes: 31 additions & 29 deletions desktop/angular/src/app/integration/taur-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { open } from '@tauri-apps/plugin-shell';
import { listen, once } from '@tauri-apps/api/event';
import { invoke } from '@tauri-apps/api/core'
import { getCurrent, Window } from '@tauri-apps/api/window';
import { getCurrentWindow, Window } from '@tauri-apps/api/window';

// Returns a new uuidv4. If crypto.randomUUID is not available it fals back to
// using Math.random(). While this is not as random as it should be it's still
Expand Down Expand Up @@ -102,7 +102,7 @@
// we waste some system resources due to tauri window objects and the angular
// application.

getCurrent().hide()
getCurrentWindow().hide()

return Promise.resolve();
}
Expand Down Expand Up @@ -130,7 +130,7 @@
}
}

get_state(_: string): Promise<string> {

Check warning on line 133 in desktop/angular/src/app/integration/taur-app.ts

View workflow job for this annotation

GitHub Actions / Lint

'_' is defined but never used
return invoke<string>("get_state");
}

Expand Down Expand Up @@ -164,7 +164,7 @@
}

openApp() {
Window.getByLabel("splash")?.close();
Window.getByLabel("splash").then(splash => { splash?.close();});
const current = Window.getCurrent()

current.isVisible()
Expand All @@ -177,40 +177,42 @@
}

closePrompt() {
Window.getByLabel("prompt")?.close();
Window.getByLabel("prompt").then(window => { window?.close();});
}

openPrompt() {
if (!this.withPrompts) {
return;
}

if (Window.getByLabel("prompt")) {
return;
}
Window.getByLabel("prompt").then(prompt => {
if (prompt) {
return;
}

const promptWindow = new Window("prompt", {
alwaysOnTop: true,
decorations: false,
minimizable: false,
maximizable: false,
resizable: false,
title: 'Portmaster Prompt',
visible: false, // the prompt marks it self as visible.
skipTaskbar: true,
closable: false,
center: true,
width: 600,
height: 300,

// in src/main.ts we check the current location path
// and if it matches /prompt, we bootstrap the PromptEntryPointComponent
// instead of the AppComponent.
url: `http://${window.location.host}/prompt`,
} as any)

promptWindow.once("tauri://error", (err) => {
console.error(err);
const promptWindow = new Window("prompt", {
alwaysOnTop: true,
decorations: false,
minimizable: false,
maximizable: false,
resizable: false,
title: 'Portmaster Prompt',
visible: false, // the prompt marks it self as visible.
skipTaskbar: true,
closable: false,
center: true,
width: 600,
height: 300,

// in src/main.ts we check the current location path
// and if it matches /prompt, we bootstrap the PromptEntryPointComponent
// instead of the AppComponent.
url: `http://${window.location.host}/prompt`,
} as any)

promptWindow.once("tauri://error", (err) => {
console.error(err);
});
});
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { CommonModule } from "@angular/common";
import { Component, OnInit, TrackByFunction, inject } from "@angular/core";
import { AppProfile, AppProfileService, PortapiService } from "@safing/portmaster-api";
import { combineLatest, combineLatestAll, forkJoin, map, merge, mergeAll, of, switchMap } from "rxjs";
import { combineLatest, forkJoin, map, of, switchMap } from "rxjs";
import { ConnectionPrompt, NotificationType, NotificationsService } from "../services";
import { SfngAppIconModule } from "../shared/app-icon";
import { getCurrent } from '@tauri-apps/api/window';
import { getCurrentWindow } from '@tauri-apps/api/window';
import { CountryFlagModule } from "../shared/country-flag";

interface Prompt {
Expand All @@ -30,7 +30,7 @@
prompts: Prompt[] = [];

trackPrompt: TrackByFunction<ConnectionPrompt> = (_, p) => p.EventID;
trackProfile: TrackByFunction<Prompt> = (_, p) => p.profile._meta!.Key;

Check warning on line 33 in desktop/angular/src/app/prompt-entrypoint/prompt-entrypoint.ts

View workflow job for this annotation

GitHub Actions / Lint

Forbidden non-null assertion

ngOnInit(): void {

Expand All @@ -43,7 +43,7 @@
switchMap(notifications => {
const distictProfiles = new Map<string, ConnectionPrompt[]>();
notifications.forEach(n => {
const key = `${n.EventData!.Profile.Source}/${n.EventData!.Profile.ID}`

Check warning on line 46 in desktop/angular/src/app/prompt-entrypoint/prompt-entrypoint.ts

View workflow job for this annotation

GitHub Actions / Lint

Forbidden non-null assertion

Check warning on line 46 in desktop/angular/src/app/prompt-entrypoint/prompt-entrypoint.ts

View workflow job for this annotation

GitHub Actions / Lint

Forbidden non-null assertion
const arr = distictProfiles.get(key) || [];
arr.push(n);
distictProfiles.set(key, arr);
Expand All @@ -64,7 +64,7 @@

// show the prompt now since we're ready
if (this.prompts.length) {
getCurrent()!.show();
getCurrentWindow()!.show();

Check warning on line 67 in desktop/angular/src/app/prompt-entrypoint/prompt-entrypoint.ts

View workflow job for this annotation

GitHub Actions / Lint

Forbidden non-null assertion
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM: Method name change looks good.

The method name change from getCurrent() to getCurrentWindow() is consistent with the API change mentioned in the AI-generated summary and the list of alterations.

Use optional chaining instead of non-null assertion.

The non-null assertion (!) is used to force unwrap the window object returned by getCurrentWindow(). This assumes that the window object will always be available, which may not be the case in all scenarios.

Consider using optional chaining (?.) instead to safely access the show() method only if the window object is available:

-getCurrentWindow()!.show();
+getCurrentWindow()?.show();
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
getCurrentWindow()!.show();
getCurrentWindow()?.show();
Tools
GitHub Check: Lint

[warning] 67-67:
Forbidden non-null assertion

}
})
}
Expand All @@ -72,7 +72,7 @@
selectAction(prompt: ConnectionPrompt, action: string) {
prompt.SelectedActionID = action;

this.portapi.update(prompt._meta!.Key, prompt)

Check warning on line 75 in desktop/angular/src/app/prompt-entrypoint/prompt-entrypoint.ts

View workflow job for this annotation

GitHub Actions / Lint

Forbidden non-null assertion
.subscribe();
}
}
Loading
Loading